<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shloka Shah on Medium]]></title>
        <description><![CDATA[Stories by Shloka Shah on Medium]]></description>
        <link>https://medium.com/@shlokashah?source=rss-c22d15327617------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sagIwz7UtJEnoRqC5TqCDw.jpeg</url>
            <title>Stories by Shloka Shah on Medium</title>
            <link>https://medium.com/@shlokashah?source=rss-c22d15327617------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:03:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shlokashah/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Joy of Stationery]]></title>
            <link>https://shlokashah.medium.com/the-joy-of-stationery-86292ddd3171?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/86292ddd3171</guid>
            <category><![CDATA[stationery]]></category>
            <category><![CDATA[joy]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 04:26:10 GMT</pubDate>
            <atom:updated>2023-08-05T04:26:10.220Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i-6e4YUalbBQV8uy" /></figure><p>There is something genuinely magical about the everyday pleasure of stationery in a world dominated by technology and digital advancements. For many people, stationery is more than just a set of tools; it’s a way to express their personalities, a source of inspiration, and a doorway to a universe of limitless possibilities. I’ll take you on a tour of my love for stationery in this blog and explain why these seemingly unremarkable items have come to hold a special place in my heart.</p><p>When I was a kid, I used to look forward to exam time because it gave me the justification I needed to go out and buy a new pen and all the stationery I wanted. The feel of the grip, the ease of the ink, and the elegance of the design all played a part in my decision when selecting the ideal pen; it became an art form. Each new pen I acquired served as both a tool and a companion, bearing witness to both my highs and lows. My favorite pens were Uniball ones. All of the pens I used in school are still safely stored.</p><p>Not only pens, but also board markers and diaries used to excite me, and they still do. I am happiest when someone gifts me stationery.</p><p>Stationery, in my opinion, is a source of power. A pen has the ability to transform me into a person of authority, ready to conquer whatever came my way. There’s an undeniable allure to using a luxurious pen, whether it’s during a meeting or simply in the solitude of journaling in my diary or creating my checklist. It’s an elegant and sophisticated symbol that inspires me to embrace my thoughts and ideas. A pen provides an unparalleled sense of empowerment; it is more than just an instrument; it is an extension of myself. I recently purchased a set of ten different colored pens in order to make my note-taking more enjoyable. I carry it everywhere I go.</p><p>The same is true for whiteboards and markers. When I was in school and saw teachers writing on the whiteboard, I thought they were so powerful. By writing on the whiteboard, they had the power to transform the world. One of the reasons I wanted to be a teacher when I grew up was because of this. I got my first whiteboard when I was in fourth or fifth grade where I used to solve maths problems. I still have a whiteboard which has now become my place to write checklists.</p><p>Every pen, marker, and diary serves as a link between my thoughts and the physical world. They motivate me to slow down and appreciate life’s simple pleasures.</p><p>So, the next time you pass by a stationery store, stop for a moment and let the magic of stationery enchant you. With each pen stroke and page turn, you might just discover a universe of enchantments waiting to be discovered-one colorful pen at a time.</p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/the-joy-of-stationery"><em>https://blog.shlokashah.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86292ddd3171" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Indexes in MySQL]]></title>
            <link>https://shlokashah.medium.com/understanding-indexes-in-mysql-ed4535998863?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed4535998863</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 09:23:27 GMT</pubDate>
            <atom:updated>2023-07-09T09:23:27.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCm9Fl95jxZbGfEfvUSLoQ.png" /></figure><p>Indexes are important as our Database grows in size. We can consider Indexes as Keys that will help us perform faster lookups of rows. In this blog, we will understand the different types of Index in MySQL, their use cases, various strategies to decide the index for a table, and finally, the benefits of having Indexes. So, let’s get started.</p><h3>Different Types of Indexes</h3><h3>B-Tree Index</h3><p>This is the default type of Index in MySQL which is based on the B-Tree data structure.</p><p>The B-Tree index doesn’t need a full table scan to find the desired data; hence it speeds up the data access process. Similar to how a B-Tree works, in this index, the search starts from the root node and goes to the leaf node. Each node contains the minimum and maximum values for the child nodes. We find the right pointer by looking at these values and reaching the leaf node that has the pointer to the data needed. The depth of the B-Tree depends on how big our data is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BMk8FBQfRDPBSlfX" /></figure><p>B-Tree stores the columns in an ordered manner which makes them useful for searching over a range of data, ORDER BY and GROUP BY operations.</p><p>B-Tree does a lookup from the leftmost indexed columns. Let’s take an example to understand how adding a B-Tree Index will help us.</p><p>Consider the example of an Employee Database where we want to search for employees.</p><h4>Employee Table Schema</h4><pre>CREATE TABLE EMPLOYEE (<br>    first_name varchar(40) not null,<br>    last_name varchar(40) not null,<br>    department varchar(40) not null,<br>    joining_date date not null<br>);</pre><p>Consider the following data inserted in the table,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hA1SYMfMPOULM_YNLy7rbQ.png" /></figure><p>Now that we have the schema defined let’s try to search for some Employees in the table and understand how the indexes can be defined and used.</p><h4>Single Column Index</h4><pre>ALTER TABLE EMPLOYEE (<br>    ADD INDEX first_name, <br>    ADD INDEX department, <br>    ADD INDEX joining_date<br>);</pre><p><strong>Query 1:</strong></p><pre>SELECT * FROM EMPLOYEE WHERE first_name = &#39;Donna&#39; and department = &#39;Engineering&#39;<br>-- Uses the Index on first_name</pre><p>Even though there is an Index on the department column, we only use the index on first_name as the three individual indexes act as three separate tables.</p><p>Now when we run this query, MySQL will have to scan across seven rows where the first_name is Donna; imagine the same scan across a huge table where around 1 million people have a similar name. Adding a single-column index won&#39;t help a lot.</p><h4>Multi-Column Index:</h4><pre>ALTER TABLE EMPLOYEE (<br>    ADD INDEX (department, first_name, joining_date)<br>);</pre><p>The following table contains a composite index on (department, first_name, joining_date).</p><p><strong>Query 1:</strong></p><pre>SELECT * FROM EMPLOYEE WHERE department = &#39;Engineering&#39; AND first_name = &#39;Donna&#39;<br>-- Uses the Index on (department, first_name)</pre><p>As compared to single column index, this will be faster as the number of rows to scan will get decreased by using the composite index on (department, first_name)</p><p><strong>Query 2:</strong></p><pre>SELECT * FROM EMPLOYEE WHERE last_name = &#39;Hardy&#39;<br>-- Doesn&#39;t use any Index</pre><p><strong>Query 3:</strong></p><pre>SELECT * FROM EMPLOYEE <br>         WHERE first_name = &#39;Donna&#39; <br>         AND joining_date &gt; 2010-07-28<br>-- Doesn&#39;t use any Index <br>-- since the lookup follows the leftmost side of indexed columns<br>-- we are not mentioning the department<br>-- hence composite index is of no use</pre><p><strong>Query 4:</strong></p><pre>SELECT * FROM EMPLOYEE <br>         WHERE department = &#39;Engineering&#39; <br>         AND first_name LIKE &#39;%S%&#39; <br>         AND joining_date = 2010-07-28<br>-- Uses the Index on (department, first_name)<br>-- since for first_name we have a range query <br>-- it will only use first two columns of index</pre><p>In the case of using indexes for range queries, we should try using the range condition field last in the index. This is because after applying the range query, there is no way for the B-Tree to apply the next filter. Hence we should keep the range condition column at last.</p><p>For the Multi-column Indexes in this Table, we have index search capabilities on (department), (department, first_name) and (department, first_name, joining_date)</p><h4>ORDER BY</h4><p>Consider the following query</p><pre>SELECT * FROM EMPLOYEE WHERE department = &#39;Engineering&#39; ORDER BY last_name</pre><p>This will use the department index to give us the records and then perform a sort on the records to sort them by last_name. This is because we didn&#39;t have any index last_name hence the records were not sorted by that column. This type of sort fetches the data in a temporary buffer before returning it (File Sort), which leads to extra computation.</p><p>This can be avoided by adding an index on last_name. The new composite index for us would be (department, first_name, joining_date, last_name)</p><h4>GROUP BY</h4><p>Proper Indexing also helps in GROUP BY operation.</p><p>Consider an example like</p><pre>SELECT * FROM EMPLOYEE WHERE department = &#39;Engineering&#39; GROUP BY first_name</pre><p>The records would already be sorted by department hence speeding up the filtering. After these results are returned, they are also then sorted by first_name due to the second part of the index, and so they are already grouped for us. This won&#39;t require any other sorting hence making our query fast.</p><h4>Index Selectivity</h4><blockquote>Index selectivity is the ratio of a number of distinct indexed values(cardinality) to the total number of rows in the table(#T). The range for selectivity is from 1/#T to 1.</blockquote><p>An index is said to be highly selective if, for each value, we have fewer rows. Having a highly selective index is good as it filters out more rows when searching for query matches.</p><h4>Choosing the Right Order</h4><p>Now that we have understood what Index Selectivity is let’s see how it helps in deciding the column order.</p><p>Consider the same Employee Table Schema with the multicolumn index on (department, first_name, joining_date, last_name) . This composite index will perform better than a single column on queries, but let&#39;s check if this is the perfect column order for the given set of values in the Employee Table.</p><p>Firstly, let’s check the Index Selectivity of each of the four columns,</p><ol><li>first_name: 3/9 = 0.33</li><li>Department: 4/9 = 0.44</li><li>last_name: 9/9 = 1</li></ol><p>Since joining_date is a date field, and we might want to do range queries on it; it is good to have it last in the order of the index.</p><p>Based on the Selectivity, the ideal order looks like this (last_name, department, first_name, joining_date).</p><p>If we see the Query Examples above, the initial order we defined works well for us as we can use Indexes for most queries. Hence along with selectivity, the use case of the WHERE clause also matters.</p><p>In Conclusion, the Index order for the Multi-Column Index depends on:</p><ul><li>WHERE conditions to effectively lookup data</li><li>Use of ORDER BY and GROUP BY</li><li>Use of Range conditions in the query</li><li>Index Selectivity when unsure about the column order</li><li>The columns we want to SELECT in the Query</li></ul><blockquote>It is important to note that the indexes shouldn’t be optimized only for the WHERE clause but for the entire query.</blockquote><h3>Hash Index</h3><p>Hash Indexes are used when we want to do exact lookups on every column in the table. Hash codes are generated for each row on the indexed columns. Since the original values are converted to short values based on the hash function, they are compact.</p><p>In the case of Hash Indexes, the index contains only pointers to the values rather than the entire values. Hence MySQL uses the in-memory rows to fetch the values from the pointers.</p><p>Some of the drawbacks of Hash Indexes are:</p><ol><li>Since we are generating Hash using a function, we can’t use it for partial matching of values. Example: If we have an Index on (A, B), we can’t use this Index in a query that only uses column A.</li><li>In case of two or more rows having the same values for a column, when generating the Hash Index, it will lead to a collision. In such a case, the engine will traverse all the row pointers and read the values for comparison to find the right value leading to extra computation.</li><li>Hash Indexes are not very useful for columns that have low selectivity since they will lead to hash collisions.</li><li>They can’t be used for sorting because they don’t store rows in a sorted fashion.</li></ol><h4>Adaptive Hash Index</h4><p>In the InnoDB storage engine, when the values are being used frequently, it creates a hash index on top of the B-Tree Index, which leads to faster lookups. This is known as adaptive hash indexes.</p><h3>Other Types of Indexes</h3><p>Some other available Index Types include the Spatial Index, which is used for geometry and geography types, and Full-text Indexes, which split the text into words and make an index over the words and not the whole text. This works faster for text searches when looking for specific words.</p><h3>Benefits of Indexing</h3><p>The benefits of indexing are measured on the three-star system</p><ol><li><em>One Star</em> if the Index reduces the rows that we have to scan.</li><li><em>Two Star</em> if it improves performance by removing the overhead of sorting and temporary tables.</li><li><em>Three Star</em> if all the required columns for querying are a part of the index.</li></ol><h3>Points to Remember while Indexing</h3><h4>Use of Functions in Queries</h4><p>MySQL can use columns only if they are isolated in the query. We should avoid using functions in the WHERE clause.</p><p><strong>Bad Query:</strong></p><pre>SELECT * FROM EMPLOYEE <br>         WHERE department = &#39;Engineering&#39; <br>         AND YEAR(joining_date) = 2010</pre><p>The above query will only use the index department even though an index is present on joining_date. This is because we have enclosed joining_date within a function.</p><h4>Index Merge</h4><p>In the case of multiple single-column indexes, MySQL sometimes uses multiple indexes by performing Index Merge. But it is not efficient since, in the case of OR conditions, operations like sorting and grouping can utilize a lot of resources. In the case of AND conditions, it makes more sense to use a multicolumn index over multiple single-column indexes.</p><h4>Other Things to Note</h4><ol><li>Indexes are implemented at the storage engine level and not the server level; hence differ from engine to engine.</li><li>Even though we use an ORM, we can’t rely on it for indexing as they usually generate queries that satisfy the underlying logic.</li><li>Indexes come with drawbacks as well. There is a performance impact on INSERT, UPDATE, and DELETE operations. Every time we perform a write on a table, the indexes have to be maintained. Hence, it&#39;s important to choose Index wisely.</li><li>Always Test the indexes on the queries the application is performing by measuring the response time.</li><li>Using the EXPLAIN statement to understand how the query is executing and reveal why it is slow. Explain statement shows values such as the indexes used, order used for joining the table, rows accessed, use of Filesort or not, and a temporary table used or not.</li></ol><p>I hope this article helps you in starting to use Indexes in your MySQL Databases.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed4535998863" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoding Web Scraping with Python]]></title>
            <link>https://python.plainenglish.io/decoding-web-scraping-with-python-9fcd7371b7fb?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fcd7371b7fb</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sat, 03 Jun 2023 09:50:44 GMT</pubDate>
            <atom:updated>2023-06-21T10:24:25.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fJZUfPK6DC0Bq0hZ" /></figure><p>Web scraping has become an important technique for extracting valuable information from websites. With the growing need for data-driven insights, web scraping provides a powerful means to gather data from various sources on the internet.</p><p>In this blog post, we will delve into the world of web scraping with Python, exploring its definition, differences from web crawling, traditional methods, implementation with Python, how can the data be utilized, importance, and ethical considerations.</p><h3>What is Web Scraping?</h3><p>Web scraping refers to the automated extraction of data from websites. It involves parsing the HTML structure of web pages, extracting specific data elements, and storing them in a desired format, such as a CSV or database. By automating the retrieval of data, web scraping saves time and effort compared to manual data collection.</p><h3>Web Scraping Vs Web Crawling</h3><p>Although the terms web scraping and web crawling are frequently used interchangeably, they are not the same thing.</p><p>Web scraping typically involves extracting specific data from targeted web pages, whereas web crawling entails traversing the web systematically in order to index or analyze web content.</p><p>A web crawler starts with a seed, which is a list of URLs to visit. The crawler finds links in the HTML for each URL, filters those links based on specific criteria, and then passes those links to a scraper so that the desired information can be extracted from them.</p><p>Web scraping is a subset of web crawling that serves more specific purposes such as obtaining product information, obtaining customer reviews, or gathering news articles.</p><h3>Traditional Methods of Web Scraping</h3><p>Before the libraries with Python came into the picture, the go-to methods to get data from the internet including:</p><ol><li><strong><em>Regular Expressions:</em></strong> To extract data from structured HTML documents, regular expressions were commonly used. We could use regex syntax to define patterns that would match specific data elements within the HTML source code. Regex-based scraping, while powerful, was limited to cases where the HTML structure was predictable and consistent. Handling complex or nested structures with regular expressions can be difficult and error-prone.</li><li><strong><em>Manual Copying and Pasting:</em></strong> Manually copying and pasting data from websites into a local file or spreadsheet was one of the earliest and simplest methods of web scraping. This method worked well for scraping small amounts of data, but it became inefficient and time-consuming for larger-scale scraping tasks.</li></ol><p>These traditional methods had drawbacks. They worked best with static websites with simple HTML structures and struggled with dynamic or JavaScript-rendered content. Furthermore, these methods were less scalable and necessitated a significant amount of manual labor, making them inefficient for large-scale data extraction tasks.</p><h3>Web Scraping with Python</h3><p>Some widely used Python libraries for web scraping include BeautifulSoup, Scrapy, Selenium &amp; Extruct.</p><p><strong>BeautifulSoup</strong></p><p>BeautifulSoup is used for parsing HTML and XML documents. Beautiful doesn’t directly interact with the server of the URL we are trying to scrape. We need to use libraries request to get the response data from the URL. Once that is done, we can use a parser like html.parser or lxml&#39;s parser to get the HTML content. Once we have the HTML content, we can fetch the required data.</p><p>We can use Beautiful when we need to extract data from a single webpage or webpages of the same HTML structure which don’t require complex navigation. <em>One drawback with BeautifulSoup is, it works only for static web pages.</em></p><pre>import requests<br>from bs4 import BeautifulSoup<br><br>url = &quot;https://beautifulsoup.com&quot;<br>response = requests.get(url)<br><br># Parse the HTML content<br>soup = BeautifulSoup(response.content, &quot;html.parser&quot;)<br><br># Extract data in the title tag from the parsed HTML<br>title = soup.title.text<br>print(&quot;Title of the page is &quot;, title)</pre><p><strong>Selenium</strong></p><p>Selenium is a web testing framework that allows automated browser interactions. It can be used for web scraping by controlling a browser instance and extracting data from <em>dynamic or JavaScript-driven web pages</em> which is one of its major advantages.</p><pre>from selenium import webdriver<br><br># Configure the chrome webdriver<br>driver = webdriver.Chrome()<br><br># Load the web page<br>url = &quot;https://selenium.com&quot;<br>driver.get(url)<br><br># Extract data in the title tag using Selenium<br>title_element = driver.find_element_by_tag_name(&quot;title&quot;)<br>title = title_element.text<br>print(&quot;Page title:&quot;, title)<br><br># Close the browser<br>driver.quit()</pre><p>We can also combine Selenium with BeautifulSoup to get content rendered dynamically. Selenium automates web browser interaction. Hence the data rendered by JavaScript links can be made available with Selenium and then can be extracted using Beautiful Soup. Below is a snippet of how to use the combination of the two.</p><pre>soup = BeautifulSoup(driver.page_source, &#39;html.parser&#39;)<br>title = soup.title.text</pre><p><strong>Extruct</strong></p><p>Python’s extruct library is useful for extracting structured data from web pages. The extruct library comes in handy when you need to extract structured data from web pages, such as microdata or json-ld. It makes it simple to access and process structured information embedded in HTML. We need requests to load the web page data, just like BeautifulSoup.</p><pre>import requests<br>from extruct.jsonld import JsonLdExtractor<br><br># Make a request to the website<br>url = &quot;https://extruct.com&quot;<br>response = requests.get(url)<br><br># Extract JSON-LD structured data from the HTML content<br>extractor = JsonLdExtractor()<br>data = extractor.extract(response.text)</pre><p><strong>Scrapy</strong></p><p>Scrapy offers an integrated method for following links and extracting data from multiple pages. Scrapy is typically used to scrape data from multiple pages, follow links in web crawling, handle pagination, and perform more complex scraping tasks. It includes advanced features such as middleware, pipelines, and built-in asynchronous request handling. One disadvantage of Scrapy is that it does not support JavaScript by default, instead relying on Splash.</p><pre>import scrapy<br><br>class MySpider(scrapy.Spider):<br>  name = &quot;example_spider&quot;<br>  start_urls = [&quot;https://scrapy.com&quot;]<br><br>  def parse(self, response):<br>    # Extract title tag data from the response<br>    title = response.css(&quot;title::text&quot;).get()<br>    print(&quot;Page title:&quot;, title)</pre><h3>Analyzing &amp; Storing Data</h3><p>Now that we have the data from the web, we can save it in the formats we want, such as CSV or databases. We can use Python libraries such as Pandas for data cleaning, transformation, and obtaining the final version of our preprocessed data.</p><p>Next, we can use Matplotlib or Seaborn to understand the trends, patterns, or correlations in the scraped data.</p><p>We can use Natural Language Processing to perform sentiment analysis on data containing customer reviews or movie reviews.</p><p>There are numerous applications for Machine Learning in scraped data.</p><h3>Importance of Web Scraping</h3><p>Web scraping is important in many industries. It aids in the monitoring of product prices, the analysis of customer reviews, and the tracking of competitors in e-commerce. Web scraping is used in finance for stock market analysis, tracking economic indicators, and collecting financial data. It is useful in investigative reporting and data journalism.</p><p>The applications are numerous, and web scraping enables businesses to remain competitive and make data-driven decisions.</p><h3>Ethical Consideration &amp; Best Practices</h3><p>Some Ethical &amp; Best Practices for web scraping include:</p><ol><li><strong><em>Respecting website policies:</em></strong> Check the website’s terms of service and robots.txt file to ensure compliance with their guidelines.</li><li><strong><em>Rate limiting:</em></strong> Implement delays between requests to avoid overwhelming the target website’s server and potentially causing disruption.</li><li><strong><em>Adding User Agents:</em></strong> Include a user agent in your HTTP requests that identifies your web scraping script. This allows website owners to contact you if needed.</li><li><strong><em>Scraping public data:</em></strong> Focus on scraping publicly available data and avoid sensitive information or private areas of websites.</li></ol><p>Hope this article helps you in getting a brief overview of Web Scraping &amp; how it can be achieved using Python.</p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/decoding-web-scraping-with-python"><em>https://blog.shlokashah.com</em></a><em>.</em></p><h4>Further Reading on Web Scraping</h4><ul><li><a href="https://javascript.plainenglish.io/what-is-web-scraping-and-how-to-scrap-a-website-using-node-6e82da37b3f5">How to Scrape a Website using Node.js &amp; Use Node.js and React to Create a Web Scraper</a></li><li><a href="https://javascript.plainenglish.io/common-anti-scraping-measures-on-websites-and-how-to-bypass-them-a32de1b066a2">Common Anti-Scraping Measures on Websites and How to Bypass Them</a></li><li><a href="https://javascript.plainenglish.io/scraping-youtube-with-this-headful-remote-web-scraping-browser-5e2448c8b54">Scraping YouTube With This ‘Headful’ Remote Web Scraping Browser</a></li></ul><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fcd7371b7fb" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/decoding-web-scraping-with-python-9fcd7371b7fb">Decoding Web Scraping with Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Model Deployment Strategies]]></title>
            <link>https://python.plainenglish.io/ml-model-deployment-strategies-26b27a1fb414?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b27a1fb414</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sun, 26 Mar 2023 12:59:50 GMT</pubDate>
            <atom:updated>2023-03-28T15:03:24.672Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c7eLCDv0Ov4Ua7mC" /></figure><p>Deploying any ML Model to production involves certain challenges which include:</p><ol><li><strong><em>Concept Drift &amp; Data Drift</em></strong><em>:</em> Concept Drift is basically when the relationship between the training variable &amp; the target output changes whereas data drift is the change in the distribution of the data over time. Both can lead to a decline in the model’s performance.</li><li><strong><em>Software Engineering Issues</em></strong><em>:</em> When we are deploying an ML Model there are certain factors that we need to think about, for example, the latency &amp; the throughput needed, whether to have real-time or batch predictions. How to log the results for monitoring &amp; maintaining the security &amp; privacy of data.</li></ol><p>When we train Machine Learning using a specific algorithm, the best way to deploy the model in production depends on a number of factors:</p><ol><li>The acceptable downtime of our Machine Learning Solution.</li><li>The operation cost &amp; the human involvement in deploying the model.</li><li>The ease with which we can roll back the model in case of a drift.</li><li>Whether there is a need to test with production traffic or not.</li></ol><p>Now that we have understood what are the different challenges in deploying a Model, let’s take a look into the different deployment strategies.</p><h3>Recreate Deployment</h3><ol><li>In this strategy, we scale down the prior model before scaling up the new model version. Because it takes time to scale down the current model and scale up the new model version, the recreate technique is slow and causes downtime for the ML solution. Because we just have one version of the model, this strategy is incredibly straightforward to use. Recreate Deployment is not a scalable method and is best suited for small-scale applications.</li><li>We should use the Recreate Deployment when we can afford downtime with the product or when we don’t want the new deployment to be backward compatible.</li><li><strong><em>Example:</em> </strong>In Machine Learning applications where we run the predictions in the form of batches.</li></ol><h3>Shadow Deployment</h3><ol><li>Shadow Deployment technique is used when we already have an ML model running in production. We used this technique to run the new model alongside the existing one in production. The forecast from the previous model is returned to the application, while the response data from the new model is saved for testing and comparing the outcomes. We require sufficient monitoring to access performance and must operate more servers for the new prediction service.</li><li>We should use Shadow Deployment when we want to test the new version across actual production data &amp; at the same time don’t disrupt the existing users.</li><li><strong><em>Example</em>:</strong> In Machine Learning applications where we want to forecast the business performance or growth, we can use shadow deployment to compare the predicted value from the model &amp; actual growth.</li></ol><h3>Gradual Ramp-Up with Monitoring</h3><p>The next 2 deployment strategies involve releasing the model for a certain % of users &amp; then based on the performance monitoring, making it available to 100% of users.</p><h3>Canary Deployment</h3><ol><li>In Canary Deployment, we have the old &amp; new versions both running in production &amp; serving the application. The major difference between canary &amp; shadow deployment is that in Shadow, the response data from the new model is used for performance monitoring whereas here it is used to serve the application. The new model version is made available to a minimum set of users and then exposed to the entire set.</li><li>We should use Canary Deployment when we want to test the new version across actual production data &amp; at the same time evaluate the existing user’s response to the model. It allows us to spot problems early on before there are maybe overly large consequences to the application with no downtime.</li><li><strong><em>Example</em>:</strong> In Machine Learning applications that serve as recommendation systems like content or product. We can compare the interactions of different users with different models applied &amp; then determine which was effective in providing recommendations</li></ol><h3>A/B Testing Deployment</h3><ol><li>As the name suggests in A/B Testing Deployment, we have many different versions of the model. We divide the users into different groups based on the number of models we have &amp; then decide the best model based on the performance &amp; the user’s interaction. With A/B testing we can discard the low-performing models fast with no downtime.</li><li>We can use A/B testing deployment when we have a couple of models which provide almost similar results. With this technique, we can determine the best model using production data &amp; response.</li><li><strong><em>Example</em>:</strong> Similar to Canary Deployment, A/B Testing can also be used for recommendation systems like content or product recommendation.</li></ol><h3>Blue-Green Deployment</h3><ol><li>The blue-green deployment is accomplished by utilizing an existing prediction service. Then, as the staging environment, we build a new prediction service, the green version. Once the performance and functionality testing in the green environment is completed, we have the router switch traffic from the old to the new. It incurs additional costs due to the upkeep of various settings. The benefit of a blue-green deployment is that it enables simple rollback. If something goes wrong, we may simply reset the router or switch to the blue version to divert traffic.</li><li>We can use Blue-Green deployment when the application can afford no downtime and backward compatibility is required.</li><li><strong><em>Example</em>:</strong> Real-time prediction system like fraud/anomaly detection.</li></ol><p>Below is a brief table of differences based on the explanation of each method and the four main considerations we mentioned above for picking a deployment strategy. I hope this article helps you select the right deployment strategy for your Machine Learning applications.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fairtable.com%2Fembed%2Fshrsb51dGnW1o0gbH&amp;display_name=Airtable&amp;url=https%3A%2F%2Fairtable.com%2Fshrsb51dGnW1o0gbH&amp;image=https%3A%2F%2Fstatic.airtable.com%2Fimages%2Foembed%2Fairtable.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=airtable" width="800" height="533" frameborder="0" scrolling="no"><a href="https://medium.com/media/610019b28975a8a870df75d2cc4473ec/href">https://medium.com/media/610019b28975a8a870df75d2cc4473ec/href</a></iframe><p><em>Originally published at </em><a href="https://blog.shlokashah.com/ml-model-deployment-strategies"><em>https://blog.shlokashah.com</em></a><em>.</em></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b27a1fb414" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/ml-model-deployment-strategies-26b27a1fb414">ML Model Deployment Strategies</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flip Side]]></title>
            <link>https://shlokashah.medium.com/flip-side-d75dd26795ac?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/d75dd26795ac</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Wed, 01 Mar 2023 17:21:09 GMT</pubDate>
            <atom:updated>2023-03-01T17:21:09.624Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wkvvNZywFmCEFswb" /></figure><p>Recently I had the chance to go as a mentor and judge for a couple of Hackathons. During my time in college, I participated in a lot of hackathons, but this was my first time serving as a mentor or judge.</p><p>As a contestant, I believed it was simple for the judges to determine the outcomes or how simple it was for them to give the teams advice. Being on the other side of the table helped me to realize that both sides require the same amount of preparation.</p><p>There is a similar sense of anxiety or nervousness on both sides. Developing and pitching your solution properly is the biggest challenge for a contestant while judging your solution based on a fair evaluation is the biggest challenge for a judge.</p><p>My primary learnings from the experiences were the following.</p><ul><li>The contestants must design a distinctive solution to the problem, while the judges must understand the problem statement, think of all possible solutions, and evaluate using the right technology.</li><li>Similarly to how participants need to be prepared to deal with any questions that might come their way during the pitch, mentors need to have answers/suggestions to questions participants might ask.</li><li>I realized during the mentoring session that you need to control the developer inside of you. When teams came up and mention bugs/errors they are experiencing, it’s tempting to grab the laptop and fix them. However, you need to control yourself and provide them with the right information.</li><li>Just as teamwork is required in participation, it is also needed between the judging panel members. An agreement needs to be reached on the evaluation criteria and the scoring system.</li></ul><p>Thus there’s no need to be intimidated by the evaluator if you’re just starting to take part in hackathons. Keep in mind that both parties are under equal pressure, for the participant it is to produce the finest idea and pitch, while the judge is under pressure to render a fair judgment.</p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/flip-side"><em>https://blog.shlokashah.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d75dd26795ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Tech Talk]]></title>
            <link>https://shlokashah.medium.com/my-first-tech-talk-fadd176ee266?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/fadd176ee266</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tech-talk]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sat, 11 Feb 2023 08:02:26 GMT</pubDate>
            <atom:updated>2023-02-11T08:02:26.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-vkUbmGJtgvZZ9FF" /></figure><p>It was an afternoon in September &amp; I was having a discussion with <a href="https://in.linkedin.com/in/sp2hari">Hari</a>. While discussing, he gave me a new task. This is a screenshot of what we wrote in a document. In the next 6 months, I had to first attend a conference &amp; then give one external tech talk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lYA68vW2FAiGDomi" /></figure><p>Being my first time doing one, the prospect of presenting a Tech Talk was both exciting and scary.</p><p>Now that I had to give a talk, the most important thing was to find a conference. Since I had been working on Ruby on Rails, the idea was to find a Ruby-related conference and submit the CFP there.</p><p>In November, I came across the <a href="https://events.geekle.us/ruby/">Ruby on Rails Global Summit by Geekle</a>. I intended to attend this summit, observe the speakers’ presentations, and then submit a CFP for any upcoming Ruby conferences I could find. The CFPs were still open though.</p><p>I told my idea to Hari, he convinced me that since the CFPs are open, I should submit one &amp; if I don’t get selected I can always come back to attend the summit. This way my plan of attending the summit was now changed to speaking at the summit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XE7g-xyjn7y9TQsb" /></figure><h3>Submitting the CFP</h3><p>Since the CFPs had been open for some time, many of the topics I was thinking to speak on were already taken. I finally decided to speak on Rubocop, since I had been working on it for some time. The plan was to show a live demo on modifying cops &amp; showing the before &amp; after results. After various iterations on the abstract &amp; title I finally submitted my first ever CFP — <strong><em>Enhancing Code Quality with Rubocop</em></strong>.</p><p>During mid-December, <a href="https://www.linkedin.com/in/liliya-kravchak-975a09206/">Liliya</a> from the <a href="https://www.linkedin.com/company/geekle-us/">Geekle</a> team reached out &amp; yes the CFP was accepted, I was now giving my very first Tech Talk.</p><h3>Preparing for the Talk</h3><p>Since the talk was in January, I was pretty chilled out when I received the acceptance. I had already written a <a href="https://blog.shlokashah.com/configuring-rubocop-in-code-base">blog</a> on Rubocop so I felt that I could manage the talk.</p><p>When I got another email with information on the platform we would be utilizing and promotional banners for my talk, that’s when I started to freak out as I realized the scale of the conference. To make sure everything was set up, I was requested to schedule a test call with the technical team.</p><p>During the technical call, they walked me through the Streamyard platform, how screen sharing works, and all other minor details.</p><p>When the call was over, that’s when I first felt tense. I started overthinking even simple things like screen sharing because I was so new to the platform. What if I share the wrong screen or my internet goes out? Furthermore, I had to code live in front of my audience. What happens if my code malfunctions? I began to wonder if I ought to have recorded the presentation beforehand and submitted it. But it was time to push past your comfort level.</p><p>To avoid any problems that might arise during the discussion, the idea was to prepare the slides and run through the full flow as many times as I could. Also to get an idea of how people usually do it, I went to youtube &amp; watched various talks given by developers I had heard of.</p><h3>Practicing the talk</h3><p>Once I had the talk ready, I practiced them &amp; that is when I realized, I need to restructure the slides. Since I had a combination of theory &amp; code, I had to make sure there was proper spacing between the two, so that the content was easy to consume. I reordered and practiced again. I realized the speed at which I was talking was too fast &amp; need to slow down.</p><p>I showed Hari a demo of my talk two days before the event, and he offered me revisions as feedback. This was quite helpful. The most significant piece of advice I received was to interact with the audience &amp; make the talk more engaging.</p><p>I began to consider ways to include audience participation in the presentation. The options for participation were restricted because it was an online conference and nobody’s video would be turned on. As a result, I incorporated surveys in the form of QR codes and invited the audience to participate in the coding.</p><p>Once I had the final slides, I did a final demo talk with <a href="https://linkedin.com/in/ishandeveloper">Ishan</a> &amp; again with Hari. Giving demos helped in boosting my confidence.</p><p>On the day of the talk, I played around with the commands &amp; the code two or three times to make sure that everything was running as expected.</p><h3>Going Live</h3><p>All the nervousness vanished as soon as I began to speak because I became absorbed. During the talk, I wasn’t able to see whether people were answering my questions or the poll but when I completed the talk &amp; checked, I was happy to see that the audience engaged with me &amp; answered the polls. Some people even reached out on LinkedIn with positive comments.</p><p>Overall, it was a fantastic experience &amp; I am glad I went live instead of pre-recording.</p><p><strong><em>PS: You can find my talk here :)</em></strong> <a href="https://youtu.be/H7ggpT_ZFIQ">https://youtu.be/H7ggpT_ZFIQ</a></p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/my-first-tech-talk"><em>https://blog.shlokashah.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fadd176ee266" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retrospective — A developer’s POV]]></title>
            <link>https://shlokashah.medium.com/retrospective-a-developers-pov-45f3feff4c70?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/45f3feff4c70</guid>
            <category><![CDATA[retrospectives]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineer]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sun, 18 Dec 2022 06:54:53 GMT</pubDate>
            <atom:updated>2022-12-18T06:58:25.172Z</atom:updated>
            <content:encoded><![CDATA[<h3>Retrospective — A developer’s POV</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ORXsuVA-VwVS8ITg" /></figure><p>As the year comes to a close, this blog post will discuss the importance of Retrospectives from the perspective of a developer.</p><p>What is a retrospective, to begin with? Wikipedia’s description</p><blockquote><em>A retrospective (from Latin retrospectare, “look back”), generally, is a look back at events that took place, or works that were produced, in the past.</em></blockquote><h3>First, why is it important to write a personal retrospective</h3><ul><li><strong><em>Avoid Recency Bias:</em></strong> It is a typical fact that we tend to remember recent events better than events that occurred in the past, giving the recent event more significance. It’s wise to pause, take a step back, and reflect on our past actions in order to avoid this bias.</li><li><strong><em>To comprehend what you have learned:</em></strong> To identify the important areas where you need to improve, make a list of all the lessons you’ve learned.</li><li><strong><em>To consider what went wrong:</em></strong> Reflecting on situations when your work fell short of expectations or where you encountered difficulties will help you identify potential mistakes you shouldn’t make.</li><li><strong><em>Understanding your preferences:</em></strong> There will be many different jobs that you have worked on. While some may be of interest to you, others won’t. You can request more tasks if you have a detailed list of your preferences.</li></ul><h3>What can be the format of the retrospective?</h3><ul><li>If you worked on several projects over the quarter or year, you can break up the retrospective into each project’s learnings and successes part.</li><li>The alternative strategy involves combining ideas like learning, successes, failures, preferences, and dislikes.</li></ul><h3>How can you start writing your retrospective?</h3><ul><li><strong><em>Gather all the data points:</em></strong> This, in my opinion, is the most crucial action. You can review the data from the SCM you use to understand all languages, code bases, and even the kind of issues you worked on. To learn the theme and the list of languages, look at the commit messages and file types. Moreover, you can look at project management systems like JIRA to determine whether you focused more on Debugging or Features throughout your time. Review all the different architecture-related guilds that you have been a part of.</li><li><strong><em>Random notes from the past:</em></strong> Due to recency bias, which we discussed above, there are likely to be some little but significant events from the year that you will soon forget. These may be difficult problems to fix, a team discussion about the architecture, a few support tickets, or anything else. The notes don’t have to be flawlessly formatted; a few bullet points can do the trick and serve as a recall of the entire scenario when you go back to it. I personally record everything that comes to me using the self-messaging function in Slack.</li><li><strong><em>Initial Thoughts:</em></strong> Wait a while before beginning to write a well-organized reflection. Make a list of all the things in the form of bullet points that come to mind when you think of retrospect as you stop. I usually prepare a list of every point I want to make in my retrospective before going into more detail on each one.</li></ul><p>Even while we may believe that writing a retrospective is simple, it actually requires a lot of thought and perseverance.</p><p>A personal retrospective is written similarly to a Root Cause Analysis of any technical incident, with the exception that in this case, the RCA is based on the individual.</p><p><em>Also published </em><a href="https://blog.shlokashah.com/retrospective-a-developers-pov"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45f3feff4c70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Debugging]]></title>
            <link>https://shlokashah.medium.com/the-art-of-debugging-5ca1e94aed15?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ca1e94aed15</guid>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 12:08:19 GMT</pubDate>
            <atom:updated>2022-11-19T12:08:19.161Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4z7KaBg44NgHbptr" /></figure><p>As software engineers, debugging is an integral part of our jobs. You may have times as a Software Engineer when you are more concerned about fixing bugs than developing novel features.</p><p>A debugging process can be divided into two categories:</p><ul><li><strong><em>Active:</em></strong> In this step, you investigate all methods of fixing the bug by altering the code. The next steps are developing a hypothesis as to whether the solution will work and implementing it.</li><li><strong><em>Passive:</em></strong> For passive debugging, we use logging when the bug cannot be reproduced, so we cannot run through the execution steps.</li></ul><p>Throughout this blog post, I’ll share some of the debugging practices I adopted and have now become part of my debugging process.</p><p>It is essential to remember that if a bug exists, even if you are not experiencing it, it implies that something is definitely off with the code. This could be logic, a dependency issue, or a missed edge case.</p><h3>Go Back in the History</h3><p>Gathering all available historical information about the issue is the first step in debugging. This typically allows you to identify whether the problem is persistent or whether it has never been fixed. There may be a log, error note, screenshot, and perhaps some old message exchanges.</p><p>SCM also allows you to view all of the file’s previous modifications. Different Git extensions in the IDE can help with this process. Going back in time and discovering even the smallest indication might occasionally inspire an idea when you are absolutely baffled as to how the bug is happening.</p><h3>Read Read Read</h3><p>Sometimes, half of the issues may be solved by just reading the code and tracing back all the functions.</p><p>In my experience, after locating the API Endpoint where the problem occurred, I look for the method connected to it and then attempt to visualize the flow by creating a mental model of the code.</p><p>Once you comprehend the code, you may add breakpoints (eg: <em>binding.pry in Rails</em>) to the code to verify your comprehension.</p><h3>Talk to Yourself</h3><p>When working on a complicated problem, speaking aloud to yourself might occasionally disclose blind spots.</p><p>I try putting it down in the manner of what I would advise someone to do if they were in a similar circumstance if thinking aloud doesn’t help.</p><p>Simply write down everything you know about the bug so that when you see it all written out in front of you, your mind will start to fill in the blanks.</p><h3>Add Logs Everywhere</h3><p>One of the most popular debugging techniques is this one. It entails inserting logs into the code at various locations-basically, before and after every function call.</p><p>Adding logs can help you understand the state of a variable whose value is changing across many functions.</p><h3>Play Around to Reproduce the Bug</h3><p>As a result of the discovery of the defect, we can conclude that the code is flawed. In huge code bases, it is essential to reproduce problems that only appear under a certain set of circumstances.</p><p>In order to understand the set of conditions, all the data points can be gathered as you analyze the database values. Try finding a pattern across all the users for whom the error has been occurring. You can then experiment with a different set of conditions to correct the issue.</p><p>To further aid in the debugging of edge cases, the code may be significantly modified to include early returns, conditional returns, etc.</p><p>Forgetting what you know about the product is a crucial step in trying to recreate something. Typically, when we have been working on something for a very long time, we are familiar with all the tricks and know what will work and what won’t. Due to this, the bug’s reproduction is biassed. Consider your product from the user’s perspective and create the most absurd scenario possible.</p><h3>It’s not always some Big Change</h3><p>When you encounter a bug, don’t always think of the issue to be some big code change or rewrite. Start small.</p><p>Check for null values, any before action validations, if else conditions.</p><p>When I originally started, I believed that significant modifications would be necessary, but over time, I’ve learned that it’s better to focus on the little aspects first.</p><h3>Read the Unit Tests</h3><p>You can start by reviewing the unit tests for that specific piece of code if you are entirely perplexed by the various edge situations the function handles.</p><h3>Talk to the Code Owner</h3><p>There is a possibility that you will not always have to debug something that you have worked on. When this happens, it can be helpful to speak to someone with a broader understanding.</p><p>You can bounce your ideas for solving when working on a critical flow, if modifying something, with the working team to ensure you haven’t missed any edge cases.</p><h3>Have a Proper Alert &amp; Monitoring System</h3><p>Using tools like HoneyBadger, and Sentry can help you keep a log of the errors. You can add them to all your APIs &amp; critical workflows.</p><p>Other than alerting, you can have a logging system, where you can monitor the routes that are being called in actual production.</p><h3>Document it</h3><p>The most crucial step is the last: once you’ve identified the cause of the problem, remember to record it for the future you.</p><p>Lastly, if none of the above steps work, take a break, come back and start again.</p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/the-art-of-debugging"><em>https://blog.shlokashah.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ca1e94aed15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 Things I’ve Learned as a Software Developer]]></title>
            <link>https://shlokashah.medium.com/things-learned-as-a-software-developer-960ecbf9aa9e?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/960ecbf9aa9e</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[software-developer]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sun, 16 Oct 2022 11:17:40 GMT</pubDate>
            <atom:updated>2022-10-16T17:26:09.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzJ-AyGOpI3Ghg0-Z2kajw.jpeg" /></figure><p>In this Blog Post, I share some of the things I have learned so far while working as a Software Developer.</p><h3>Document Everything</h3><p>Documenting can be classified into four types:</p><ul><li><em>The tasks you need to complete:</em> Team members use product management tools to track tasks, but maintaining a personal TODO list is extremely helpful. On a regular basis, the list can be created. In retrospect, you can mark off the tasks that you were able to complete. I usually like to maintain a daily TODO list.</li><li><em>Maintaining your blog:</em> Recently, I also began this &amp; it has helped me organize my thoughts and easily document the things I have learned. It helps you think about your problems and communicate them more effectively when you write.</li><li><em>The work you have done:</em> Consider keeping a journal of your work so that you can reflect on your performance. As a result, you’ll have a clearer idea of what you’ve learned.</li><li><em>Things that pop up randomly:</em> While working, you may get some questions or find something interesting related to your work, or the approach to solving a problem may be complicated. Be sure to document it. The complicated approach becomes easier to convey when you write it for yourself.</li></ul><h3>If something doesn’t work, leave it for sometime</h3><p>In development, we often end up coding all the time while trying to solve a problem/bug. The brain reaches a saturation point at which it is no longer productive.</p><p>When I would get some issues in the past, I had a policy of not sleeping or taking a break until the bug was resolved. It only took me some time to realize that having some breaks reduced the time it needed to fix the bug.</p><p>Now when I get stuck on code, I take a break for 10/15 minutes, and when I returned, the code ran fine with minor adjustments.</p><p>Sleeping over an issue has also been beneficial. As soon as I awoke after sleeping, the solution that I had been unable to find after hours of research came to me in minutes. Sometimes the solution felt like a Deja Vu dream.</p><h3>Not always about coding</h3><p>Being a Software Developer doesn’t mean you need to code daily.</p><p>It is sometimes necessary to spend hours reading the code to figure out the root cause of the bug, gain a better understanding of the issue, or find different approaches to the problem.</p><p>There have been some bugs where the actual code change was only 1–2 lines, but it took me hours to research and go through the code.</p><h3>Consistency</h3><p>You don’t have to be an expert at everything all the time. You will become proficient at it only if you practice it repeatedly.</p><p>The first time you do something similar, you will probably make mistakes. However, the next time you do it, you will already know what to do and what not to do. Your brain will follow along automatically.</p><h3>You Never Stop Learning</h3><p>Technology is a vast field that is advancing every day. The work you do on a daily basis will teach you things, but it usually happens in a chaotic way.</p><p>A book, course, or blog can be very helpful for learning stuff in a structured manner.</p><p>Furthermore, you can gain knowledge from other developers with different experiences &amp; journeys. Learning is a continuous process.</p><h3>Every piece of code should be run once</h3><p>Whenever I make a change to code, I test it after someone reviews it and asks for a change, and before merging it to master after getting the approval.</p><p>You never know what might fail if you don’t test every change. You’re better off delaying a feature than pushing one that has flaws.</p><p>Whenever you write code, you should test it before you put it into production.</p><h3>The process of breaking down into smaller pieces</h3><p>Take each part of a problem and divide it into small achievable goals, whenever you encounter them.</p><p>My usual approach is to think about the dependencies involved in solving the problem. Then search for solutions to each of the dependencies. Your brain automatically gets motivated to tackle the larger problems as soon as you begin solving the smaller ones.</p><p>By creating a flowchart or list of smaller tasks to be completed, you have the requirements clearly in front of you. All you need to do now is think of the solution.</p><p>These are some of the things I have learned so far as a Software Developer. I hope you find these tips useful in your journey as a software developer at whatever level you find yourself.</p><p><em>Also published </em><a href="https://blog.shlokashah.com/things-learned-as-a-software-developer"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=960ecbf9aa9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Rubocop in Code Base]]></title>
            <link>https://shlokashah.medium.com/configuring-rubocop-in-code-base-55e094958caf?source=rss-c22d15327617------2</link>
            <guid isPermaLink="false">https://medium.com/p/55e094958caf</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[rubocop]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Shloka Shah]]></dc:creator>
            <pubDate>Sat, 24 Sep 2022 14:42:21 GMT</pubDate>
            <atom:updated>2022-09-24T14:49:57.962Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XsZkA-2HLg_FUI9xtIs5AA.png" /></figure><p><em>Rubocop is a code-style linter for Ruby based on the official </em><a href="https://rubystyle.guide/"><em>Ruby style guide</em></a><em>. Rubocop supports autocorrection &amp; is flexible in terms of the configuration of various cops based on our preference.</em></p><p>In this blog post, we discuss the various steps on how we can improve code quality using Rubocop in our codebase.</p><h3>Why do we need Rubocop?</h3><ol><li><strong>Creating a Standard</strong>: There are various patterns in which developers write code. To harmonize the coding style, we can use Rubocop. By enabling and disabling rules with Rubocop, we can discuss with the team what good practices we need to follow.</li><li><strong>Ease the process of understanding &amp; reviewing code</strong>: Sometimes, when a PR is sent for review, the reviewer might spend time commenting on the code style/format, such as extra whitespaces and missing lines at the end. By integrating Rubocop into pre-commit hooks and GitHub Actions, the developer can be made aware of offenses even before the PR is reviewed.</li><li><strong>Best Practices:</strong> As Ruby beginners, we may not be aware of the practices used by the Ruby community. In the form of various gems, Rubocop provides us with an excellent starting point for understanding all of them.</li></ol><h3>Rubocop Config</h3><p>In order to integrate Rubocop into our codebase, add the following gems to your Gemfile</p><pre>gem &#39;rubocop&#39;, &#39;1.23.0&#39;, require: false<br>gem &#39;rubocop-performance&#39;, &#39;~&gt; 1.12.0&#39;, require: false<br>gem &#39;rubocop-rails&#39;, &#39;~&gt; 2.12.0&#39;, require: false<br>gem &#39;rubocop-rake&#39;, &#39;~&gt; 0.6.0&#39;, require: false<br>gem &#39;rubocop-rspec&#39;, &#39;~&gt; 2.6.0&#39;, require: false</pre><ol><li><strong>rubocop-performance</strong>: <em>Performance optimization analysis</em>.</li><li><strong>rubocop-rails</strong>: <em>Rails best practices &amp; coding convention</em>.</li><li><strong>rubocop-rspec</strong>: Rspec (used for Ruby code testing) specific code analysis.</li></ol><p>The next step is to create the .rubocop.yml which contains the cops to be enabled/disabled, and the files that we don&#39;t want to run specific cops on.</p><p>An example can look like this</p><pre>require:<br>  - rubocop-performance<br>  - rubocop-rake<br>  - rubocop-rails<br>  - rubocop-rspec</pre><pre>AllCops:<br>  DisabledByDefault: false<br>  NewCops: enable<br>  TargetRubyVersion: 2.6.3<br>  Exclude:<br>    - db/schema.rb<br>    - node_modules/**/*<br>    - vendor/**/*</pre><pre>Layout/FirstArgumentIndentation:<br>  Exclude:<br>    - spec/controllers/api/payments_controller_spec.rb</pre><p>what this piece of code does is,</p><ul><li>excludes all files under AllCops::Exclude when running Rubocop</li><li>disables running of Cop Layout/FirstArgumentIndentation on the files under Exclude</li></ul><h3>Rubocop TODO Approach</h3><p>For existing projects, RuboCop provides a file .rubocop_todo.yml which records all the offenses from our codebase. Rather than having to fix everything at once, we can fix each offense as we touch the corresponding piece of code.</p><p>In order to generate the todo file use the command rubocop --auto-gen-config --exclude-limit 10000 which runs rubocop on your entire codebase and adds the offenses in the code as disabled.</p><p>--exclude-limit 10000 is a hack to make sure that Rubocop will not disable any cops in the .rubocop_todo.yml file.</p><p>An example of how the .rubocop_todo.yml will look like</p><pre># This configuration was generated by<br># `rubocop --auto-gen-config --exclude-limit 10000`<br># on 2022-09-24 07:33:55 UTC using RuboCop version 1.23.0.<br># The point is for the user to remove these configuration records<br># one by one as the offenses are removed from the code base.<br># Note that changes in the inspected code, or installation of new<br># versions of RuboCop, may require this file to be generated again.</pre><pre># Offense count: 8<br># Cop supports --auto-correct.<br># Configuration parameters: IndentationWidth.<br>Layout/AssignmentIndentation:<br>  Exclude:<br>    - &#39;app/controllers/home_controller.rb&#39;<br>    - &#39;app/helpers/application_helper.rb&#39;<br>    - &#39;app/helpers/regex_helper.rb&#39;</pre><p>The next step is to let rubocop know to ignore the files in .rubocop_todo.yml. You can do this by inheriting the file in the main config.</p><pre>inherit_from: .rubocop_todo.yml</pre><pre>inherit_mode:<br>  merge:<br>    - Exclude</pre><pre>require:<br>  - rubocop-performance<br>  - rubocop-rake<br>  - rubocop-rails<br>  - rubocop-rspec<br>...</pre><p>This is how your .rubocop.yml will look after configuring the todo file. Then when we run rubocop, it pulls the configuration from .rubocop.yml, which then pulls the configuration from .rubocop_todo.yml, which contains all the excluded files. Therefore, we won&#39;t see any offenses.</p><p>An added todo file does not mean that the offenses have been solved, it simply indicates that we have suppressed the warnings we were receiving repeatedly. As a result, the offenses remain present and now it is our responsibility to rectify each one individually.</p><p>The approach that we have been following at <strong><em>HackerRank</em></strong> to solve these offenses includes the following steps:</p><ul><li>Pick up a cop with offenses in the .rubocop-todo.yml file.</li><li>Read the documentation at <a href="https://docs.rubocop.org/rubocop/1.36/index.html">docs.rubocop.org/rubocop/1.36/index.html</a>.</li><li>Check if the Cop supports <em>Safe Autocorrection</em>.</li><li>Check the default enforced style for the Cop. Check if the Style is shared across various languages. The reason for this is to bring consistency among our developers.</li><li>If we change the enforced style, drop a note to the Engineering Team.</li><li>Finally, create a PR.</li></ul><p>It is important to not overcompensate for old code with many violations but to ensure that the new code adheres to the standards enforced by Rubocop config and to incrementally improve it.</p><h3>Configuring Cops</h3><p>As I was cleaning up the .rubocop-todo.yml file at HackerRank, we discovered that some cops needed configs different from what the official Ruby style guide recommends. Listed below are a few examples of those, along with the reason and how you can modify the defaults.</p><ol><li><a href="https://docs.rubocop.org/rubocop/cops_style.html#styleredundantreturn">Style/RedundantReturn:</a> In Ruby, the last line in a method is something that is returned, so the official style guide recommends avoiding returns unless necessary. However, we disabled this Cop for the following reasons:</li></ol><p>→ Almost all languages adhere to explicit returns, which makes transitioning between them easier for the developer.</p><p>→ It simplifies the code at first glance and doesn’t require any previous language-specific knowledge. When I first started with Ruby, I wasn’t aware of this, so when my code stopped working, I assumed a return statement was missing. Eventually, I realized that it wasn’t the return statement but something else.</p><p>You can disable this cop using the following piece of code in .rubocop.yml</p><pre>Style/RedundantReturn:<br>   Enabled: false</pre><p>2. <a href="https://docs.rubocop.org/rubocop/cops_style.html#stylewordarray">Style/WordArray</a>: For defining an array, the Style Guide recommends using the % format for strings that don&#39;t have any spaces. In the case of spaces using the %w will be considered an offense.</p><pre># bad<br> STATES = [&#39;draft&#39;, &#39;open&#39;, &#39;closed&#39;]</pre><pre># good<br> STATES = %w[draft open closed]</pre><pre># bad (contains spaces)<br> STR = %w[foo\ bar baz\ quux]</pre><pre># good (contains spaces)<br> STR = [&#39;foo bar&#39;, &#39;baz quux&#39;]</pre><p>There is a problem with this format if the strings have spaces (which is highly likely in a large codebase), there will be two different formats used in code: “Brackets” for strings with spaces and “%” for strings without spaces.</p><p>Additionally, brackets are a common format across many languages, so if a newcomer is trying to understand your code, they won’t have to learn all kinds of syntax first. We can bring consistency to our developers by using brackets.</p><p>For the above two reasons, we configured the default to Brackets. You can use the following piece in .rubocop.yml.</p><pre>Style/WordArray:<br> EnforcedStyle: brackets</pre><p>3. <a href="https://docs.rubocop.org/rubocop/cops_style.html#stylesymbolarray">Style/SymbolArray</a>: The configuration for this is similar to Style/WordArray.</p><pre>Style/SymbolArray:<br> EnforcedStyle: brackets</pre><p>4. <a href="https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmethodlength">Metrics/MethodLength</a>: The use of this cop to check if the length of a method exceeds some maximum value. The default is. 10 but you can take a look at your codebase and analyze the suitable number for it.</p><p>It also provides a configuration like <em>CountAsOne</em> which is available for array, hash, and heredoc where each literal will be counted as one line regardless of its actual size &amp; <em>IgnoredMethods</em> where we can provide the list of methods that we want the cop to ignore.</p><p>The approach we have been following includes:</p><ul><li>Taking the number for which most methods have offenses.</li><li>Set that as the Max limit.</li><li>Add the remaining methods as offenses.</li><li>Gradually decrease the limit.</li></ul><p>The goal was to avoid unnecessarily high lines of code in new methods and also not have to worry too much about refactoring old code.</p><pre>Metrics/MethodLength:<br> Max: 100<br> CountAsOne: [&#39;array&#39;, &#39;hash&#39;, &#39;heredoc&#39;]<br> IgnoredMethods: [&#39;a&#39;,&#39;b&#39;]</pre><p>These are some Cops which we have configured differently compared to the default Style Guide after discussing with the entire team.</p><h3>Maintaining the Standard</h3><p>Now that we have the configuration in place, we need to make sure that the new code written doesn’t contain the offenses.</p><p>To do this we can do the following:</p><ol><li>Make use of <em>pre-commit hooks</em> that run Rubocop across all the configured Cops.</li><li>Setup <em>Code Climate/Github Actions</em> that report offenses on the PR. You can also make these checks as required to pass for merging the code.</li></ol><p>PS: The following screenshot is a trend on how we have improved the code quality at <strong>HackerRank</strong> by cleaning up the .rubocop_todo.yml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6xfYH80rjY0T5lE7" /></figure><p>I hope this article helps to configure Rubocop in your code bases &amp; improve the code quality.</p><p><em>Originally published at </em><a href="https://blog.shlokashah.com/configuring-rubocop-in-code-base"><em>https://blog.shlokashah.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55e094958caf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>