<?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 Evan Hoffman</title><link>https://evan.wtf/tags/code/</link><description>Recent content in Code on Evan Hoffman</description><generator>Hugo</generator><language>en-US</language><copyright>Evan Hoffman</copyright><lastBuildDate>Fri, 02 Mar 2012 10:01:11 +0000</lastBuildDate><atom:link href="https://evan.wtf/tags/code/index.xml" rel="self" type="application/rss+xml"/><item><title>Reorganizing photos in 1 line with exiftool</title><link>https://evan.wtf/2012/03/02/reorganizing-photos-in-1-line-with-exiftool/</link><pubDate>Fri, 02 Mar 2012 10:01:11 +0000</pubDate><guid>https://evan.wtf/2012/03/02/reorganizing-photos-in-1-line-with-exiftool/</guid><description>&lt;p&gt;A few years ago I wrote &lt;a href="https://evan.wtf/2007/03/28/java-utility-to-reorganize-photos-by-date-taken-via-exif-metadata/"&gt;a utility&lt;/a&gt; in Java to find all JPG files in a directory and move them into a date-based directory structure like /YYYY/MM/DD/ based on the date the photo was taken, extracted from the exif metadata in the file. Well, apparently that was a huge waste of time, as I just discovered that &lt;code&gt;exiftool&lt;/code&gt;, an awesome perl utility I&amp;rsquo;ve used for years to edit/extract the metadata on the command line, can also do this natively. So my entire program can be replaced with this simple command:&lt;/p&gt;</description></item><item><title>Graphing SSH dictionary attacks with HighCharts</title><link>https://evan.wtf/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/</link><pubDate>Fri, 18 Nov 2011 14:06:03 +0000</pubDate><guid>https://evan.wtf/2011/11/18/graphing-ssh-dictionary-attacks-with-highcharts/</guid><description>&lt;p&gt;After my 10-year-old basement Linux server died this week from a power outage, I took the sad step of giving up on it. It&amp;rsquo;s died before and I&amp;rsquo;ve patched it back together with a new power supply here or an addon PCI SATA card there, but I finally decided to throw in the towel since I had a newer old computer that had been idle for several years. The one that died was an Athlon K7 750 MHz with 512 MB ram. The new one is an Athlon 2 GHz (3200+) with 1 gig. For my uses, specs don&amp;rsquo;t really matter that much, but it&amp;rsquo;s nice to have more power for free.&lt;/p&gt;</description></item><item><title>Displaying currently-playing iTunes track in the Mac menu bar</title><link>https://evan.wtf/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/</link><pubDate>Fri, 21 Oct 2011 14:48:42 +0000</pubDate><guid>https://evan.wtf/2011/10/21/displaying-currently-playing-itunes-track-in-the-mac-menu-bar/</guid><description>&lt;p&gt;In an attempt to teach myself Objective C, and because I couldn&amp;rsquo;t find anything that did what I wanted, I wrote a little utility to display the currently-playing iTunes track in the Mac taskbar. Originally I had it display the full track name right in the taskbar but it was too much text for such a small space (especially on a 1440x900 screen), so now you click a little musical note and it shows you the info in a menu.&lt;/p&gt;</description></item><item><title>Benchmarking DNS servers with Java</title><link>https://evan.wtf/2011/09/26/benchmarking-dns-servers-with-java/</link><pubDate>Mon, 26 Sep 2011 12:33:28 +0000</pubDate><guid>https://evan.wtf/2011/09/26/benchmarking-dns-servers-with-java/</guid><description>&lt;p&gt;I&amp;rsquo;m currently in the process of moving our DNS over to another provider and I was curious as to whether the old or new provider offers faster lookups. &lt;code&gt;dig&lt;/code&gt; shows query times, but I didn&amp;rsquo;t want to just run that over and over. I decided to write something to do this, in Java since I like Java. I found &lt;a href="http://mowyourlawn.com/blog/?p=8"&gt;this post,&lt;/a&gt; which has the meat of the work done already. I also read some of Sun&amp;rsquo;s &lt;a href="http://download.oracle.com/javase/1,5.0/docs/guide/jndi/jndi-dns.html"&gt;JNDI/DNS&lt;/a&gt; lookup info, which was pretty dense. All I want to do is specify the name server&amp;rsquo;s IP and do the lookup. I don&amp;rsquo;t even really care about the result, just how long the query takes.&lt;/p&gt;</description></item><item><title>Amazon SES: "illegal headers" with ses-send-email.pl (followup)</title><link>https://evan.wtf/2011/08/02/amazon-ses-illegal-headers-with-ses-send-email-pl-followup/</link><pubDate>Tue, 02 Aug 2011 14:39:45 +0000</pubDate><guid>https://evan.wtf/2011/08/02/amazon-ses-illegal-headers-with-ses-send-email-pl-followup/</guid><description>&lt;p&gt;A few people have emailed me asking me to integrate &lt;a href="https://evan.wtf/2011/05/16/amazon-ses-illegal-header-errors/"&gt;the perl code snippet into I wrote to strip illegal headers&lt;/a&gt; when sending email via Amazon SES into something actually usable. I&amp;rsquo;ve done so! I haven&amp;rsquo;t really tested this beyond sending some test emails, but here it is. Use this at your own risk, I make no warranty, blah blah blah.&#10;This fix requires editing &lt;code&gt;ses-send-email.pl&lt;/code&gt;, so I&amp;rsquo;d advise making a backup copy, though I imagine you can always get a fresh version from Amazon if necessary.&lt;/p&gt;</description></item><item><title>MongoDB logrotate script</title><link>https://evan.wtf/2011/07/21/mongodb-logrotate-script/</link><pubDate>Thu, 21 Jul 2011 10:10:26 +0000</pubDate><guid>https://evan.wtf/2011/07/21/mongodb-logrotate-script/</guid><description>Daily mongodb log rotation via &lt;code&gt;logrotate&lt;/code&gt;.</description></item><item><title>Teaching myself node.js: Part 3</title><link>https://evan.wtf/2011/06/23/teaching-myself-node-js-part-3/</link><pubDate>Thu, 23 Jun 2011 17:39:59 +0000</pubDate><guid>https://evan.wtf/2011/06/23/teaching-myself-node-js-part-3/</guid><description>Notes on MongoDB&amp;rsquo;s ObjectID vs sequential identifiers.</description></item><item><title>JavaScript regex for stripping leading &amp; trailing whitespaces</title><link>https://evan.wtf/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/</link><pubDate>Wed, 22 Jun 2011 00:09:51 +0000</pubDate><guid>https://evan.wtf/2011/06/22/javascript-regex-for-stripping-leading-trailing-whitespaces/</guid><description>&lt;code&gt;str.replace(/^(\s*)((\S+\s*?)&lt;em&gt;)(\s&lt;/em&gt;)$/,&amp;quot;$2&amp;quot;);&lt;/code&gt;</description></item><item><title>Teaching myself node.js: Part 2</title><link>https://evan.wtf/2011/06/18/teaching-myself-node-js-part-2/</link><pubDate>Sat, 18 Jun 2011 00:45:02 +0000</pubDate><guid>https://evan.wtf/2011/06/18/teaching-myself-node-js-part-2/</guid><description>More work learning node.</description></item><item><title>Teaching myself node.js: Part 1</title><link>https://evan.wtf/2011/06/14/teaching-myself-node-js-part-1/</link><pubDate>Tue, 14 Jun 2011 00:50:59 +0000</pubDate><guid>https://evan.wtf/2011/06/14/teaching-myself-node-js-part-1/</guid><description>In which I try to learn node.js by building a Quora-like site (since it seems everyone is building a blog).</description></item><item><title>Calculating SHA-1 sums in Java</title><link>https://evan.wtf/2011/05/25/calculating-sha-1-sums-in-java/</link><pubDate>Wed, 25 May 2011 18:19:27 +0000</pubDate><guid>https://evan.wtf/2011/05/25/calculating-sha-1-sums-in-java/</guid><description>Java code for calculating SHA-1 sums from arbitrary InputStreams, files, or Strings and printing them as strings.</description></item><item><title>Integrating Amazon Simple Email Service with postfix for SMTP smarthost relaying.</title><link>https://evan.wtf/2011/04/28/integrating-amazon-simple-email-service-with-postfix-for-smarthost-relaying/</link><pubDate>Thu, 28 Apr 2011 12:23:47 +0000</pubDate><guid>https://evan.wtf/2011/04/28/integrating-amazon-simple-email-service-with-postfix-for-smarthost-relaying/</guid><description>How I configured an EC2 instance to relay mail through Amazon&amp;rsquo;s SES, and some of the bumps I encountered along the way.</description></item><item><title>Perl script to calculate DNS queries per second in BIND (named)</title><link>https://evan.wtf/2010/12/07/perl-script-to-calculate-dns-queries-per-second-in-bind-named/</link><pubDate>Tue, 07 Dec 2010 18:53:43 +0000</pubDate><guid>https://evan.wtf/2010/12/07/perl-script-to-calculate-dns-queries-per-second-in-bind-named/</guid><description>&lt;p&gt;I&amp;rsquo;m pricing out DNS providers and was asked what our current queries-per-second currently are. Sadly I had no idea. After lots of Googling I decided there was really no good way to get this information so I decided to parse the logfile myself.&#10;First, I turned on logging with timestamp in named.conf:&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;logging&#10;{&#10;...&#10; # Query logging 2010-12-07&#10; channel query-log {&#10; file &amp;#34;data/queries.log&amp;#34; versions 3 size 10m;&#10; print-time yes;&#10; };&#10; category queries { query-log; };&#10;};&#10;options&#10;{&#10;...&#10; # Query logging 2010-12-07&#10; querylog yes;&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;};&lt;/p&gt;</description></item><item><title>ldapsearch example on Active Directory</title><link>https://evan.wtf/2010/08/26/ldapsearch-on-active-directory-2/</link><pubDate>Thu, 26 Aug 2010 10:40:18 +0000</pubDate><guid>https://evan.wtf/2010/08/26/ldapsearch-on-active-directory-2/</guid><description>&lt;p&gt;Just putting this here for safekeeping since I couldn&amp;rsquo;t remember the exact syntax.&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;[evan@ehoffman 10:35:50 ~]$ ldapsearch -x -LLL -D &amp;#34;ldapuser@example.com&amp;#34; -w password -b &amp;#34;OU=Users,DC=example,DC=com&amp;#34; -s sub -H ldaps://activedirectory.example.com &amp;#34;(sn=hoffman)&amp;#34; cn mail displayName samaccountname&#10;dn: CN=Evan Hoffman,OU=Tech,OU=Users,DC=example,DC=com&#10;cn: Evan Hoffman&#10;displayName: Evan D. Hoffman&#10;sAMAccountName: ehoffman&#10;mail: Evan.Hoffman@example.com&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Explanation: Connect to &lt;strong&gt;activedirectory.example.com&lt;/strong&gt; using ldaps (SSL) with simple authentication, binding as &lt;strong&gt;&lt;a href="mailto:ldapuser@example.com"&gt;ldapuser@example.com&lt;/a&gt;&lt;/strong&gt; with password &lt;strong&gt;password&lt;/strong&gt;; search for &lt;strong&gt;(sn=hoffman)&lt;/strong&gt; within the &lt;strong&gt;OU=Users,DC=example,DC=com&lt;/strong&gt; search base (branch), and search the &lt;strong&gt;sub&lt;/strong&gt;tree. Return the &lt;strong&gt;cn&lt;/strong&gt;, &lt;strong&gt;displayName&lt;/strong&gt;, and &lt;strong&gt;samaccountname&lt;/strong&gt; fields.&lt;/p&gt;</description></item><item><title>Java Code: searching a Binary Search Tree for the largest value strictly less than X</title><link>https://evan.wtf/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/</link><pubDate>Sun, 09 May 2010 13:43:17 +0000</pubDate><guid>https://evan.wtf/2010/05/09/java-code-searching-a-binary-search-tree-for-the-largest-value-strictly-less-than-x/</guid><description>Java code for creating and searching a Binary Search Tree of any element implementing the Comparable interface.</description></item><item><title>Code to flatten a list in Java, with and without recursion</title><link>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</link><pubDate>Sat, 17 Apr 2010 23:42:16 +0000</pubDate><guid>https://evan.wtf/2010/04/17/code-to-flatten-a-list-in-java-with-and-without-recursion/</guid><description>&lt;p&gt;Recently had someone ask me to solve this problem: assume you have a list of objects, some of which may be lists of arbitrary depths. Write a function to return the list &amp;ldquo;flattened,&amp;rdquo; so sublists are all in the &amp;ldquo;main&amp;rdquo; list. I solved it recursively pretty easily, but it took some thought to do it without recursion. My solutions are below.&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;package com.evanhoffman.listflattener;&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;import java.util.LinkedList;&#10;import java.util.List;&#10;import java.util.ListIterator;&lt;/p&gt;&#10;&lt;p&gt;import org.apache.log4j.BasicConfigurator;&#10;import org.apache.log4j.Logger;&lt;/p&gt;</description></item><item><title>Java compound interest calculator</title><link>https://evan.wtf/2008/01/10/java-compound-interest-calculator/</link><pubDate>Thu, 10 Jan 2008 00:00:08 +0000</pubDate><guid>https://evan.wtf/2008/01/10/java-compound-interest-calculator/</guid><description>&lt;p&gt;I wrote a thing to calculate compound interest and print out how much you&amp;rsquo;ve accrued after each period. It&amp;rsquo;s pretty basic but I was bored and didn&amp;rsquo;t want to do it via calculator. The code is in &lt;a href="https://evan.wtf/InterestCalculator.java"&gt;InterestCalculator.java&lt;/a&gt;, sample output is below:&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;Initial principal: 5000.00&#10;Interest rate: 0.05 (4.93%)&#10;# of ann. periods: 4&#10;Total years: 5&#10;Annual Addition: 500.0&#10;Starting year 1 with $5000.00&#10;Year 1, period 1, accrued $61.62, value is now: $5061.62&#10;Year 1, period 2, accrued $62.38, value is now: $5124.01&#10;Year 1, period 3, accrued $63.15, value is now: $5187.16&#10;Year 1, period 4, accrued $63.93, value is now: $5251.09&#10;Added $500.00 for the end of year 1, total is now: 5751.09&#10;Starting year 2 with $5751.09&#10;Year 2, period 1, accrued $70.88, value is now: $5821.98&#10;Year 2, period 2, accrued $71.76, value is now: $5893.73&#10;Year 2, period 3, accrued $72.64, value is now: $5966.37&#10;Year 2, period 4, accrued $73.54, value is now: $6039.91&#10;Added $500.00 for the end of year 2, total is now: 6539.91&#10;Starting year 3 with $6539.91&#10;Year 3, period 1, accrued $80.60, value is now: $6620.51&#10;Year 3, period 2, accrued $81.60, value is now: $6702.11&#10;Year 3, period 3, accrued $82.60, value is now: $6784.71&#10;Year 3, period 4, accrued $83.62, value is now: $6868.34&#10;Added $500.00 for the end of year 3, total is now: 7368.34&#10;Starting year 4 with $7368.34&#10;Year 4, period 1, accrued $90.81, value is now: $7459.15&#10;Year 4, period 2, accrued $91.93, value is now: $7551.08&#10;Year 4, period 3, accrued $93.07, value is now: $7644.15&#10;Year 4, period 4, accrued $94.21, value is now: $7738.37&#10;Added $500.00 for the end of year 4, total is now: 8238.37&#10;Starting year 5 with $8238.37&#10;Year 5, period 1, accrued $101.54, value is now: $8339.90&#10;Year 5, period 2, accrued $102.79, value is now: $8442.69&#10;Year 5, period 3, accrued $104.06, value is now: $8546.75&#10;Year 5, period 4, accrued $105.34, value is now: $8652.09&#10;Added $500.00 for the end of year 5, total is now: 9152.09&#10;Final value: $9152.09&#10;&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Java utility to reorganize photos by date taken (via EXIF metadata)</title><link>https://evan.wtf/2007/03/28/java-utility-to-reorganize-photos-by-date-taken-via-exif-metadata/</link><pubDate>Wed, 28 Mar 2007 00:00:37 +0000</pubDate><guid>https://evan.wtf/2007/03/28/java-utility-to-reorganize-photos-by-date-taken-via-exif-metadata/</guid><description>&lt;p&gt;I wrote a little utility to reorganize my digital camera pics based on the EXIF date-taken data stored in the pic. It&amp;rsquo;s pretty simple, I hacked it together in about an hour,&#10;but I thought it might be worth sharing for anyone else looking to do something similar. My camera organizes stuff as it sees fit sometimes, I am particular about my directory structure. This is probably a job best left to perl, but I don&amp;rsquo;t feel like getting Perl running on my Windows box where all the pics are. Now I can finally burn all my images to DVD.&lt;/p&gt;</description></item></channel></rss>