<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saral Karki</title>
    <description>The latest articles on DEV Community by Saral Karki (@saral).</description>
    <link>https://dev.to/saral</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F115650%2F47698c84-7d24-4f83-bb44-c062cd3b970c.jpg</url>
      <title>DEV Community: Saral Karki</title>
      <link>https://dev.to/saral</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saral"/>
    <language>en</language>
    <item>
      <title>Comparing Sandeep Lamichhane’s Twenty 20 stats with other prominent leggies</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Mon, 08 Jul 2019 08:34:43 +0000</pubDate>
      <link>https://dev.to/saral/comparing-sandeep-lamichhane-s-twenty-20-stats-with-other-prominent-leggies-5c1l</link>
      <guid>https://dev.to/saral/comparing-sandeep-lamichhane-s-twenty-20-stats-with-other-prominent-leggies-5c1l</guid>
      <description>&lt;p&gt;&lt;em&gt;Surely the name “Sandeep Lamichhane” needs no introduction. He has been making waves in the Twenty 20 cricketing world by delivering outstanding performances in the IPL, Big Bash and other international T20 leagues. However, I wanted to take a look at how exactly Sandeep has been faring compared with some other legendary leg-spinners and his contemporaries.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Play around with the &lt;a href="https://cricketapp-spinner.herokuapp.com/"&gt;dashboard&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of the data were collected from Cricinfo.com and after meticulous cleaning of the data, here are the findings. The bowlers in the list are : Shane Warne, Anil Kumble, Rashid Khan, Yuzvendra Chahal, Amit Mishra, Imran Tahir, Adam Zampa, Adil Rashid, Rashid Khan and Sandeep Lamichhane.&lt;/p&gt;

&lt;h3&gt;
  
  
  Matches played:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4-CDFDLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A3GtWfhitsfb1nuYB3XH7qA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4-CDFDLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A3GtWfhitsfb1nuYB3XH7qA.png" alt=""&gt;&lt;/a&gt;Total number of matches played&lt;/p&gt;

&lt;p&gt;Sandeep is relatively very new to the realm of T20 leagues and comparatively has played much fewer games compared to others. Anil Kumble and Shane Warne are the only two former players in the list, but even they have played more than Sandeep. Sandeep is likely to catch up to these two legends though.&lt;/p&gt;

&lt;p&gt;Some of the key indicators to judge a bowlers ability in T20 cricket are the&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Economy rate: The average number of runs conceded per over in cricket.&lt;/li&gt;
&lt;li&gt;Bowling Strike rate: Measurement of a bowler’s average number of balls bowled for every wicket taken.&lt;/li&gt;
&lt;li&gt;Average: is the number of runs they have conceded per wicket taken.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, it is widely recognized that such statistics have severe limitations in assessing the true abilities of a player’s performance [1]. Therefore, we will be looking at the measure called Combined Bowling Rate(CBR) as developed by Lemmer. [2] CBR was constructed by using the harmonic mean of A, E and S. For calculation purposes it can be written as:[3]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TO6CYgO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/264/1%2AiGUA5W5y259t2ekE4XM-Cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TO6CYgO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/264/1%2AiGUA5W5y259t2ekE4XM-Cw.png" alt=""&gt;&lt;/a&gt;CBR Formula&lt;/p&gt;

&lt;p&gt;One of the limitation we would be facing was the variable value if the number of overs bowled were small. However, in our case all the bowlers have bowled enough overs and we likely need not worry about the few overs limitations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nDFItULC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/196/1%2AYP4xDN7Qzk5I9QvmLkLV2Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nDFItULC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/196/1%2AYP4xDN7Qzk5I9QvmLkLV2Q.png" alt=""&gt;&lt;/a&gt;Total number of overs bowled&lt;/p&gt;

&lt;p&gt;Using the CBR we can get a good overview of Sandeep’s performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  CBR Vs Economy:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tfygkYmp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A46_BVwy-yLqujFInAzh-uw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tfygkYmp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A46_BVwy-yLqujFInAzh-uw.jpeg" alt=""&gt;&lt;/a&gt;CBR vs Economy rate&lt;/p&gt;

&lt;p&gt;We can observe that based on economy Sandeep is fourth on the list. However, if we take a look at the CBR which according to the earlier cited works is a better measure for performance, we can see that Sandeep jumps to the third position only behind Rashid Khan, and Imran Tahir.&lt;/p&gt;

&lt;p&gt;Judging by both the CBR score and the economy rate we can see that Sandeep has been successful in his short stint as a T20 bowler.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Surprise finding: It was rather interesting to see Shane Warne go to the bottom of this list. A case can be made for him though: the champion spinner was in the latter part of his career and therefore wasn’t at his supreme best.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For the &lt;a href="https://github.com/Saralkarki/bowling_performance/blob/master/Project.ipynb"&gt;full code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;—&lt;br&gt;
References:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lewis, A. J. Towards fairer measures of player performance in one-day cricket. _Journal of the Operational Research Society._2005, &lt;strong&gt;56&lt;/strong&gt; : 804–815.&lt;/li&gt;
&lt;li&gt;Lemmer, H. H. The combined bowling rate as a measure of bowling performance in cricket. &lt;em&gt;South African Journal for Research in Sport, Physical Education and Recreation.&lt;/em&gt; 2002, &lt;strong&gt;24&lt;/strong&gt; (2): 37–44.&lt;/li&gt;
&lt;li&gt;Lemmer, H. H, Perspectives on the use of the Combined Bowling Rate in Cricket. &lt;em&gt;International Journal of Sports Science &amp;amp; Coaching Volume 9 · Number 3&lt;/em&gt; · 2014, 513–523&lt;/li&gt;
&lt;li&gt;Bhattacharjee D, Pahinkar D. G, &lt;em&gt;Analysis of Performance of Bowlers using Combined Bowling Rate,&lt;/em&gt; &lt;strong&gt;International Journal of Sports Science and Engineering&lt;/strong&gt; Vol. 06 (2012) №03, pp. 184–192&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>datavisualization</category>
      <category>python</category>
      <category>dash</category>
      <category>dataanalysis</category>
    </item>
    <item>
      <title>Nepal Earthquakes Magnitude Data Analysis and Data Visualization with Python</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Wed, 15 May 2019 09:30:30 +0000</pubDate>
      <link>https://dev.to/saral/nepal-earthquakes-magnitude-data-analysis-and-data-visualization-with-python-12gl</link>
      <guid>https://dev.to/saral/nepal-earthquakes-magnitude-data-analysis-and-data-visualization-with-python-12gl</guid>
      <description>&lt;p&gt;This paper attempts to analyze and visualize the earthquake data of Nepal ranging from 1994–2019. The data was extracted from the &lt;a href="http://seismonepal.gov.np/earthquakes" rel="noopener noreferrer"&gt;National Seismological Centre (NSC) database&lt;/a&gt;. The code run to fetch and clean the data can be found &lt;a href="https://github.com/Saralkarki/Nepal_earthquake/blob/master/extract_data.ipynb" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where did the data require cleaning?
