<?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 Aidanmc on Medium]]></title>
        <description><![CDATA[Stories by Aidanmc on Medium]]></description>
        <link>https://medium.com/@aidanmc95?source=rss-495bab6e66fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HNDvhW3ZmpzhGYx4.jpg</url>
            <title>Stories by Aidanmc on Medium</title>
            <link>https://medium.com/@aidanmc95?source=rss-495bab6e66fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:36:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aidanmc95/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[Patching Array]]></title>
            <link>https://aidanmc95.medium.com/patching-array-7e0571d2b1e3?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e0571d2b1e3</guid>
            <category><![CDATA[greedy-algorithms]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 03 Jan 2021 02:49:31 GMT</pubDate>
            <atom:updated>2021-01-03T02:49:31.417Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a sorted positive integer array <em>nums</em> and an integer <em>n</em>, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number of patches required.</p><p>This is an interesting greedy problem because it is simple but makes you think. You could brute force this problem but the time complexity would be atrocious. The way you would go about it is checking every single value up to n and seeing if it could be created. Every time you cant create it you add the new value in. This would cause you to have to recalculate every time you check a value forgetting about every value before.</p><p>The better way to attack this problem is knowing that if you can create the values up to a value in the given array then you can create double that value minus 1. If you are unable to create something up to a given value then you need to add that value into the array. Then the same logic holds that you can create everything double its size minus 1.</p><pre>def minPatches(self, nums: List[int], n: int) -&gt; int:<br>        miss = 1; added = 0; i = 0;<br>        while(miss &lt;= n):<br>            if(i &lt; len(nums) and nums[i] &lt;= miss):<br>                miss += nums[i]<br>                i += 1<br>            else:<br>                miss += miss<br>                added += 1<br>        return added</pre><ul><li>miss: tracks what value we can create at this point</li><li>added: tracks the number of inclusion we need to make to get all sums</li><li>i: tracks what spot in the array we are at</li></ul><p>We will check values until miss is greater than or equal to the value we want. In each loop, we will check if i is still within the array and if it is less than or equal to miss. This will allow us to shift miss up by smaller increments and increase the range that we have. If either of these checks fails that means that the number we are trying to create cant be reached and we must add a new value.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e0571d2b1e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bucket Sort]]></title>
            <link>https://aidanmc95.medium.com/bucket-sort-15f9fbead657?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/15f9fbead657</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[bucket-sort]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 27 Dec 2020 05:22:23 GMT</pubDate>
            <atom:updated>2020-12-27T05:22:23.240Z</atom:updated>
            <content:encoded><![CDATA[<p>Bucket sort is constructed of two main parts, the hash and sort. The hash is the way that the information in the sorted array can be accessed in O(1) time. This is important because it allows the data to be easily accessed and changed quickly. The sort takes the smaller parts of the hash and sorts them thus allowing for much fewer data to be compared.</p><p><strong>THE BUCKET</strong></p><p>The bucket is the part that sorts the data and allows for easy access. Using a has is the simplest way to achieve this. Create an array that is the size of the given array and place the data into it based on its info.</p><pre><strong>def</strong> bucketSort(x):<br>    arr <strong>=</strong> []<br>    <br>    slot_num <strong>=</strong> 10 # 10 means 10 slots, each<br>    <br>    # slot&#39;s size is 0.1<br>    <strong>for</strong> i <strong>in</strong> range(slot_num):<br>        arr.append([])</pre><pre># Put array elements in different buckets<br>    <strong>for</strong> j <strong>in</strong> x:<br>        index <strong>=</strong> int(slot_num <strong>*</strong> j)<br>        arr[index].append(j)</pre><p>This function only works for elements that are between 0 and 1. It takes the floating-point and changes it to an int which correlates to the index in the array.</p><p><strong>THE SORT</strong></p><p>We are going to use a simple insertion sort to sort the different indices of the bucket.</p><pre><strong>def</strong> insertionSort(b):<br>    <strong>for</strong> i <strong>in</strong> range(1, len(b)):<br>        up <strong>=</strong> b[i]<br>        j <strong>=</strong> i <strong>-</strong> 1<br>    <br>        <strong>while</strong> j &gt;<strong>=</strong> 0 <strong>and</strong> b[j] &gt; up:<br>            b[j <strong>+</strong> 1] <strong>=</strong> b[j]<br>            j <strong>-=</strong> 1</pre><pre>        b[j <strong>+</strong> 1] <strong>=</strong> up</pre><pre><strong>    return</strong> b</pre><p><strong>PUTTING IT TOGETHER</strong></p><p>Now that we have all the parts connecting it all is simple. All we need to do is take the sort of each section of the bucket and then grab the sorted arrays out in order.</p><pre><strong>def</strong> insertionSort(b):<br>    <strong>for</strong> i <strong>in</strong> range(1, len(b)):<br>        up <strong>=</strong> b[i]<br>        j <strong>=</strong> i <strong>-</strong> 1<br>    <br>        <strong>while</strong> j &gt;<strong>=</strong> 0 <strong>and</strong> b[j] &gt; up:<br>            b[j <strong>+</strong> 1] <strong>=</strong> b[j]<br>            j <strong>-=</strong> 1</pre><pre>        b[j <strong>+</strong> 1] <strong>=</strong> up</pre><pre><strong>    return</strong> b</pre><pre><strong>def</strong> bucketSort(x):<br>    arr <strong>=</strong> []<br>    <br>    slot_num <strong>=</strong> 10 # 10 means 10 slots, each<br>    <br>    # slot&#39;s size is 0.1<br>    <strong>for</strong> i <strong>in</strong> range(slot_num):<br>        arr.append([])</pre><pre>    # Put array elements in different buckets<br>    <strong>for</strong> j <strong>in</strong> x:<br>        index <strong>=</strong> int(slot_num <strong>*</strong> j)<br>        arr[index].append(j)<br>   <br>    # Sort individual buckets<br>    <strong>for</strong> i <strong>in</strong> range(slot_num):<br>        arr[i] <strong>=</strong> insertionSort(arr[i])</pre><pre>    # concatenate the result<br>    k <strong>=</strong> 0<br>    <strong>for</strong> i <strong>in</strong> range(slot_num):<br>        <strong>for</strong> j <strong>in</strong> range(len(arr[i])):<br>            x[k] <strong>=</strong> arr[i][j]<br>            k <strong>+=</strong> 1<br>    <br>    <strong>return</strong> x</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15f9fbead657" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB]]></title>
            <link>https://aidanmc95.medium.com/mongodb-7efaf05b6c3c?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7efaf05b6c3c</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nosql-database]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 20 Dec 2020 06:51:39 GMT</pubDate>
            <atom:updated>2020-12-20T06:51:39.336Z</atom:updated>
            <content:encoded><![CDATA[<p>We are looking for someone who knows how to use NoSQL databases. But what does that mean. Does it just mean that SQL isn&#39;t necessary? What it means is that the storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases.</p><p>How do non-tabular relations help us? In the end, it comes done to efficiency. With tabular relations, every single entry has to have the same data. You have to add a new column every time you want to add information for just one entry. When this one column is added it increases the amount of space needed equal to the number of entries. This is extremely inefficient and causes a lot of unused space. Instead of forcing every entry to have the same parameter, they are allowed to be fluid. Only adding the information that is necessary.</p><p>For MongoDB, this is thought of as a document structure. Every document is one instance of an object that stores the information for that object. Take 2 online shoppers. One is just buying a product once and the other is a frequent shopper at this store. The person who is buying once might not need the shop to store all of their information so they don&#39;t give it. While the other shops so frequently that they want an easy experience every time. These two people will have very different information save by the store. As the owner, you don&#39;t want to force the one-time shopper to give them all the information that isn&#39;t useful.</p><p>To get started with MongoDB is actually quite easy. First you need to add the gem to the ruby application that you are working on.</p><pre>gem &#39;mongoid&#39;, &#39;~&gt; 7.0.5&#39;</pre><p>After you have installed it configuring the application comes next.</p><pre>bin/rails g mongoid:config</pre><p>At this point, you need to get webpacker installed onto your computer.</p><pre>rails webpacker:install</pre><p>Now you are ready to use MongoDB.</p><p>Working with it is actually quite similar to using any other database. Rails scaffolding still functions. There will be some differences with how the models look though:</p><pre><strong>class</strong> <strong>Comment</strong><br>    include Mongoid::Document<br><br>    field :name, type: String<br>    field :message, type: String<br><br>    belongs_to :post<br><strong>end</strong></pre><p>Now that you understand the basics go out and try. Its not as hard to use as you would think it would be.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7efaf05b6c3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Leap To GPT-3]]></title>
            <link>https://aidanmc95.medium.com/the-leap-to-gpt-3-551f8a322d08?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/551f8a322d08</guid>
            <category><![CDATA[gpt-3]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 13 Dec 2020 05:06:55 GMT</pubDate>
            <atom:updated>2020-12-13T05:06:55.835Z</atom:updated>
            <content:encoded><![CDATA[<p>Generative Pre-Trained Transformer 3 (GPT-3) is the third in a series of AI language models released by the OpenAI lab in San Fransisco. GPT-3 was made available earlier this year and represents a big step forward in AI natural language processing. Compared to its predecessor, GPT-2, GPT-3 is a much more sophisticated and convincing imitation of not only human language, but other human skills as well.</p><p>The main thing that sets GPT-3 apart from its previous generation is the sheer amount of computing power available to it. The full version of GPT-3 has 125 billion machine learning parameters, compared to the only 1.5 billion in GPT-2. Before the advent of GPT-3, some theorized that merely scaling up a language model in this way would have diminishing returns in terms of performance. However, GPT-3 has shown that, at least for now, this isn’t the case. It begs the question, how much bigger can we go before the impact starts to be reduced?</p><p>GPT-3 can do a number of things better than its earlier counterparts. For one thing, humans can only accurately identify short articles written by GPT-3 about 52% of the time, when comparing them with human-written articles. Additionally, GPT-3 is much better at simple arithmetic than other language models, regularly able to answer simple sums and differences. This is important because it implies a degree of general knowledge, i.e. the AI performing broad tasks beyond the language processing it was trained for. It also has done things like making jokes, providing translations, generating plots, and writing its own code.</p><p>Here are a few interesting things people have done with the GPT-3 API:</p><ul><li><a href="https://www.gwern.net/GPT-3">gwern.net</a> has a collection of creative fiction in many styles, all generated by GPT-3</li><li><a href="https://play.aidungeon.io/main/landing">AI Dungeon</a> uses GPT-3 to create interactive RPG-style stories along with the user</li><li><a href="http://giftgenius.ai/">GiftGenius</a> is a gift recommendation engine powered by GPT-3</li></ul><p>GPT-3 is very powerful, but don’t worry, we haven’t reached the singularity just yet. It still struggles with certain tasks, like maintaining a narrative thread over a longer work or identifying and appropriately answering nonsensical questions. Regardless, GPT-3 gives us a glimpse at what the future of AI might be and how we could use it to reach goals that seemed impossible before.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=551f8a322d08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activate Fountain]]></title>
            <link>https://aidanmc95.medium.com/activate-fountain-3d7b47d9db7b?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d7b47d9db7b</guid>
            <category><![CDATA[greedy-algorithms]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 06 Dec 2020 06:50:31 GMT</pubDate>
            <atom:updated>2020-12-06T06:50:31.235Z</atom:updated>
            <content:encoded><![CDATA[<p>This is just one problem but it was one that I got from an interview and would love to talk about where I went wrong and how to solve it. Question:</p><pre>There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n).</pre><pre>There are n + 1 taps located at points [0, 1, ..., n] in the garden.</pre><pre>Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open.</pre><pre>Return <em>the minimum number of taps</em> that should be open to water the whole garden, If the garden cannot be watered return <strong>-1</strong>.</pre><p>This is a greedy algorithm problem that can be solved in log(n) time. I definitely did not go about the problem in this way.</p><p>The first thing I tried to do was reduce the number of taps that I am working with. The easiest way to do this is by checking if any of the taps are completely encompassed by another tap.</p><pre>for i in range(len(ranges)):<br>    for j in range(max(0, i - ranges[i]), min(len(ranges)-1, i - ranges[i])):<br>        if(i != j and ranges[j] != -1 and max(0, i - ranges[i]) &lt;= max(0, j- ranges[j]) and min(len(ranges)-1, i - ranges[i]) &gt;= min(len(ranges)-1, i - ranges[j]):<br>            ranges[j] = -1</pre><pre>count = 0<br>for i in range(len(ranges)):<br>    if(ranges[i] &gt; -1):<br>        count += 1</pre><pre>return count</pre><p>Now yes we can get a solution in some cases that does not mean in all cases. Sometimes you will want to turn on 2 different taps that can encompass the single tap because these 2 other taps may be able to cover other taps that are outside of the range.</p><p>Okay well, why not just make a check that sees if 2 other taps can encompass the single tap after you have eliminated all of the encompassed taps.</p><pre>for i in range(len(ranges)):<br>    for j in range(max(0, i - ranges[i]), min(len(ranges)-1, i - ranges[i])):<br>        if(i != j and ranges[j] != -1 and max(0, i - ranges[i]) &lt;= max(0, j- ranges[j]) and min(len(ranges)-1, i - ranges[i]) &gt;= min(len(ranges)-1, i - ranges[j])):<br>            ranges[j] = -1</pre><pre>left = false<br>right = false</pre><pre>for i in range(len(ranges)):<br>    for j in range(max(0, i - ranges[i]), min(len(ranges)-1, i - ranges[i])):<br>        if(i != j and ranges[j] != -1 and max(0, i - ranges[i]) &lt;= max(0, j- ranges[j])):<br>            left = true<br>        if(i != j and ranges[j] != -1 and min(len(ranges)-1, i - ranges[i]) &gt;= min(len(ranges)-1, i - ranges[j])):<br>            right = true<br>    if(left and right):<br>        range[i] = -1</pre><pre>count = 0<br>for i in range(len(ranges)):<br>    if(ranges[i] &gt; -1):<br>        count += 1</pre><pre>return count</pre><p>I can see why I did this if 2 different taps cover the area of another tap and these taps are not completely encompassed by another then great. The problem starts with what if most of the taps can be covered by others. Which set do you start with then. You might not cover the entire garden if you turn off the wrong pairing of taps.</p><p>Well there is a way but you have to think about the problem in a completely different way. Think about how far one tap can go and then find the next farthest tap after that one.</p><pre>def minTaps(self, n: int, ranges: List[int]) -&gt; int:</pre><pre>    new_list = a = [0] * (n + 1)</pre><pre>    for i in range(n + 1):<br>         left = max(0, i - ranges[i])<br>         right = min(n, i + ranges[i])</pre><pre>         new_list[left] = max(new_list[left], right - left)</pre><pre>    start = end = count = 0</pre><pre>    while(end &lt; n):<br>        count += 1<br>        start, end = end, max(i + new_list[i] for i in range(start, end + 1))</pre><pre>        if(start == end):<br>            return -1</pre><pre>return count</pre><p>This works because you create a new array that has the distance from the left that that spot can move. Then after that, you are starting at the front and move as far as you can. Then the range that you have increased on the next run and you can then get farther.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d7b47d9db7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FTP Servers]]></title>
            <link>https://aidanmc95.medium.com/ftp-servers-854420427e46?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/854420427e46</guid>
            <category><![CDATA[ftp-server]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 07:14:13 GMT</pubDate>
            <atom:updated>2020-11-29T07:14:13.346Z</atom:updated>
            <content:encoded><![CDATA[<p>There are three different types of FTP server connections. The different types are:</p><ul><li>FTP</li><li>FTPS</li><li>FTPES</li></ul><p><strong>FTP: </strong>This is a plain unencrypted connection that by default connects over port 21. Most browsers support this type of connection.</p><p><strong>FTPS: </strong>This type of connection works just like HTTPS. The connection is secured with SSL as soon as it set. The default port is 990. This was the first version of an encrypted FTP available, and while considered depreciated it is still widely used. No major web browser supports this type of connection.</p><p><strong>FTPES: </strong>This type of connection starts out as a plain FTP connection over port 21, but through special commands is upgraded to SSL encryption. These commands usually occur before the user credentials are sent over. None of the major web browsers support this type of connection.</p><p>While there are multiple ways to set up an FTP server interacting with them all works roughly the same.</p><pre>ftps = MyFTP_TLS(server, timeout=5)<br>ftps.login(user=user, passwd=password)<br>ftps.prot_p()<br>files = []<br>ftps.retrlines(&#39;LIST&#39;, files.append)<br>pprint(files)</pre><pre>def downloadFiles(path, destination):<br>    try:<br>        ftps.cwd(path)<br>        os.chdir(destination)<br>        os.makedirs(destination[0:len(destination)-1] + path)<br>    except OSError:<br>        pass<br>    except ftplib.error_perm:<br>        print (&quot;Error: could not change to &quot; + path)<br>        sys.exit(&quot;Ending Application&quot;)</pre><pre>    filelist=ftps.nlst()</pre><pre>    for file in filelist:<br>        time.sleep(interval)<br>        try:<br>            with open(path + &quot;/&quot; + file, &#39;w+b&#39;) as f:<br>            res = ftps.retrbinary(&#39;RETR %s&#39; % file, f.write)<br>        except ftplib.error_perm:<br>            os.chdir(destination[0:len(destination)-1] + path)<br>            try:<br>                ftp.retrbinary(&quot;RETR &quot; + file, open(os.path.join(destination + path, file),&quot;wb&quot;).write)<br>                print (&quot;Downloaded: &quot; + file)<br>            except:<br>                print (&quot;Error: File could not be downloaded &quot; + file)<br>    return</pre><p>This function will allow you to log into an FTPES server and download the files from the desired folder. To work with FTPES and FTPS the process is the same you just need to use a different library from Python. For FTP all you need to change is the library and not log in.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=854420427e46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting Again]]></title>
            <link>https://aidanmc95.medium.com/starting-again-45b7f663b14d?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b7f663b14d</guid>
            <category><![CDATA[latex]]></category>
            <category><![CDATA[resume]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 22 Nov 2020 06:01:11 GMT</pubDate>
            <atom:updated>2020-11-22T06:01:11.351Z</atom:updated>
            <content:encoded><![CDATA[<p>The process of picking up and starting again is challenging for everyone. No one enjoys the process of trying to break into a new field. The effort of reaching out and asking people to spare some of their time so that you can try and wow them is something neither side enjoys. And that&#39;s if they even give you the time of day to talk with them.</p><p>There are tons of time and tricks on how to land your first job with little experience, but most of it isn&#39;t helpful if they don&#39;t even let you start. A great place to start is always with your resume. There are tons of templates and Word is great, but it can really only get you so far. It&#39;s limited in what you can do and hard to customize. If you want to up your game with ease Latex where you will want to go.</p><p>Latex is a simple to learn programming language with one purpose, to write documents. I know not everyone wants to learn a whole programming language just to write one flimsy resume, but don&#39;t let that stop you. There are tons of ready to use templates that you can choose from.</p><p>I know what you are thinking, ‘If you are just going to use a template anyway why not just use Word?’ This is simply because you can customize it with ease. Just copy and paste one section of the template that you want from one area into a different spot. This simple trick will allow you so much freedom when creating your resume.</p><p>Just to show you what a difference Latex can make here is a side by side comparison for almost the same resume:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnFR_sq0zWOLLV_yVlqUWA.png" /></figure><p>The image on the left is the original word doc and the image on the right is in Latex. Almost everything about the right one comes directly from a template. While the left one isn&#39;t terrible it isn&#39;t great either. It&#39;s forgettable. While the one on the right looks professional, clean, and feels like something you would want to pick up and read.</p><p>I am not suggesting learn all of the intricacies of Latex but just that next time you need to apply for a job try Latex.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b7f663b14d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backtracking]]></title>
            <link>https://aidanmc95.medium.com/backtracking-52a9d16f39df?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/52a9d16f39df</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[backtracking]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 15 Nov 2020 06:26:07 GMT</pubDate>
            <atom:updated>2020-11-15T06:26:07.244Z</atom:updated>
            <content:encoded><![CDATA[<p>Backtracing is an algorithmic-technique for solving problems incrementally by building the solution incrementally. The system is implemented by removing solutions that don&#39;t satisfy the constraints at any point. This means that rather than checking everything you can check everything up to a point and move one if it doesn&#39;t work or stops if everything is satisfied.</p><p>There are two main parts of this algorithmic-technique checking if a value is valid to be put into the solution and running the solver to add each input one value at a time and being able to reverse course if needed.</p><p>Their implementations are easiest seen in use so we will talk about how to solve a sudoku board:</p><p>Check Valid Function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-8njStAHA3U1R0AwIwaLg.png" /></figure><p>This function checks the rows, columns, and the section to see if the number can be put into that spot. This is the most important step of using backtracking because it is the underpinning of if the solution will work. You need to know the constraints that you are working with if you want to use backtracking.</p><p>Solve Utility Function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*472GVrQcHZVfpr8-x2oNgw.png" /></figure><p>This is the recursive portion of the code. Once called you to continue to call this function within itself until there are no more inputs to try or solve the sudoku. It is recursive because if you hit a spot that doesn&#39;t work it will reverse the inputs till it finds what it needs.</p><p>What backtracking allows us to do is speed up code. Instead of trying to check everything, it allows us to take diverging paths and just check until we know that the current path will fail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52a9d16f39df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Logging]]></title>
            <link>https://aidanmc95.medium.com/advanced-logging-5d712928da42?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d712928da42</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 08 Nov 2020 07:46:36 GMT</pubDate>
            <atom:updated>2020-11-08T07:46:36.124Z</atom:updated>
            <content:encoded><![CDATA[<p>While it is nice to be able to look at what went wrong easily, the organization of it is important. There are some built-in tools that allowed us to more easily organize where information is placed. These tools are loggers, handlers, formatters, and configuration logging.</p><h4>Loggers</h4><p>Logger objects are used to split up how certain messages are handled. They have three many jobs: exposing methods for the application, determine which messages are handled, and pass messages to their appropriate destination.</p><p>How we interact with a logger object starts with <a href="https://docs.python.org/2/library/logging.html#logging.getLogger"><strong>getLogger()</strong></a><strong> </strong>this allows us to get the object to properly set up the loggers. From here we are able to change how the logger is set up using the methods within:</p><ul><li><a href="https://docs.python.org/2/library/logging.html#logging.Logger.setLevel"><strong>Logger.setLevel()</strong></a> specifies the lowest-severity log message a logger will handle, where debug is the lowest built-in severity level and critical is the highest built-in severity. These follow the same levels as started before.</li><li><a href="https://docs.python.org/2/library/logging.html#logging.Logger.addHandler"><strong>Logger.addHandler()</strong></a> and <a href="https://docs.python.org/2/library/logging.html#logging.Logger.removeHandler"><strong>Logger.removeHandler()</strong></a> add and remove handler objects from the logger object. The handler needs to be added to allow for the message to be sent to the right place. Multiple handlers can be set for a logger.</li></ul><h4>Handlers</h4><p>Handler objects are responsible for actually patching the message through to where they need to go. Multiple handlers can be set on the same logger. This allows for messages to be shifted to different places depending on the severity.</p><p><strong>Handler</strong> objects are responsible for dispatching the appropriate log messages (based on the log messages’ severity) to the handler’s specified destination. <a href="https://docs.python.org/2/library/logging.html#logging.Logger"><strong>Logger</strong></a> objects can add zero or more handler objects to themselves with an <a href="https://docs.python.org/2/library/logging.html#logging.Logger.addHandler"><strong>addHandler()</strong></a> method. As an example scenario, an application may want to send all log messages to a log file, all log messages of error or higher to stdout, and all messages of critical to an email address. This scenario requires three individual handlers where each handler is responsible for sending messages of a specific severity to a specific location.</p><ul><li>The <a href="https://docs.python.org/2/library/logging.html#logging.Handler.setLevel"><strong>setLevel()</strong></a> method, just as in logger objects, it is a bit redundant but this allows us to change where the message is going dependent on the severity.</li><li><a href="https://docs.python.org/2/library/logging.html#logging.Handler.setFormatter"><strong>setFormatter()</strong></a> selects a Formatter object for this handler to use.</li></ul><h4>Formatter</h4><p>The formatter object is used to configure the structure and contents of the log message. The way that we can do this is by using the logging.Formatter.<strong>__init__</strong>(<em>fmt=None</em>, <em>datefmt=None</em>) function. For strings you can formater the messages with:</p><pre>&#39;<em>%(asctime)s</em> - <em>%(levelname)s</em> - <em>%(message)s</em>&#39;</pre><p>While for dates you can use:</p><pre>%Y-%m-%d %H:%M:%S</pre><h4>Configuring Logging</h4><p>While the configuring logs don’t store a lot of data this data can be extremely helpful. The log lets you know how all logger objects are set up. This allows us to easily look up and fix any incorrect logger that has been set up. It also allows us to know which logger to use at different points.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d712928da42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging]]></title>
            <link>https://aidanmc95.medium.com/logging-eac439cd6d03?source=rss-495bab6e66fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/eac439cd6d03</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aidanmc]]></dc:creator>
            <pubDate>Sun, 01 Nov 2020 05:36:16 GMT</pubDate>
            <atom:updated>2020-11-01T05:36:16.174Z</atom:updated>
            <content:encoded><![CDATA[<p>Logging what is the point. It doesn&#39;t move the codebase forward and doesn&#39;t make introduce new functionality to your users. So really why would I need it?</p><p>While yes it does not do any of these things it can help speed up the development process, help new contributors acclimate to the code more easily and help you get back to a project that you haven&#39;t worked on for some time. Let&#39;s say you ran into a bug and wanted to figure out why the problem occurred. Without a good log, you will have to try and figure out how the problem occurred and recreate it. This could take hours of hunting just to figure out that one line of code was missing a ‘:’ or your code only accepted integers but you were passing a string. These are just simple instances of when a nice log could come in handy and let you know where and some extra information as to why it may have failed.</p><p>In this, we will just talk about the simples version of logging in Python. This would be the use of the logging module that is built into Python. This is a simple but highly complex system that can allow you to start on your logging journey.</p><p>In this library there are 5 different levels of logging messages that you can set. Bellow the level and when to use it will be described:</p><p>DEBUG</p><p>Detailed information, typically of interest only when diagnosing problems.</p><p>INFO</p><p>Confirmation that things are working as expected.</p><p>WARNING</p><p>An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.</p><p>ERROR</p><p>Due to a more serious problem, the software has not been able to perform some function.</p><p>CRITICAL</p><p>A serious error, indicating that the program itself may be unable to continue running.</p><p>Here is a simple example of how to implement your first logger:</p><pre><strong>import</strong> <strong>logging</strong><br>logging.warning(&#39;Watch out!&#39;)  <em># will print a message to the console</em><br>logging.info(&#39;I told you so&#39;)  <em># will not print anything</em></pre><p>The default logger will only output logging for anything ‘Warning’ and above. If you would like to set logging for lower-level things you will need to change the configuration of the logger. This and more can be done by using:</p><pre><strong>import</strong> <strong>logging</strong><br>logging.basicConfig(filename=&#39;example.log&#39;,level=logging.DEBUG)<br>logging.debug(&#39;This message should go to the log file&#39;)<br>logging.info(&#39;So should this&#39;)<br>logging.warning(&#39;And this, too&#39;)</pre><p>This statement will allow logging for anything all types of messages because we set the level to DEBUG which is the lowest level. Not only did we change the level but also changed the logger to write to a file instead of the command line. This is helpful because it allows a user to more easily access and search the logs at any time. This is just a brief overview of logs there are much more advanced topics that we will delve into next time. If you would like to read more then please head to, <a href="https://docs.python.org/2/howto/logging.html">https://docs.python.org/2/howto/logging.html</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eac439cd6d03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>