<?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 Mikekaufman on Medium]]></title>
        <description><![CDATA[Stories by Mikekaufman on Medium]]></description>
        <link>https://medium.com/@mikekaufman4?source=rss-dcdfd24cdd39------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eUh4YjBHVwSURGHMyyLG8A.gif</url>
            <title>Stories by Mikekaufman on Medium</title>
            <link>https://medium.com/@mikekaufman4?source=rss-dcdfd24cdd39------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:09:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikekaufman4/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[How to Git like an Expert]]></title>
            <link>https://medium.com/@mikekaufman4/how-the-pros-git-it-done-bf954c94838a?source=rss-dcdfd24cdd39------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf954c94838a</guid>
            <dc:creator><![CDATA[Mikekaufman]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 04:40:13 GMT</pubDate>
            <atom:updated>2023-04-09T18:49:08.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Futuristic woman writing code?" src="https://cdn-images-1.medium.com/max/512/1*W0eMoTlwOnj574H5hO_bAw.jpeg" /><figcaption>How you’ll feel after learning these git commands</figcaption></figure><p>Here are a few tricks I picked up while working at Amazon Kindle that I use on the daily.</p><p>We’re talking about big things like:</p><ol><li>Saving your progress into multiple commits while you work (for safety), but only pushing one commit (for clean git history).</li><li>Drop what you’re doing and do something else.</li><li>Look at a previous commit and going back.</li><li>Restore your changes back to original state.</li></ol><h3>Work in one commit</h3><p><strong>Save your progress at checkpoints, then SQUASH them!</strong></p><p>When we first learn git, we tend to over commit. 😜 We make a change, run git add foo.file, and git commit -m &quot;some message&quot; then repeat this every time we hit some point in the code where we want to save a spot. What you end up with a messy git history of commits that could be one.</p><p>For this case, this is the time to use squash. Squash your last N commits from your current one. Use git log to confirm things are working as they should.</p><pre>$ git log --graph --all<br>* commit 4f9b3ac9 (HEAD -&gt; master)<br>| Author: mike &lt;email@gmail.com&gt;<br>| Date:   Thu Apr 6 19:56:43 2023 -0700<br>|<br>|     Changed how isNewAnnotation set. Moved from NotebookController to dataModel<br>|<br>* commit 2e5397cd6e7fca1b8b14fad17f020dec1fd5e48d<br>  Author: mike kaufman &lt;mikekaufman4@gmail.com&gt;<br>  Date:   Thu Apr 6 19:55:55 2023 -0700<br><br>      Added Save button and save logic</pre><p>Now we have just the one</p><pre>$ git rebase -i --root<br><br># will bring up this text view. Change the pick to squash on all you want to squish<br>&gt; pick 485jgut Changed how isNewAnnotation set. Moved from NotebookController to dataModel<br>&gt; pick fhf84jg Added Save button and save logic<br><br># change to:<br>&gt; pick 485jgut Changed how isNewAnnotation set. Moved from NotebookController to dataModel<br>&gt; squash fhf84jg Added Save button and save logic</pre><p>Looking good!</p><pre>$ git log  --graph --all<br>* commit 1fd5e48d (HEAD -&gt; master)<br>  Author: mike &lt;email@gmail.com&gt;<br>  Date:   Thu Apr 6 19:55:55 2023 -0700<br><br>      Added Save button and save logic, works with themes. Moved isNewAnnotation logic to dataModel.</pre><p><strong>If no check point needed, just amend the last commit</strong></p><p>In another case: we have a commit and have an uncommitted change, but the change isn’t that big of a deal and could add it to the last commit. In that case don’t make another commit! Instead, add to the previous one.</p><pre>git add foo.file<br>git commit --amend --no-edit</pre><p>Basically this adds your new change to the last commit.</p><h3>Drop whatever you’re doing and do something else</h3><p>Say you’re in the middle of something, maybe you have uncommitted changes or/ and previous commits, and now you need to drop all of that to work on something else. git stash is your friend here. Use git status to confirm things are working as they should.</p><pre>git stash<br>git status</pre><p>Need to get back to before?</p><pre>git stash pop<br>git status</pre><h3>Going to previous commit and back</h3><p>Did you notice some bug and want to see if it exists on the last commit, before you made any changes? Use the stash and pop method from above, and checkout the previous commit.</p><pre>git stash # stashed your changes<br>git checkout HEAD^N # N is number of commits back<br>git checkout HEAD # go back to before<br>git stash pop # now edits back from where we started</pre><h3>Revert a change</h3><p>Sometimes we want a file to go back to how it started. Restore is your friend!</p><pre>git restore foo.file # single file<br>git restore . # everything</pre><p>I know Senior Software Engineer’s that don’t know some of these tricks! I hope you enjoyed at least one. Let me know in the comments! Best of luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf954c94838a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Programming Made Easy: A Step-by-Step Guide to Solving Problems Intuitively]]></title>
            <link>https://medium.com/@mikekaufman4/guide-to-identify-and-solve-dynamic-programming-problems-in-an-interview-a3ee3a010d8e?source=rss-dcdfd24cdd39------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3ee3a010d8e</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Mikekaufman]]></dc:creator>
            <pubDate>Sun, 03 Apr 2022 01:44:10 GMT</pubDate>
            <atom:updated>2022-12-08T11:07:48.691Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In a nutshell:</em></p><ul><li><strong>Check: </strong>If future “decisions” depend on earlier decisions and we are trying to get the optimal solution start by drawing out a recursive decision tree and proceed with trying to solve using DP.</li><li><strong>Solve Recursively: </strong>Figure out what describes each state, define a recurrence relation, define base cases, and solve recursively. Memoize past solutions using an LRU Cache for efficiency. <br>– <em>If the interviewer does not allow a LRU Cache</em> use state variables (reduce them first) to define size and dimension for an array or nested arrays. (Similar to when a LRU cache remembers which input/output a recursive function had).</li><li><strong>Convert to Iterative: </strong>If interviewer asks to further optimize, change the bounds for an iterative approach and recycle the recurrence relation and state variables, but tweak to work with new bounds. I.e. Top down (Recursive) to Bottom up (Iterative).</li></ul><h3>First, what is DP and when can I use it?</h3><p><strong>Dynamic Programming</strong> (DP) is a programming paradigm that can systematically explore all possible solutions to a problem. Therefore, it is capable of solving a wide variety of problems that often have the following characteristics:</p><ol><li>The problem has an “optimal substructure” — an optimal solution can be formed from optimal solutions to the overlapping subproblems of the original problem.<em> In practice this is typically maximizing, minimizing median, heuristic, count, etc. of some kind. Minimum coins for change, max profit from buy/sell stock, shortest path, etc.</em></li><li>Problems where future “decisions” depend on earlier decisions. Deciding what to do at one step may affect the ability to do something in a later step.<em> This characteristic means you cannot use a </em><strong><em>greedy </em></strong><em>algorithm — we need to factor in results from previous decisions.</em></li><li>The problem can be broken down into overlapping subproblems — less complex problems of the original problem that can be re-used multiple times. <em>In practice this will translate to a data structure; where you would draw out a recursive call tree, or iteratively use a string, list, nested lists, etc.</em></li></ol><p><strong>Careful!</strong> These characteristics should be used as a guideline— while common, DP is a very broad topic.</p><h3>How do I start?</h3><p>To help explain this topic we will walk through the problem, “746. Min Cost Climbing Stairs”. <a href="https://leetcode.com/problems/min-cost-climbing-stairs/">https://leetcode.com/problems/min-cost-climbing-stairs/</a></p><figure><img alt="This is a screenshot of Leetcode problem 746. Min Cost Climbing Stairs" src="https://cdn-images-1.medium.com/max/903/1*6ZU2FtvjI2nyUePoo0FfrA.png" /></figure><h4><strong>1. We need to think of the problem in terms of previous subproblems then translate this into a data structure. The easiest way to do this is through recursion<em> (it is closest to how we think usually)</em></strong></h4><p>First we draw out a recursion tree.</p><p>From the input [10,15,20]</p><p>Note: Some problems require changing the input into another form more convenient to work with, or into a secondary source in conjunction with the input before we proceed to drawing out a tree.</p><h4>How to draw the tree</h4><ul><li>We check the first two stairs 10 and 15.</li><li>For the first stair: we go either one step or two steps</li><li>For the second stair: we go either one step or two steps</li><li>If we can go two or less steps to reach n (0 indexed) steps then we are done.</li></ul><figure><img alt="Recursion tree for dynamic programming problem: 746. Min Cost Climbing Stairs" src="https://cdn-images-1.medium.com/max/800/1*bKoEIdxEK_15-GMyPfKXrA.jpeg" /><figcaption>Recursion tree for dynamic programming problem: 746. Min Cost Climbing Stairs</figcaption></figure><h4>2.A. Define our state variables</h4><p>The first step is to see what variables should represent each state, these are called <strong><em>state variables</em></strong>. These are things which would differentiate one state from another.</p><ul><li>i, being the step we are at</li></ul><p>Make sure you reduce state variables to absolutely necessary. Otherwise time/space efficiency will not be optimal and you will recalculate subtrees. In this case i is the only variable we need so it is reduced enough.</p><h4>2.B. What is our intended result?</h4><ul><li>total weight of path taken</li></ul><h4>3. Define our <strong>recurrence relation</strong></h4><ul><li>We can start from the first or second step</li></ul><pre>first_step=cost[i]+dp(i)</pre><pre>second_step=cost[i+1]+dp(i+1)</pre><pre>return min(first_step,second_step)</pre><ul><li>We either take one step or two steps.</li></ul><pre> step1=cost[i+1]+dp(i+1)<br> step2=cost[i+2]+dp(i+2)<br> return min(step1,step2)</pre><h4>4. Define base cases</h4><p>When we reach the end we should stop.</p><pre>if i+2&gt;=n:return 0</pre><p><strong>5. Solve recursively</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a51b99858047b2927272986b0681b03c/href">https://medium.com/media/a51b99858047b2927272986b0681b03c/href</a></iframe><p><strong>Ask your interviewer if you’re allowed to use functools</strong> for automatic memoization of your function calls for some given input.</p><p>This is what makes the runtime go from O(2**n) to O(n), etc. Instead of solving for f(1), f(2),f(3),… multiple times it will solve it once and keep it in memory for when it will be used again.</p><p><strong>If you cannot use functools</strong>: use your state variables to determine what would describe a state. We see we have one dimension i of length n so we make a list called mem to keep track of previous states.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15f1eafe39b09585e93fafbe17703642/href">https://medium.com/media/15f1eafe39b09585e93fafbe17703642/href</a></iframe><p>✨We’ve solved the problem!✨</p><h4>Although we’ve solved the problem an interviewer might want an iterative approach because it’s typically much more efficient, or they simply just feel like asking.</h4><h3>To convert recursion into iteration:</h3><p>U<strong>sually </strong>top-down algorithms are easier to implement than a bottom-up approach. However bottom up is typically more efficient, therefore it is important to know how to convert it.</p><p><strong>Steps to convert top-down into bottom-up</strong></p><ol><li>Start with a recursive implementation that is working.</li><li>Initialize an array with size and dimensions according to your state variables. The values should be initialized as some default value opposite of what the problem is asking for. I.e. if the problem is asking for the maximum of something, set the values to negative infinity.</li><li>Set your base cases, same as the ones you are using in your top-down function.</li><li>Write a for-loop(s) that iterate over your state variables. If you have multiple state variables, you will need nested for-loops. <strong>These loops should</strong> <strong>start iterating from the base cases</strong>.</li><li>Now, each iteration of the inner-most loop represents a given state, and is equivalent to a function call to the same state in top-down. Copy the logic from your function into the for-loop and change the function calls to accessing your array.</li><li>Change your recurence relation according to the bounds you’ll iterate over.</li><li>We’re done!</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4493be639991b72804fbb3ad12e4f884/href">https://medium.com/media/4493be639991b72804fbb3ad12e4f884/href</a></iframe><p>I.e. your current step is the minimum of stepping on that step from 1 step ago, or two steps ago.</p><p>This can be more confusing to conceptualize which is why we start recursively.</p><h3>One more example — State Transition by Inaction</h3><p>This will illustrate the technique of doing nothing!</p><p>This pattern occasionally shows up in DP problems. “doing nothing” refers to two different states having the same value. We’re calling it “doing nothing” because often the way we arrive at a new state with the same value as the previous state is by “doing nothing”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*OVO3pnu6Ma8MxONqPFKEBg.png" /></figure><p><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/</a></p><p>Again, we see we want the optimal solution ie the max profit from a decision based off previous decisions. So we start with a recursive decision tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f4fdYCHz2lhUwCPF_kvQwA.jpeg" /></figure><h4>State variables:</h4><ul><li>ith price</li><li>Boolean for owning stock</li><li>k transactions allowed to do</li></ul><p><strong>Recurrence Relation</strong></p><pre>skip=dp(i+1,ownStock,k) # we always calculate a skip</pre><pre>if ownStock: # if we own we calculate a sale too<br>   sell=price[i]+dp(i+1,False,k-1)<br>else: # if we don&#39;t we calculate a purchase instead<br>   buy=-price[i]+dp(i+1,True,k)<br>return max(skip,buy+sell)</pre><h4>Base Case</h4><p>When we reach the end or we have no more transactions left to do stop looking.</p><pre>if i==n or k==0:return 0</pre><h4>Solve Recursively</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a187292a1a9a7f1bda872abe4037cc6b/href">https://medium.com/media/a187292a1a9a7f1bda872abe4037cc6b/href</a></iframe><p>✨We’ve solved the problem!✨</p><p>What have we covered? <em>One dimensional DP problem, and the do something or nothing pattern.</em></p><h4>There are more common cases to go over: <strong><em>(I’ll link these in if I make more articles on this)</em></strong></h4><ul><li>paths</li><li>state variable reduction (make sure you don’t recalculate subtrees)<a href="https://leetcode.com/problems/paint-fence/discuss/1911745/Top-Down-Recursive-Full-Walk-Through-Lesson-on-State-Variable-Reduction-Python"> I have a leetcode post on this here!</a></li><li>counting (I touch on this in the leetcode post for state variable reduction above)</li><li>Kadane’s algorithm</li></ul><p>Reference:leetcode.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3ee3a010d8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a Video Streaming Server with Go — Simplified]]></title>
            <link>https://medium.com/@mikekaufman4/how-to-stream-video-with-go-simplified-eb8244277da5?source=rss-dcdfd24cdd39------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb8244277da5</guid>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[streaming-video]]></category>
            <category><![CDATA[streaming-music]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[Mikekaufman]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 06:25:57 GMT</pubDate>
            <atom:updated>2022-04-09T20:28:46.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5MgU35mQk306ljKcO_Ccxw.gif" /><figcaption>index.html</figcaption></figure><h4>Summary:</h4><p>This article walks through an example of how to set up and stream a video through http.</p><p>In the following example we will encode a video into a format to be distributed over http, serve it from a http server, and view it in two different video players.</p><h3>Installation</h3><p>Download and install <a href="https://ffmpeg.org/download.html">ffmpeg</a> on your computer.</p><h4>Linux</h4><pre>sudo apt update &amp;&amp; sudo apt upgrade &amp;&amp; sudo apt install ffmpeg</pre><h4>Windows/ Mac</h4><p>Download <a href="https://ffmpeg.org/download.html">ffmpeg </a>(Learn more about it <a href="https://www.quora.com/What-is-ffmpeg">here</a>) Decompress the folder to some location on your computer, for example in C:\</p><p><em>For names sake we will rename our folder to ffmpeg, the final outcome is C:\ffmpeg. </em>Now add the environment variable path to C:\ffmpeg\bin and restart your computer.</p><h3>First, how do we stream video?</h3><h4>Compress it</h4><p>Raw uncompressed 1080p video is about <strong>3 GB per second, w</strong>here 1080p in FHD has a bitrate of <strong>5 MB</strong> per second (both at 60 frames per second).</p><h4>Slice it up</h4><p>Cut it into multiple files</p><h4>Create a Playlist file</h4><p>Create a file to keep track of names and times for each file</p><p>You can download demo.flv <a href="https://filesamples.com/samples/video/flv/sample_1280x720_surfing_with_audio.flv">here</a>. Although feel free to try your own video: mp4, etc.</p><h3>Compress and Slice</h3><p>The first file to be sent is a text file (typically UTF-8 i.e. chars of 8 bits) which looks something like this:</p><figure><img alt="playlist.m3u8" src="https://cdn-images-1.medium.com/max/215/1*JetGV2q3-679gGMpNcG1Rg.png" /><figcaption>playlist.m3u8</figcaption></figure><p>ffmpeg does all the slicing and compression for us. Simply run a the following command on your terminal to create a similar result to the photo above.</p><h4>Run ffmpeg in the same directory as your video file:</h4><pre>ffmpeg -i demo.flv -b:v 1M -g 60 -hls_time 2 -hls_list_size 0 -hls_segment_size 500000 output.m3u8</pre><p><strong>Let’s breakdown the command <em>(It does a lot! </em></strong><a href="https://emojipedia.org/face-with-open-mouth/">😮</a> <strong><em>)</em></strong></p><blockquote>We have as <em>-i</em> input the demo.flv file with a video <em>-b:v</em> bitrate of <em>1M</em> and <em>-g </em>set the group of pictures to 60 (default 12), <em>-hls_time</em> of 2 creates a playlist file and makes one or more segment files in time slices of 2.</blockquote><blockquote>Then, set <em>hls_list_size</em> to 0 so the list file will contain all the segments and return only one playlist.m3u8, and finally <em>hls_segment_size</em> of 62.5kB max (Unfortunately <em>hls_segment_size</em> is ignored). <a href="http://underpop.online.fr/f/ffmpeg/help/options-51.htm.gz">Learn more about ffmpeg options here!</a></blockquote><h4>What you should expect to see</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KhG-fQPCsI7v8k5QnNxrUw.gif" /><figcaption>Running the ffmpeg command above to to slice and encode video</figcaption></figure><h4>This will be our project structure</h4><pre>Our Project/<br>├─ videos/<br>│  ├─ video/<br>│  │  ├─ ...<br>│  │  ├─ output37.ts<br>│  │  ├─ playlist.m3u8<br>│  ├─ index.html<br>├─ server.go</pre><h3>Create a server to host your video file</h3><p>This snippet will serve files in the directory videos/on your computer.</p><p>Now, add a folder called <strong><em>videos </em></strong>and under it another folder called <strong>video </strong><em>(like in my photos)</em><strong> </strong>or something cooler like <strong><em>demovideo1 </em></strong>or whatever. Now drag-and-drop all our .mpk files and our .m3u8 file into there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83b69243aa618d23836a960eb601ad25/href">https://medium.com/media/83b69243aa618d23836a960eb601ad25/href</a></iframe><p>Run the server.</p><pre>go run server.go</pre><p><strong>[Skip this step if you don’t want to download VLC Player]</strong></p><h4>Test things are working with VLC Player</h4><p>Visit localhost:8080/video in the browser.</p><p>However, <a href="http://localhost:8080/video/playlist.m3u8">http://localhost:8080/video/playlist.m3u8</a> is what we want specifically. This is what a player uses.</p><figure><img alt="Our server makes files in the videos directory available over http" src="https://cdn-images-1.medium.com/max/309/1*fdR48pxxkHrbYrxOqCD_rw.png" /><figcaption>Our server makes files in the videos directory available over http</figcaption></figure><p>Now download VLC media player and click Open Network Stream.</p><p>Paste the url into the the line and click the button.</p><p>Walla! We see the server’s distributing our video!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*F8wq1KtvCpcoGbaPZ_202A.gif" /></figure><h4>Finally, Make a Simple Web App to Receive Video in the browser</h4><p>Add this one file to your videos/ directory so in the browser when we go to <a href="http://localhost:8080/">http://localhost:8080/</a> we only get one file, index.html</p><p>index.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec05f6d454bd906ed4e749dacdbad9ed/href">https://medium.com/media/ec05f6d454bd906ed4e749dacdbad9ed/href</a></iframe><p>This makes one html video component with the source of our Go server’s playlist.m3u8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5MgU35mQk306ljKcO_Ccxw.gif" /><figcaption>index.html</figcaption></figure><p>Want me to continue this thread? We can add different/automatic qualities, video upload, real time streaming in example 2?</p><p>Please tell me! =)</p><p>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb8244277da5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>