&lt;/h4&gt;

&lt;p&gt;Once the data was scraped from the webpage it required a bit of cleaning. Most of how the cleaning was done has been described with comments in the code, however few things I was required to do were:&lt;/p&gt;

&lt;h4&gt;
  
  
  i. Change the date to a proper format:
&lt;/h4&gt;

&lt;p&gt;The dates in the database were not in the standard DateTime format. The Nepali and the English dates were concatenated together. So the first task was to change the dates to a proper format.&lt;/p&gt;

&lt;h4&gt;
  
  
  ii. Changing the time to a proper format:
&lt;/h4&gt;

&lt;p&gt;The time column in the database was not in a standard format. Therefore, this too required changing.&lt;/p&gt;

&lt;p&gt;Once these two tasks were completed, my database was more or less ready for quick analysis and visualization.&lt;/p&gt;

&lt;h4&gt;
  
  
  iii. Dropped rows:
&lt;/h4&gt;

&lt;p&gt;One of my precondition for this analysis was that the Epicenter had to be inside Nepal. Therefore, I dropped off any row where the Epicenter was countries other than Nepal.&lt;/p&gt;

&lt;p&gt;Finally, there were a few coordinates where there were errors in latitudes and longitudes. Once those were accounted for and cleaned the data was ready to be used.&lt;/p&gt;

&lt;h4&gt;
  
  
  Data analysis
&lt;/h4&gt;

&lt;p&gt;The first step of the analysis was to import the required libraries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-pastel')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the library ready, next up was importing the data file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df = pd.read_csv('earthquake.csv')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I was able to import the required CSV file pandas ‘read_csv’ function. I quickly viewed the contents of the data frame now conveniently called df.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df.head()
df.describe()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F383%2F1%2AeI8SgxLV2zYH-6TUGOoOtQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F383%2F1%2AeI8SgxLV2zYH-6TUGOoOtQ.png"&gt;&lt;/a&gt;df.head( )&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F289%2F1%2A6U6hBR8WyWGndxCRpOOuqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F289%2F1%2A6U6hBR8WyWGndxCRpOOuqg.png"&gt;&lt;/a&gt;df.describe( )&lt;/p&gt;

&lt;p&gt;This gave me a quick overview of what the data looked like and a quick summary stats for the numerical data.&lt;/p&gt;

&lt;p&gt;A quick glance at the summary statistics showed that there have been 933 earthquakes in Nepal since 1994. It has been stated that “&lt;a href="https://thehimalayantimes.com/kathmandu/30000-plus-tremors-follow-nepal-earthquake-in-365-days/" rel="noopener noreferrer"&gt;More than 30,000 tremors”&lt;/a&gt;were felt in 2015 alone after the massive earthquake. However, it must be noted that &lt;a href="http://The%20NSC%20processed%20the%20data%20of%20more%20than%20450%20significant%20aftershocks" rel="noopener noreferrer"&gt;NSC processes the data of significant earthquakes and aftershocks.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Earthquake Magnitude Plot
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plt.figure(figsize=(10,10))

sns.scatterplot(y="Magnitude", x=df.Magnitude.index , data=df)

plt.annotate('Gorkha,2015', xy=(389, 7.5), xytext=(385, 7.25),arrowprops=dict(facecolor='black', shrink=0.01),)

plt.annotate('Gorkha,2015', xy=(390, 6.5), xytext=(350, 6.0),arrowprops=dict(facecolor='black', shrink=0.01),)

plt.annotate('Dolkha, 2015', xy=(443, 6.84), xytext=(445, 6.3),arrowprops=dict(facecolor='black', shrink=0.01),)

plt.annotate('Dolkha, 2015', xy=(540, 6.74), xytext=(541, 6.5),arrowprops=dict(facecolor='black', shrink=0.01),)

plt.annotate('Taplejung-Sikkim border, 2011', xy=(282, 6.74), xytext=(100, 6.6),arrowprops=dict(facecolor='black', shrink=0.01),)

plt.savefig('overall\_earthquakes.png')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F720%2F1%2ADqmIUcLyBDCPzhqe8JT4fA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F720%2F1%2ADqmIUcLyBDCPzhqe8JT4fA.png"&gt;&lt;/a&gt;Plotting every earthquake since 1994 to 2019&lt;/p&gt;

&lt;p&gt;We can observe from the scatter plot there have been some massive earthquakes especially four massive ones in 2015 alone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AmbYhLbd8TGiXQe05nL_PpA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AmbYhLbd8TGiXQe05nL_PpA.png"&gt;&lt;/a&gt;Plotting frequency by Magnitude of Earthquake (1994–2019)&lt;/p&gt;

&lt;h3&gt;
  
  
  Yearly Earthquakes from 1994–2019
&lt;/h3&gt;

&lt;p&gt;It can be observed from the graph the surge of frequency in earthquakes in 2015. The number of earthquakes has gone down and is following the pattern prior to 2015.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASGTdjn7oifPRJB4289SkGg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASGTdjn7oifPRJB4289SkGg.png"&gt;&lt;/a&gt;Yearly earthquakes from 1994–2019&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Earthquake Magnitude Classes&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Earthquakes are also classified in categories ranging from minor to great, depending on their magnitude. (&lt;a href="http://www.geo.mtu.edu/UPSeis/magnitude.html" rel="noopener noreferrer"&gt;Source&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ClassMagnitude&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Great: 8 or more&lt;/li&gt;
&lt;li&gt;Major: 7–7.9&lt;/li&gt;
&lt;li&gt;Strong: 6–6.9&lt;/li&gt;
&lt;li&gt;Moderate: 5–5.9&lt;/li&gt;
&lt;li&gt;Light: 4–4.9&lt;/li&gt;
&lt;li&gt;Minor: 3 -3.9
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#array for storing the size\_class
size\_class = []

