<?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 Brian Kustra on Medium]]></title>
        <description><![CDATA[Stories by Brian Kustra on Medium]]></description>
        <link>https://medium.com/@bkentropy?source=rss-f651564172c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eJrU0Q0yvg7wnj_V.jpg</url>
            <title>Stories by Brian Kustra on Medium</title>
            <link>https://medium.com/@bkentropy?source=rss-f651564172c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:36:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bkentropy/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[Docker Cheat Sheet]]></title>
            <link>https://medium.com/@bkentropy/docker-cheat-sheet-91260ae1c943?source=rss-f651564172c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/91260ae1c943</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Brian Kustra]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 16:57:08 GMT</pubDate>
            <atom:updated>2023-12-07T22:29:21.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WF0OC9phVbU1j3k2McOSA.png" /></figure><p>I am regularly asked questions about Docker, containers, running, and debugging them. I’ve noticed enough of a pattern I thought it was worth writing a article about the most common ones.</p><p>Part 1 is about building an image and part 2 is about running/operating it. So if you are just docker pull -ing the images and running them, feel free to skip to part 2.</p><h3>Part 1, Building an image</h3><p>Let’s start by pulling a base image. Before we go customizing it run:</p><pre>docker pull python:3.11</pre><p>With that, you can test out python like:</p><pre>docker run -ti python:3.11 python</pre><p>For now we will ignore the flags and arguments. But just running that bring up a python REPL and that’s pretty cool already. When you are done hit Ctrl+D or run quit().</p><p>Now let’s create a Dockerfile and use that as the base image. Where ever you want to run this create a Dockerfile with:</p><pre>FROM python:3.11<br><br>CMD [&quot;python&quot;, &quot;-c&quot;, &quot;print(&#39;hello!&#39;)&quot;]</pre><p>FROM is the base image that you are building on top of.</p><p>CMD is the command the container execute upon a docker run .</p><p>Then we will build the new image:</p><pre>docker build . -t cheatsheet</pre><p>The . means: build using this directory and the Dockerfile in it.</p><p>The -t means tag and we are saying to tag the image as cheatsheet .</p><p>Now, go ahead and run it:</p><pre>docker run cheatsheet <br># you should see:                            <br>hello!</pre><p>Exercise: change the text from “hello” to what ever you want. Rebuild the image (same tag is fine, but will overwrite your current). Run it, you should see your new text.</p><p>So now you’ve pulled, built, and run a container. While not rare, containers are generally not run this way. This is a single command that we run through python. Containers are often running servers, or other long running processes. So let’s do that</p><p>Bring up your Dockerfile again. Now, let’s modify CMD to a long running process.</p><pre>FROM python:3.11<br><br>CMD [&quot;python&quot;, &quot;-m&quot;, &quot;http.server&quot;]</pre><p>This should start up a server that will serve up all the file in the directory that the server is run from.</p><h3>Part 2, Running a container (from an image)</h3><p>We’ll start with the most basic way to run this server. We’re going to go from a container that does not work to one that does.</p><p>The most basic way to run a container is to run an image like:</p><pre>docker run -t cheatsheet-python:latest</pre><pre>docker run -p 8000:8000 cheatsheet-python:latest<br>docker run -p 8000:8000 -v ${PWD}:/srv cheatsheet-python:latest<br>docker run -p 8000:8000 -v ${PWD}:/srv -d cheatsheet-python:latest<br>docker run -p 8000:8000 -v ${PWD}:/srv -d --name cs-python cheatsheet-python:latest</pre><h3>Part 3, Working with a running container</h3><p>In this section we’ll go over reading logs from a container in daemon mode, and ‘execing’ into a container to see what’s going on inside the container.</p><p>If you don’t get an error from Docker itself, the next place to look is inside the container. Let’s look at some useful logging commands.</p><p>The most basic: this will print out all (most) of the logs your container has created and exit.</p><pre>docker logs cs-python</pre><p>This will keep the terminal attached to the logs so that you can (-f) follow along:</p><pre>docker logs cs-python -f</pre><p>I find this one really useful for longer running processes, by adding</p><p>--since 5m you can ignore log message older than 5 minutes (and keep following):</p><pre>docker logs cs-python -f --since 5m</pre><p>Another version of seeing less logs is providing a tail value:</p><pre>docker logs cs-python --tail 10</pre><p>That should definitely get you started with your logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91260ae1c943" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A quick dip into recursion]]></title>
            <link>https://medium.com/@bkentropy/a-deeper-dive-into-recursion-4106452a221b?source=rss-f651564172c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4106452a221b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Brian Kustra]]></dc:creator>
            <pubDate>Sat, 12 Dec 2015 22:06:42 GMT</pubDate>
            <atom:updated>2015-12-12T22:22:37.299Z</atom:updated>
            <content:encoded><![CDATA[<p>In this example, you will type this code into something like <a href="http://jsbin.com/?js,console">http://jsbin.com/?js,console</a>. In this case you <strong>must</strong> answer <strong>yes </strong>or<strong> no </strong>to break out of the loop.</p><pre>var askRecursively = function(question) {<br>var reply = prompt(question);<br> <br> if ( reply === ‘yes’ ) {<br>   return true;<br> } else if ( reply === &#39;no&#39; ) {<br>   return false;<br> } else {<br>   alert(‘Incorrent answer! Try Again!’);<br>   askRecursively(question);<br> }<br>};<br> <br>askRecursively(“Am I awesome?”);</pre><p>Now that you have typed this out in the JavaScript interpreter of your choice I am going to break it down. First, we declare the function called <em>askRecursively</em>, and it takes a string that will be the question that the alert pop-up will ask. Next, declare the variable <em>reply</em> and set it equal to the response from the prompt pop-up that is asking the question from the last step. Now, there are two base cases, and for this example the answers ‘yes’ (the correct choice!) and ‘no’ to the question ‘Am I awesome?’ will break the loop. Else an alert will pop-up that says ‘Incorrent answer! Try again!’ and it will recursively (call itself inside the function) ask the original question. Again, once you invoke this function pop-ups will repeatedly appear on screen until the prompt receives the answer ‘yes’ or ‘no’ all other answer will display the pop-up and re-call the function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4106452a221b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion in JavaScript is awesome.]]></title>
            <link>https://medium.com/@bkentropy/recursion-in-javascript-is-awesome-6b19aad5d5ad?source=rss-f651564172c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b19aad5d5ad</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Brian Kustra]]></dc:creator>
            <pubDate>Sat, 05 Dec 2015 22:12:33 GMT</pubDate>
            <atom:updated>2015-12-05T22:12:33.664Z</atom:updated>
            <content:encoded><![CDATA[<p>If you aren’t familiar with for loops check <a href="https://medium.com/@bkentropy/iteration-one-step-at-a-time-15c0b183cc5a#.oi3pdfmj0">this</a> out.</p><p>Recursion, in this example, is basically calling a function within the same function. A non-technical way to think about this might be to think of a pizza. You don’t pick up a whole pizza and start eating, you cut it up into smaller slices. This makes eating each piece more manageable. When we run into a problem in JavaScript that can be broken into smaller pieces but looks a lot like the problem we started with, this is when to use recursion.</p><p>Today I worked on a problem that would almost always be done with a for loop, iteration. Instead, I used recursion. While this is a simplistic example, it highlights just how powerful recursion can when it comes to traversing arrays and what will become more apparent in the future, matrices. Let’s take a deeper look at the example of today’s problem:</p><p>“Write a function using recursion that will print out each of the elements in an array.”</p><p>Most of the time, one would use a for loop for this job. Instead let’s look at the recursive way (again, <a href="http://jsbin.com/?js,console">http://jsbin.com/?js,console</a> is very useful):</p><pre>var printArray = function(array, i) {<br>  i = i | 0;</pre><pre>  if ( i === array.length) {<br>    return;<br>  } else {<br>    console.log(array[i]);<br>    printArray(array, i+1);<br>  }</pre><pre>};</pre><pre>var myArray = [&#39;text&#39;,&#39;goes&#39;,&#39;here&#39;];<br>printArray(myArray);</pre><p>Since we are using the recursive technique instead of the iterative technique we must first have a base case. When is this problem done? We don’t want to go on infinitely. Arrays start at zero, so when the variable i reaches 3, the length of myArray, it is time to break out of function. The recursive part of the function is after it prints what ever the i’th value of the array is when it calls itself printArray(array, i+1). This will increase the value of i by 1 so it will then print out the next element, and the next until i is equal to 3 which will then exit out of the function.</p><p>The large part of the problem is to print each element of the array. This is like trying to eat the whole pizza at once in the example above. To break this down I figured it would be best to print one element at a time, like cutting a pizza into smaller pieces. This simple part of the function is repeated until the desired result is accomplished.</p><p>Coming up next! More recursion! More advanced!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b19aad5d5ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>