<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Code on jpterry.com</title><link>/categories/code/</link><description>Recent content in Code on jpterry.com</description><generator>Hugo</generator><language>en</language><copyright>© John Terry</copyright><lastBuildDate>Tue, 15 Dec 2015 00:00:00 +0000</lastBuildDate><atom:link href="/categories/code/index.xml" rel="self" type="application/rss+xml"/><item><title>My favorite git alias</title><link>/2015/12/15/git-log-graph-authors/</link><pubDate>Tue, 15 Dec 2015 00:00:00 +0000</pubDate><guid>/2015/12/15/git-log-graph-authors/</guid><description>&lt;p&gt;When I use git I constantly need to understand the shape of the history graph.
And the best way to understand graphs is to visualize them.
Maybe you already know about &lt;code&gt;git log --graph --oneline --decorate&lt;/code&gt;,
but that is a lot to type.&lt;/p&gt;
&lt;p&gt;Add this alias to your .bash_profile, or .zshrc.
I call it &lt;code&gt;glga&lt;/code&gt; for &amp;ldquo;git-log-graph-author&amp;rdquo;, you can call it what you want.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;alias &lt;span style="color:#79c0ff"&gt;glga&lt;/span&gt;&lt;span style="color:#ff7b72;font-weight:bold"&gt;=&lt;/span&gt;&lt;span style="color:#a5d6ff"&gt;&amp;#34;git log --graph --abbrev-commit --date=short --pretty=format:\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a5d6ff"&gt; &amp;#39;%C(yellow)%h%Creset %C(bold blue)(%an)%Creset%C(yellow)%d%Creset %s %Cgreen&amp;lt;%cr, %ar&amp;gt;%Creset&amp;#39;&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Below is a sample screenshot of the output.
At a glance you can see how the commits are related in the graph,
their shas, their authors, messages, and commit/author dates relative to now.&lt;/p&gt;</description></item><item><title>iptables rule to limit tcp connections per ip address</title><link>/2014/02/07/iptables-rule-to-limit-tcp-connections-per-ip-address/</link><pubDate>Fri, 07 Feb 2014 15:24:46 +0000</pubDate><guid>/2014/02/07/iptables-rule-to-limit-tcp-connections-per-ip-address/</guid><description>&lt;p&gt;A vps hosting a service I maintain came under a DOS attack today. The malicious client was
opening as many tcp connections as they could. And
eventually the service would hit the ulimit of open file descriptors and
fail. Of course the service should be more resilient, but this iptables
rule solved the problem right away.&lt;/p&gt;
&lt;p&gt;It will block an individual IPv4 address from opening any more than 25
connections to the service port. It does so by sending a TCP reset when
the the client exceeds 25 connections.&lt;/p&gt;</description></item><item><title>NeoPhonic</title><link>/2012/12/20/neophonic/</link><pubDate>Thu, 20 Dec 2012 00:00:00 +0000</pubDate><guid>/2012/12/20/neophonic/</guid><description>&lt;p&gt;Today I am releasing NeoPhonic to the world. It&amp;rsquo;s a half finished
iOS drum machine app. It uses OpenAL for sound playing.&lt;/p&gt;
&lt;p&gt;You can find the github repo &lt;a href="https://github.com/jpterry/NeoPhonic"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2014-02-07:&lt;/strong&gt; I never got around to publishing this post. I intended to
spice it up a little more but that was more than a year ago, so I&amp;rsquo;m
releasing it as is.&lt;/p&gt;</description></item><item><title>passing objects to methods as blocks in ruby</title><link>/2012/03/07/passing-objects-to-methods-as-blocks-in-ruby/</link><pubDate>Wed, 07 Mar 2012 00:00:00 +0000</pubDate><guid>/2012/03/07/passing-objects-to-methods-as-blocks-in-ruby/</guid><description>&lt;p&gt;Lambda&amp;rsquo;s can come in handy when you need to apply a similar mutation to a collection of objects.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an example of a simple operation but the block can be as complicated or generic as you need.
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ints_to_floats &lt;span style="color:#ff7b72;font-weight:bold"&gt;=&lt;/span&gt; lambda { &lt;span style="color:#ff7b72;font-weight:bold"&gt;|&lt;/span&gt;i&lt;span style="color:#ff7b72;font-weight:bold"&gt;|&lt;/span&gt; i&lt;span style="color:#ff7b72;font-weight:bold"&gt;.&lt;/span&gt;to_f }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(&lt;span style="color:#a5d6ff"&gt;0&lt;/span&gt;&lt;span style="color:#ff7b72;font-weight:bold"&gt;..&lt;/span&gt;&lt;span style="color:#a5d6ff"&gt;5&lt;/span&gt;)&lt;span style="color:#ff7b72;font-weight:bold"&gt;.&lt;/span&gt;map(&lt;span style="color:#ff7b72;font-weight:bold"&gt;&amp;amp;&lt;/span&gt;ints_to_floats)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8b949e;font-style:italic"&gt;#=&amp;gt; [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
The urnary ampersand calls the :symbol&amp;rsquo;s #to_proc method and passes it as a block to the method.&lt;/p&gt;
&lt;p&gt;In ruby 1.9.2 and monkey patched in by rails, Symbol#to_proc is defined as:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"&gt;&lt;code class="language-ruby" data-lang="ruby"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#79c0ff;font-weight:bold"&gt;Proc&lt;/span&gt;&lt;span style="color:#ff7b72;font-weight:bold"&gt;.&lt;/span&gt;new { &lt;span style="color:#ff7b72;font-weight:bold"&gt;|*&lt;/span&gt;args&lt;span style="color:#ff7b72;font-weight:bold"&gt;|&lt;/span&gt; args&lt;span style="color:#ff7b72;font-weight:bold"&gt;.&lt;/span&gt;shift&lt;span style="color:#ff7b72;font-weight:bold"&gt;.&lt;/span&gt;__send__(self, &lt;span style="color:#ff7b72;font-weight:bold"&gt;*&lt;/span&gt;args) }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</description></item></channel></rss>