for magnitude in df.Magnitude:
    if magnitude &amp;gt;= 3.0 and magnitude &amp;lt;=3.9:
        size\_class.append("Minor")
    elif magnitude &amp;gt;=4.0 and magnitude &amp;lt;=4.9:
        size\_class.append("Light")
    elif magnitude &amp;gt;=5.0 and magnitude &amp;lt;=5.9:
        size\_class.append("Moderate")
    elif magnitude &amp;gt;=6.0 and magnitude &amp;lt;=6.9:
        size\_class.append("Strong")
    elif magnitude &amp;gt;=7.0 and magnitude &amp;lt;=7.9:
        size\_class.append("Major")
    else:
        size\_class.append("Great")

#Creating a column in the dataframe called size\_class
df['size\_class'] = size\_class

df\_size\_class = pd.DataFrame(df.size\_class.groupby(df.size\_class).count())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this done, I had a column in the data showing the various magnitude classes. Plotting these&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F720%2F1%2AKnP5BAdekK0FVspVmx6T3Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F720%2F1%2AKnP5BAdekK0FVspVmx6T3Q.png"&gt;&lt;/a&gt;Earthquakes group by the magnitude class. (1994–2019)&lt;/p&gt;

&lt;h4&gt;
  
  
  Mapping the Earthquake on a geographical map
&lt;/h4&gt;

&lt;p&gt;A new column was created in the database based on the earthquake’s magnitude and its estimated effect.[&lt;a href="http://www.geo.mtu.edu/UPSeis/magnitude.html" rel="noopener noreferrer"&gt;Source&lt;/a&gt;]. Based on magnitude affect the earthquakes were plotted in a map of Nepal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scale = []
for magnitude in df.Magnitude:
    if magnitude &amp;gt;= 3.0 and magnitude &amp;lt;=3.9:
        scale.append("Limited Damage")
    elif magnitude &amp;gt;=4.0 and magnitude &amp;lt;=4.9:
        scale.append("Minor Damage")
    elif magnitude &amp;gt;=5.0 and magnitude &amp;lt;=5.9:
        scale.append("Slight Damage")
    elif magnitude &amp;gt;=6.0 and magnitude &amp;lt;=6.9:
        scale.append("Severe Damage")
    elif magnitude &amp;gt;=7.0 and magnitude &amp;lt;=7.9:
        scale.append("Serious Damage")
    else:
        scale.append("Great Damage")
df['scale'] = scale
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AEGX-nC8pFIJzagfXxTrysw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AEGX-nC8pFIJzagfXxTrysw.png"&gt;&lt;/a&gt;Mapping the earthquakes based on damages&lt;/p&gt;

&lt;p&gt;Finally, the Jupyter notebook for the entire code can be found &lt;a href="https://github.com/Saralkarki/Nepal_earthquake/blob/master/Nepal_Earthquake_Magnitude_Data_Analysis_and_Visualization%20.ipynb" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>nepal</category>
      <category>dataanalysis</category>
      <category>datavisualization</category>
    </item>
    <item>
      <title>Visualizing desired steps distribution — using the central limit theorem</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Mon, 15 Apr 2019 08:08:31 +0000</pubDate>
      <link>https://dev.to/saral/visualizing-desired-steps-distribution-using-the-central-limit-theorem-7pn</link>
      <guid>https://dev.to/saral/visualizing-desired-steps-distribution-using-the-central-limit-theorem-7pn</guid>
      <description>

&lt;h3&gt;
  
  
  Visualizing desired steps distribution — using the central limit theorem
&lt;/h3&gt;

&lt;p&gt;Last week when I took a look at my steps data I noticed that the data was very spread out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0cOueGss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2A2rs7cCgwxUaJafd79s0uAw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0cOueGss--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2A2rs7cCgwxUaJafd79s0uAw.png" alt=""&gt;&lt;/a&gt;Showing the spread in the steps data&lt;/p&gt;

&lt;p&gt;Though I felt relatively satisfied with the average steps I was running in a day, the data was too spread out — i.e. Standard Deviation(&lt;strong&gt;σ)&lt;/strong&gt; was 3435.38. This suggested that 68% of the steps data was in between 7305.65 and 14177.25 steps. I had even got days where the total number of steps were well below 5000, and therefore I wanted to get my data to mimic a distribution where the standard deviation would be lower meaning that the steps data would not be as spread out as it currently is.&lt;/p&gt;

&lt;p&gt;As suggested by the central limit theorem, I decided to take 5(N = 5) independent random samples from the steps dataset. I would repeat this process 5 times (iter = 5), to begin with, therefore giving me a 5 dataset with 5 independent random samples in each set. Next, I would find the mean of each 5 independent random datasets, and finally, I would find out the mean of means. I would then run the same experiment two more times, but this time increasing random samples to 20 (N = 20) and then to 100 (N = 100)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining the Functions&lt;/strong&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def random_steps_array(name_of_array, n , iterations):
    for i in range(iterations): 
        name_of_array.append(df.steps.sample(n, random_state = i,   
                              replace = True))

def sample_means(name_of_array, sample_mean):
    for i in range(len(name_of_array)):     
        sample_mean.append(name_of_array[i].mean())
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;&lt;em&gt;random_steps_array&lt;/em&gt;&lt;/strong&gt; function would handle the random sampling and the iterations, and the &lt;strong&gt;&lt;em&gt;sample_means&lt;/em&gt;&lt;/strong&gt; array would take mean of the random samples.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Experimenting with 5 iterations where N = 5, 20,100&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;i. &lt;strong&gt;At N = 5&lt;/strong&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array_5 = []
mean_array\_5 = []
random_steps_array(array_5, 5, 5)
sample_means(array_5, mean_array_5 )
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The random samples of 5 independent random variables were stored in the &lt;strong&gt;array_5&lt;/strong&gt; means of the random variables were stored in &lt;strong&gt;mean_array_5&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3R0OCUZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2A6G3960FUY7dFPXB861IcIg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3R0OCUZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2A6G3960FUY7dFPXB861IcIg.png" alt=""&gt;&lt;/a&gt;Sample distribution of the sample means at N=5&lt;/p&gt;

&lt;p&gt;With only five iterations of 5 independent random samples, the mean of sample means was a bit further away from the actual mean of 10741.45. However, the taken the distribution was now less spread out and the standard error of the mean or (a.k.a. the standard deviation of the sampling distribution of the sample means — (S.E) was 1650.&lt;/p&gt;

&lt;p&gt;ii. &lt;strong&gt;At N = 20&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The mean of the sample means was much closer to the actual mean when I ran 20 iterations for a random sample size of 5 elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IsKBLe_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2AZK_7_E7RtmrDG5WMpAIB6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IsKBLe_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2AZK_7_E7RtmrDG5WMpAIB6g.png" alt=""&gt;&lt;/a&gt;Sample distribution of the sample means at N=20&lt;/p&gt;

&lt;p&gt;Already when the number of iterations increased I have a larger set of random samples. Thus giving me a mean that was getting closer to my actual mean, and the standard error of the mean (SE) was down to 561.72. Ideally, this is the kind of visualization I would like to have of my dataset where the data is not very spread out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;iii. At N = 100&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, at N = 100 the graph was even less spread out with the standard error of the mean (SE) at 259.27.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vHhWenKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2AdxU7dRsEBpB9X2o4HfB80w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vHhWenKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/720/1%2AdxU7dRsEBpB9X2o4HfB80w.png" alt=""&gt;&lt;/a&gt;Sample distribution of the sample means at N=100&lt;/p&gt;

&lt;p&gt;The spread was almost similar to at what the dataset was doing at 20 iterations, but the mean of sample means(10838.78) was much closer to the actual mean of 10741.45.&lt;/p&gt;

&lt;p&gt;With the following experiment, I was thus able to visualize my desired graph, also I got some working knowledge with the central limit theorem.&lt;/p&gt;


</description>
      <category>dataanalysis</category>
      <category>python</category>
      <category>datavisualization</category>
    </item>
    <item>
      <title>Have I been covering enough ground?</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Wed, 10 Apr 2019 10:02:34 +0000</pubDate>
      <link>https://dev.to/saral/have-i-been-covering-enough-ground-1278</link>
      <guid>https://dev.to/saral/have-i-been-covering-enough-ground-1278</guid>
      <description>

&lt;p&gt;My goal is to get a minimum of 10000 steps per day. The 10,000 steps per day add roughly up to&lt;a href="https://blog.fitbit.com/should-you-really-take-10000-steps-a-day/"&gt;5 miles&lt;/a&gt;, and which is about 30 minutes of daily exercise. &lt;a href="https://www.cdc.gov/physicalactivity/walking/index.htm"&gt;The Center for Disease Control and Prevention&lt;/a&gt;(CDC) recommend that adults get at least 150 minutes of moderate-intensity aerobic physical activity each week. Therefore, the 10,000 steps per day sorta satisfy CDC’s recommendation. My goal was to see if I was getting the recommended amount of exercise done on a daily basis.&lt;/p&gt;

&lt;p&gt;I have been collecting my steps data with &lt;a href="https://buy.garmin.com/en-US/US/p/529988"&gt;Garmin Forerunner&lt;/a&gt;235, and I was able to download the raw data using this code base &lt;a href="https://github.com/tcgoetz/GarminDB"&gt;Garmin DB&lt;/a&gt;. I sample data ranged from October 31st 2018 to March 31st 2019. Luckily, the data was relatively clean, and the cleaning process did not consume much of my time.&lt;br&gt;&lt;br&gt;
However, since I only needed the steps data, I took a subset of the entire data so that I got the required steps data ranging from the period aforementioned. In total, I had 153 samples but had to drop the first row since it was the day I got the tracker and no data was recorded on the day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decent average
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FfuWnAkW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/569/1%2AbyguHFiWVDDLnV96RcMgJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FfuWnAkW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/569/1%2AbyguHFiWVDDLnV96RcMgJg.png" alt=""&gt;&lt;/a&gt;The average number of steps taken&lt;/p&gt;

&lt;p&gt;On an average over the course of the past 152 days, I average around 10,741 steps per day. The average did please me as it clearly showed that I was at least getting over 10000 steps per day. However, what clearly concerned me was the data well below the 10000 steps per day. How much proportion was below the 10000 steps?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rvBhFpzY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/556/1%2AsGiBZKwgljkdmf68hWlzmQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rvBhFpzY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/556/1%2AsGiBZKwgljkdmf68hWlzmQ.png" alt=""&gt;&lt;/a&gt;Percentage of Steps taken from Oct 31st to March 31 2019&lt;/p&gt;

&lt;p&gt;Over a period of 152 days, I was running more than 10000 steps 62.5% of the times, while I failed to do so 37.5% of the times.&lt;/p&gt;

&lt;p&gt;However, there were some massive outliers on both sides of the region that was skewing my mean by around 200 steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KddBJAVc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/575/1%2AnPdf10AfE2vQxeC5Aq6BPw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KddBJAVc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/575/1%2AnPdf10AfE2vQxeC5Aq6BPw.png" alt=""&gt;&lt;/a&gt;Box Plot showing outliers in the data&lt;/p&gt;

&lt;p&gt;What was a bit heartening to see that most of my data, if I did not take into account the outliers, fell between the 12500 to around 9000 regions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xZPS4u1F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/569/1%2AduqiuN0-qZkPbgMDXa_81w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xZPS4u1F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/569/1%2AduqiuN0-qZkPbgMDXa_81w.png" alt=""&gt;&lt;/a&gt;Histogram with median&lt;/p&gt;

&lt;p&gt;Furthermore, I wanted to look at the probability of me being able to do more than 10000 steps in any given day.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m9dgWYq4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/544/1%2AEJ5b2bdwmkQa-9bQfzy1lA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m9dgWYq4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/544/1%2AEJ5b2bdwmkQa-9bQfzy1lA.png" alt=""&gt;&lt;/a&gt;The probability of me getting over 10000 on any given day&lt;/p&gt;

&lt;p&gt;I standardized the curve and using the z-table found out that there was a 59% chance of me getting more than 10000 steps on any given day. While I will take this, I intend to get that proportion higher at about 82%.&lt;/p&gt;

&lt;p&gt;Finally, I wanted to take a look at the pattern and if there was a streak where I managed to get over 10000 steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9w3WEIpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/609/1%2AFNA_tXGJECiTpLufNEynKg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9w3WEIpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/609/1%2AFNA_tXGJECiTpLufNEynKg.png" alt=""&gt;&lt;/a&gt;HeatMap showing the streak of steps &amp;gt; 10000 or &amp;lt; 10000&lt;/p&gt;

&lt;p&gt;Above in red are the days where I managed to get more than 10000 steps or less than 10000 steps. My longest streak for getting more than 10000 steps was 15 days and I managed it twice both in 2019. Once from the 9th of January to the 23rd of January. My streak was broken on the 24th, however, I managed to get back on track and start another 15 days streak from the 25th to 8th February. My streak for lesser than 10000 steps a day has also come twice and the streak has been for 8 days. The first one came way back from November 2 to 9, and the second one came from March 16th to 23.&lt;/p&gt;

&lt;p&gt;All in all, looking at the data I feel I have not done as well as I thought I had. I expected to have done more than 10000 steps for at least 80% of the times, however, the data suggests otherwise. The bright side, equipped with this data I can look forward to the future and get my probability proportion to somewhere close to 80%.&lt;/p&gt;


</description>
      <category>python</category>
      <category>datavisualization</category>
      <category>beginners</category>
      <category>dataanalysis</category>
    </item>
    <item>
      <title>This is my blog</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Sun, 17 Mar 2019 12:16:13 +0000</pubDate>
      <link>https://dev.to/saral/this-is-my-blog-lce</link>
      <guid>https://dev.to/saral/this-is-my-blog-lce</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.pexels.com%2Fphotos%2F1437904%2Fpexels-photo-1437904.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26dpr%3D2%26h%3D500%26w%3D500" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.pexels.com%2Fphotos%2F1437904%2Fpexels-photo-1437904.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26dpr%3D2%26h%3D500%26w%3D500" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, after weeks of learning and working on the &lt;a href="//saralkarki.herokuapp.com"&gt;personal blog&lt;/a&gt;, I can say it has now taken a shape that I am satisfied with. There is still a lot of work needed to be done especially with the styling of the blog, however, overall I think I have got the features I wanted to add. So what features are integrated within my personal blog&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User Authentication:&lt;br&gt;
 For user authentication, I used the 'bcrypt' gem. Though in my other projects I have used the 'Devise gem', this being my project, I chose to use bcrypt. Also, user authentication wasn't a feature that I absolutely required in this project, because it is a personal blog, and I am guessing the only person uploading here will be me. &lt;br&gt;
Here's how I went about getting bcrypt to work on &lt;a href="https://dev.to/saral/rails-here-i-come-day5-2a7l"&gt;the blog&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Markdown:&lt;br&gt;
 For my blog I wanted to be able to enter the text as I do on Dev. Therefore, I went about finding how I could implement markdown on the blog. Also, I have no idea a thing called 'Rich text editor' existed. Had I known this, I would probably have gone and tried using a rich text editor instead. My ignorance was a blessing in disguise as now I am equipped with knowledge on how to implement both markdown and rich text editor. &lt;br&gt;
Here is how I implemented the &lt;a href="https://dev.to/saral/implementing-markdown-on-my-blog-post-46jf"&gt;markdown&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bootstrap and Font-awesome:&lt;br&gt;
 Next up, I wanted to use bootstrap and for this, I followed the instructions provided on the &lt;a href="https://github.com/twbs/bootstrap-rubygem" rel="noopener noreferrer"&gt;bootstrap gem homepage&lt;/a&gt;. I also used the font-awesome icons to style the icons. Again, the &lt;a href="https://github.com/bokmann/font-awesome-rails" rel="noopener noreferrer"&gt;Font-awesome gem page&lt;/a&gt; came in handy whilst implementing the FA icons. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pagination:&lt;br&gt;
 For pagination I used the &lt;a href="https://rubygems.org/gems/will_paginate" rel="noopener noreferrer"&gt;will_paginate&lt;/a&gt; gem. Here's my implementation of the gem on the &lt;a href="https://dev.to/saral/pagination-done-309l"&gt;blog&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paperclip:&lt;br&gt;
Finally, for adding images to the blog posts I used the paperclip gem. I was able to get the gem working on localhost, however, I soon encountered an issue on Heroku. The images looked to be stored on my database but every time I refreshed the images would disappear. It was then that I learnt, that Heroku wouldn't store my images, and therefore I would have to store my images elsewhere. The recommended platform was AWS. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now I embark on my next goal to get the images on AWS. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>rails</category>
      <category>webdev</category>
    </item>
    <item>
      <title> Javascript! Here I come </title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Tue, 26 Feb 2019 15:45:22 +0000</pubDate>
      <link>https://dev.to/saral/-javascript-here-i-come--2gka</link>
      <guid>https://dev.to/saral/-javascript-here-i-come--2gka</guid>
      <description>&lt;p&gt;I am scared of javascript. There you go I said it. For some reason, I have been scared of JS and have been completely avoiding it. But, as we are all aware 'Javascript is everywhere", and if I wanted to become a developer, I would need to at some point in time face that fear and learn it. &lt;/p&gt;

&lt;p&gt;Now, was the time to learn it, to devote time my time and really learn javascript. After scouring through various posts on JS, I decided to first try my hands on vanilla JS. No frameworks, for now, I want to really learn pure JS and no matter how tough it gets, I am going to do this.&lt;/p&gt;

&lt;p&gt;For this week, I concentrated on this &lt;a href="https://saralkarki.github.io/keyboard/"&gt;app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code at [&lt;a href="https://github.com/Saralkarki/keyboard/"&gt;https://github.com/Saralkarki/keyboard/&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Under the hood of a scaffold generated controller</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Mon, 25 Feb 2019 16:23:50 +0000</pubDate>
      <link>https://dev.to/saral/under-the-hood-of-scaffold-generated-controller-o3a</link>
      <guid>https://dev.to/saral/under-the-hood-of-scaffold-generated-controller-o3a</guid>
      <description>&lt;p&gt;This week, I have been working on a Todo list app, and for the first time, I used the rails &lt;a href="https://dev.to/saral/my-first-rails-scaffold-3gfn"&gt;scaffold&lt;/a&gt;. This generated a whole host of the required files, routes and codes. I really wanted to understand what was going on in the controller that the scaffold had generated, and so I started reading between the lines and tried unravelling the Rails magic.&lt;/p&gt;

&lt;p&gt;First off was the index method in the todo_list controller that had been generated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def index
 @todo_list = TodoList.all
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This I thought was straight forward to understand having already completed a project in rails. The entire TodoList model that had been created would get stored in the &lt;code&gt;@todo_list&lt;/code&gt; instance. This was a global instance denoted by the&lt;code&gt;@&lt;/code&gt; symbol, which meant I would be able to access the contents from the views as well.&lt;/p&gt;

&lt;p&gt;I then opened up my rails console via &lt;code&gt;rails c&lt;/code&gt;. Here I wanted to test a few things out for myself. Rails console is a good place to experiment and see what certain syntaxes are actually doing. Upon running the &lt;code&gt;TodoList.all&lt;/code&gt; in the console, my understanding of the &lt;code&gt;.all&lt;/code&gt; method was verified.&lt;/p&gt;

&lt;p&gt;I wanted to see what would happen if I tried to figure out the class of the @todo_list. For this, in my rails console, I ran&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@todo_list = TodoList.all
@todo_list.class
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The output I received for class type was &lt;code&gt;TodoList::ActiveRecord_Relation.&lt;/code&gt;. When working with the model, I have seen this class type many times. There's a lot for me to understand about the ActiveRecord_Relation class, but my basic understanding,I interpreted as: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Looks like activeRecord_Relation as I see in Rails console, stores the data in an array. In my case, something like this&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#&amp;lt;ActiveRecord::Relation [#&amp;lt;TodoList id: 1, title: "New todo", description: "Hello this is the first todo", created_at: "2019-02-21 04:51:53", updated_at: "2019-02-21 04:51:53"&amp;gt;, 
#&amp;lt;TodoList id: 2, title: "Todo #2", description: "Hello", created_at: "2019-02-21 05:28:20", updated_at: "2019-02-21 05:28:20"&amp;gt;]&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since, the acitveRecord_Relation is an array, I can iterate over it, and display the contents which is exactly what is done in the views. Also, it meant, I could access the elements in the array via indexing. This is exactly what I tried to do next to validate my claim in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TodoList.all[1]
TodoList.all[1].created_at
TodoList.find(1).created_at

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I was able to access the second element of the TodoList model with the first syntax. With the second, I was able to look at the created_at time column of the second data. Finally, with the third syntax, I was able to look at the column of the data whose id was 1.&lt;/p&gt;

&lt;p&gt;Tip: See the difference between the indexing and using find method which uses id. &lt;/p&gt;

&lt;p&gt;There's a lot more to activeRecord_Relation I am sure. My minuscule understanding of it, however, allowed me a glimpse into it. Hopefully, in the future there will be a post on acitveRecord_Relation itself as I understand it better.&lt;/p&gt;

&lt;p&gt;Next, I looked at the create method that the scaffold had generated. Something was very intriguing here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create
    @todo_list = TodoList.new(todo_list_params)

    respond_to do |format|
      if @todo_list.save
        format.html { redirect_to @todo_list, notice: 'Todo list was successfully created.' }
        format.json { render :show, status: :created, location: @todo_list }
      else
        format.html { render :new }
        format.json { render json: @todo_list.errors, status: :unprocessable_entity }

      end
    end
  end

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What was intriguing to me was the &lt;code&gt;new&lt;/code&gt; method being called at times, and other times I had seen the use of the &lt;code&gt;create&lt;/code&gt; method to add entries to the model. My question was "If two method behaved the same way what was the difference between the two?"&lt;/p&gt;

&lt;p&gt;I found my answer &lt;a href="https://stackoverflow.com/questions/9791386/differences-in-rails-between-new-save-and-create%20sorta%20sums%20it%20up"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I then went to the rails console to experiment a bit with the &lt;code&gt;create&lt;/code&gt; and &lt;code&gt;new&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TodoList.new id:4 , title:"Todo 3", description:"What is up?"

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This syntax worked and I got no error, however, the data would not be written inside the model. What was happening was using the &lt;code&gt;new&lt;/code&gt; method merely instantiated but did not save to the database. In order to save to database, we needed to use the &lt;code&gt;save&lt;/code&gt; method in tandem with the &lt;code&gt;new&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test = TodoList.new id:4 , title:"Todo 3", description:"What is up?”
test.save

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This saved the contents of test into the model TodoList. When we think about it, the &lt;code&gt;new&lt;/code&gt; and the &lt;code&gt;save&lt;/code&gt; method together work similarly to the &lt;code&gt;create&lt;/code&gt; method. However, as described by the &lt;a href="https://stackoverflow.com/questions/9791386/differences-in-rails-between-new-save-and-create%20sorta%20sums%20it%20up"&gt;stackoverflow answer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The part of the answer that made some sense to me was &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Although it is correct that create calls new and then save there is a big difference between the two alternatives in their return values.&lt;br&gt;
Save returns either true or false depending on whether the object was saved successfully to the database or not. Create will return the model regardless of whether the object was saved or not. This has implications for the code above in that the top branch of the if statement will always be executed even if the object fails validations and is not saved.If you use create with branching logic you are at risk of silent failures which is not the case if you use new + save.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Finally, a new feature introduced to me was the respond_to block. This block allowed me to render my data elements in either standard html format or a json format. For quick verification, in my browser, I entered the .json at the end of my url (localhost:3000/todo_lists/27.json) and got a rendered version of the data in json. &lt;/p&gt;

&lt;p&gt;For now, I don't know what to do with this information. What I do know is that json is an important element in web development. Why, and how I will find out as I go along in my coding journey. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My first rails scaffold</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Thu, 21 Feb 2019 15:26:48 +0000</pubDate>
      <link>https://dev.to/saral/my-first-rails-scaffold-3gfn</link>
      <guid>https://dev.to/saral/my-first-rails-scaffold-3gfn</guid>
      <description>&lt;p&gt;I finished my &lt;a href="https://saralkarki.herokuapp.com"&gt;first app&lt;/a&gt; last week. This app basically is my personal blog. I hope to maintain and add features to it in the days to come. Today though, I started with a new project - a todo list. The first thing I did for this project was &lt;code&gt;rails g scaffold todo_list title:string description:text&lt;/code&gt;. And with it, I had used the scaffold for the first time. There was one thing I wanted to do though, I really wanted to understand how the scaffold worked.&lt;/p&gt;

&lt;p&gt;Here's my understanding of how the scaffold works. Upon creating the new scaffold with the above command, it did a couple of things for me.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It generated the routes for me in the &lt;code&gt;routes.rb&lt;/code&gt; file in the config folder. Viewing the &lt;code&gt;routes.rb&lt;/code&gt; file in my editor, I could see &lt;code&gt;resources :todo_list&lt;/code&gt; on the file. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It generated a model TodoList and once after migrating the database via 'rails db:migrate` the database was ready to be used.  The model had a title and description because I had set those two parameters when creating the scaffold. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scaffold also generated all the controllers for the CRUD methods. Meaning from the get-go I would be able to perform create, read, update and deletion of entries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, all the views were generated, and the views had a form with title and description. Also since the controllers had already defined the CRUD methods, I was able to create, delete, edit and see my entries. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It was that easy. My entire last week's work summarised by one syntax. 😵😵😵😵&lt;/p&gt;

&lt;p&gt;Still, last week was a great learning experience for me building everything from scratch, and this week as I delve into the scaffold generated code, I will really read between the lines of codes and understand what it does. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>rails</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Good job</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Wed, 20 Feb 2019 16:08:36 +0000</pubDate>
      <link>https://dev.to/saral/good-job-he-said-33ca</link>
      <guid>https://dev.to/saral/good-job-he-said-33ca</guid>
      <description>&lt;p&gt;How important are those two words especially coming from someone whose opinion you value? It was vital for me today, those two words "Good job!" coming from a friend and a mentor. &lt;/p&gt;

&lt;p&gt;I was having one of those days where I was getting rather overwhelmed today. With all the effort that I have been putting into learning programming, I was having that kind of a day where I was feeling incompetent. The question if I would ever get good enough was hovering and traumatizing me. I buzzed up my friend and asked if we could meet. My friend a software engineer by trade has been programming ever since I met him back when we were still kids. He had graciously offered to give some of his time to mentoring me whenever he could. There have been times when I have gone to him showed him my projects and he has helped me figure out concepts and given me coding tips. Never though had he said a good job or really given me the compliment of any kind. As a matter of fact, he has always pushed me and said there's a lot for you to learn mate, keep at it. &lt;/p&gt;

&lt;p&gt;Today, however, when he said it, it felt like I had really achieved something. Funnily, when I think about it, this "good job" from him did not come because I had mastered some algorithm or learnt about some data structure. As a matter of fact, it came from what I thought was me solving a minute issue. &lt;/p&gt;

&lt;p&gt;So I had been using the &lt;a href="https://rubygems.org/gems/will_paginate"&gt;will_paginate&lt;/a&gt; gem the other day, and I had encountered an issue with the gem &lt;a href="https://rubygems.org/gems/will_paginate-bootstrap"&gt;will_paginate_bootstrap&lt;/a&gt;. For some reason, the gem was not being applied to my HTML file. After reading the documentation on the &lt;a href="https://github.com/bootstrap-ruby/will_paginate-bootstrap"&gt;homepage&lt;/a&gt;, I figured that since will_paginate_bootstrap gem was not being maintained it might not work with the latest Bootstrap 4, the version I had been using. So I opted to use the &lt;a href="https://rubygems.org/gems/bootstrap-will_paginate"&gt;bootstrap_will_paginate gem&lt;/a&gt; instead, and it worked in an instant. &lt;/p&gt;

&lt;p&gt;As I related this what I thought was a minor victory of mine, he said "Good Job". Furthermore, he added, "much of programming in rails is about being able to figure out what gems will work for you and what won't." Until then, I did not think that figuring out something like this even counted as programming, but apparently it did. &lt;/p&gt;

&lt;p&gt;All of a sudden, I found this new vigour and if ever I needed a validation that I was doing well and I was learning - this was it. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>rails</category>
    </item>
    <item>
      <title>Pagination done</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Mon, 18 Feb 2019 15:18:25 +0000</pubDate>
      <link>https://dev.to/saral/pagination-done-309l</link>
      <guid>https://dev.to/saral/pagination-done-309l</guid>
      <description>&lt;p&gt;After a few days of much-needed break, it was time to get back to adding features to my blog project. Today's assignment was adding pagination to the blog posts. In order to get this feature working, I used the &lt;a href="https://rubygems.org/gems/will_paginate"&gt;will_paginate&lt;/a&gt; gem. On the gem file, I added &lt;code&gt;gem 'will_paginate', '~&amp;gt; 3.1', '&amp;gt;= 3.1.6'&lt;/code&gt;, and ran a quick &lt;code&gt;bundle install&lt;/code&gt; that install the required gem. &lt;/p&gt;

&lt;p&gt;Then, it was all about following the &lt;a href="https://github.com/mislav/will_paginate/wiki"&gt;documentation&lt;/a&gt; of the gem. &lt;/p&gt;

&lt;p&gt;First, off I updated the posts controller for my index method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; def index
  @post = Post.all.order('created_at DESC').paginate(:page =&amp;gt; params[:page], :per_page =&amp;gt; 3)
   end

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see the &lt;code&gt;.paginate&lt;/code&gt; has been added, and I've followed the documentation. Also, I had set three articles to be shown per page. &lt;/p&gt;

&lt;p&gt;Once this was done, the page updated itself to show only three articles on a page. Now I needed to add the pagination in the view itself so that the users can navigate on the website. For this, I used&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= will_paginate @post %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once this was done, I got the pagination working with a navigation menu. However, I still needed to add a bit of style to the menu so that they looked good. For this, I could use bootstrap, something that I had already been using for my app.&lt;/p&gt;

&lt;p&gt;I used the gem &lt;a href="https://rubygems.org/gems/bootstrap-will_paginate"&gt;bootstrap_will_paginate&lt;/a&gt;  for this via &lt;code&gt;gem 'bootstrap-will_paginate', '~&amp;gt; 1.0'&lt;/code&gt;. Again, I ran bundle install, and finally on the views, I added the styling by following the &lt;a href="https://github.com/yrgoldteeth/bootstrap-will_paginate"&gt;documentation&lt;/a&gt; of the gem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;%= will_paginate(@post, :renderer =&amp;gt;
WillPaginate::ActionView::Bootstrap4LinkRenderer) %&amp;gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The pagination was now ready to be used. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Rails with Postgresql</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Thu, 14 Feb 2019 15:31:02 +0000</pubDate>
      <link>https://dev.to/saral/rails-with-postgresql-p0l</link>
      <guid>https://dev.to/saral/rails-with-postgresql-p0l</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.plataformatec.com.br%2Fwp-content%2Fuploads%2F2014%2F07%2Fpostgresql-ruby-on-rails.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.plataformatec.com.br%2Fwp-content%2Fuploads%2F2014%2F07%2Fpostgresql-ruby-on-rails.png" alt="Postgresrails"&gt;&lt;/a&gt;&lt;br&gt;
During the last &lt;a href="https://threeirblog.herokuapp.com" rel="noopener noreferrer"&gt;project&lt;/a&gt;, it was only when I was deploying the app to heroku that I learnt that heroku supported postgresql. I then changed the database to postgresql from the default sqlite that rails came with. &lt;/p&gt;

&lt;p&gt;For the project that I am embarking on, I decided to start off using postgresql to begin with. &lt;/p&gt;

&lt;p&gt;I created the app the usual way &lt;code&gt;rails new (appname)&lt;/code&gt;, and then proceded to change the database detail. In the &lt;code&gt;database.yml&lt;/code&gt; file I changed the default details to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;default: &amp;amp;default
  adapter: postgresql
  pool: &amp;lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&amp;gt;
  timeout: 5000

development:
  &amp;lt;&amp;lt;: *default
  database: app_development

test:
  &amp;lt;&amp;lt;: *default
  database: app_test

production:
  &amp;lt;&amp;lt;: *default
  database: app_production

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also added the &lt;code&gt;gem pg&lt;/code&gt; to the &lt;code&gt;gemfile&lt;/code&gt; and ran &lt;code&gt;bundle install&lt;/code&gt; to install postgresql.&lt;/p&gt;

&lt;p&gt;With this done, I ran  &lt;code&gt;rails db:create&lt;/code&gt; that created the database. I then created my users model. This time around I will be using the &lt;a href="https://rubygems.org/gems/devise" rel="noopener noreferrer"&gt;&lt;code&gt;devise&lt;/code&gt; gem &lt;/a&gt; for the users authentication process. Finally, I ran &lt;code&gt;rails db:migrate&lt;/code&gt; and my model was ready.&lt;/p&gt;

&lt;p&gt;After all this was done, I found out that I could have skipped the process of changing the &lt;code&gt;database.yml&lt;/code&gt; file had I mentioned the kind of database I would be using while generating my app with &lt;code&gt;rails new app --database postgresql&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Did I learn something today? Yes, I did even though I did not get a lot of coding hours logged in today. I intend to start working with devise tomorrow, so I tomorrow's post will be all about getting started with the devise gem. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>rails</category>
    </item>
    <item>
      <title>Ordering the blog posts</title>
      <dc:creator>Saral Karki</dc:creator>
      <pubDate>Wed, 13 Feb 2019 15:51:54 +0000</pubDate>
      <link>https://dev.to/saral/ordering-the-blog-posts-28if</link>
      <guid>https://dev.to/saral/ordering-the-blog-posts-28if</guid>
      <description>&lt;p&gt;I have to say now, I have come to the end of my first project of building a blog app with Rails. Whilst there are features that can be added to the site, my enthusiasm in this project is wearing off. Therefore, I intend to hold this project for the time being and move on to my next project idea starting tomorrow.&lt;/p&gt;

&lt;p&gt;However, there was one more thing I wanted to implement before moving on to the next project. This feature was sorting the blog post by showing the newly created post on top. After having hacked through the solution, this one seemed pretty straightforward, and one line of changed code did the trick.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def index        
        @post = Post.all.order('created_at DESC')
   end

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the post controllers function index, all I needed was to do was add the &lt;code&gt;order&lt;/code&gt; method. The order method would look at the created_at column at sort order the posts in descending order.&lt;/p&gt;

&lt;p&gt;With this done, I did also implement a feature that allows the user to press tab when typing inside the textbox while creating a new or editing a blog post. &lt;br&gt;
I hacked my way through this and used vanilla Javascript for this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myInput = document.getElementById("textbox");
    if(myInput.addEventListener ) {
        myInput.addEventListener('keydown',this.keyHandler,false);
    } else if(myInput.attachEvent ) {
        myInput.attachEvent('onkeydown',this.keyHandler); 
    }
    function keyHandler(e) {
        var TABKEY = 9;
        if(e.keyCode == TABKEY) {
            this.value += "    ";
            if(e.preventDefault) {
                e.preventDefault();
            }
            return false;
        }
    }

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I did for a little while encounter difficulty in getting the javascript included in Rails but was finally able to do it. &lt;/p&gt;

&lt;p&gt;I included the &lt;code&gt;main.js&lt;/code&gt; the js file I had created in the &lt;code&gt;app &amp;gt; javascripts&lt;/code&gt; folder, and then on &lt;code&gt;application.js&lt;/code&gt; in the app folder, I added the following lines &lt;code&gt;//= require main&lt;/code&gt;. This I thought would work, but it did not. I got the following error in my browser console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: Cannot read property 'addEventListener' of null
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I had to search for a solution and to be honest I haven't done a lot of javascript, so I could not really follow along. Something, that I did get was that the javascript &lt;code&gt;addEventListener&lt;/code&gt; was running even before there was any text on the body textbox of my blog. &lt;/p&gt;

&lt;p&gt;For a solution that is working currently for me, I copy pasted the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;at the end of the &lt;code&gt;application.html.erb&lt;/code&gt; document.&lt;/p&gt;

&lt;p&gt;With that, I was able to get the tab working on my textbox. I am yet to understand what my issue with javascript was? Or If I am including the js file correctly to my rails app? &lt;/p&gt;

&lt;p&gt;All in all, it has been a great learning experience for me. However, I must move on from this app, and start fresh. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>rails</category>
    </item>
  </channel>
</rss>
