<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Software development B-sides and oddities</description><title>Extraneous</title><generator>Tumblr (3.0; @extensible)</generator><link>http://ext.raneous.net/</link><item><title>My UTF-8 Byte Order Mark (BOM) Adventure</title><description>&lt;p&gt;Another random issue that I resolved earlier with the help of the Internet…&lt;/p&gt;

&lt;p&gt;For quite some time now, I’ve had one particular JavaScript file in &lt;a href="https://github.com/bmoeskau/Extensible"&gt;Extensible&lt;/a&gt; that, after every run through my build script, would come out the other side with a garbage character at the top of the file.  When running it in the browser the page would choke with a strange “ILLEGAL CHARACTER” error showing the following arcane string: ï»¿&lt;/p&gt;

&lt;p&gt;I never even knew where to begin with this, and frankly just assumed it was a bug in the Java-based build tool. I’ve been manually removing that character after my builds, well, for way too long.  Tonight I finally decided to fix it, and the brilliant idea struck me — how about Googling “ï»¿”?  Well, duh, of course that led me immediately to many explanations of the good old &lt;a href="http://unicode.org/faq/utf_bom.html"&gt;UTF-8 Byte Order Mark&lt;/a&gt;, which is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. A BOM is useful at the beginning of files that are typed as text, but for which it is not known whether they are in big or little endian format—it can also serve as a hint indicating that the file is in Unicode, as opposed to in a legacy encoding.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OK, awesome. All of my files are already encoded as UTF-8, apparently without byte order marks, so I have no clue how this one file got one inserted.  How to get rid of it?&lt;/p&gt;

&lt;p&gt;I use Aptana as my JavaScript editor, so I tried converting the encoding, but turns out there is no explicit option to encode without BOM, so Apatana silently ignores the existing BOM regardless of the encoding (apparently it’s &lt;a href="https://aptanastudio.tenderapp.com/discussions/problems/1900-encoding-utf-8-with-bom"&gt;a general Eclipse issue&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;A little more Googling led me to &lt;a href="http://forums.phplist.com/viewtopic.php?f=6&amp;t=29602"&gt;a pointer&lt;/a&gt; that in &lt;a href="http://notepad-plus-plus.org/"&gt;Notepad++&lt;/a&gt; you can explicitly encode to UTF-8 without BOM. Although I work on OSX I use Windows VMs for testing, so I cranked up Parallels, copied my script into Windows 7, downloaded Notepad++, converted, copied back, and presto — problem solved!  There’s undoubtedly a way to do the conversion in OSX, but this was easy enough and it worked.&lt;/p&gt;

&lt;p&gt;Yet another completely useless factoid that was hard-won, and that I’ll almost certainly forget by tomorrow morning.&lt;/p&gt;</description><link>http://ext.raneous.net/post/16512690236</link><guid>http://ext.raneous.net/post/16512690236</guid><pubDate>Thu, 26 Jan 2012 01:03:51 -0600</pubDate><category>utf-8</category><category>bom</category><category>random</category></item><item><title>Markdown + Urls with Parentheses</title><description>&lt;p&gt;Yet another completely random topic… I ran across this when trying to link to a resource on Microsoft’s MSDN site from a  &lt;a href="http://daringfireball.net/projects/markdown/syntax"&gt;Markdown&lt;/a&gt; document. The link for the page is:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd633694"&gt;http://msdn.microsoft.com/en-us/library/dd633694&lt;/a&gt;(v=exchg.80).aspx&lt;/p&gt;

&lt;p&gt;which as you can see, readily confuses Tumblr as well, which uses Markdown during editing and converts it automatically to the broken HTML seen above. The syntax for defining a link in Markdown looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[some link](&lt;a href="http://some-url.com"&gt;http://some-url.com&lt;/a&gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which would then render the link like so: &lt;a href="http://some-url.com"&gt;some link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the url portion of the link is delimited by &lt;code&gt;(&lt;/code&gt; and &lt;code&gt;)&lt;/code&gt;, adding parentheses into the url string confuses the Markdown parser (and different Markdown parsers may actually parse it differently).&lt;/p&gt;

&lt;p&gt;The solution is simple, though maybe not obvious — you have to HTML-encode the parentheses when using them in a Markdown link. The url-encoded value for &lt;code&gt;(&lt;/code&gt; is &lt;code&gt;%28&lt;/code&gt; and &lt;code&gt;)&lt;/code&gt; is &lt;code&gt;%29&lt;/code&gt;. So our fixed link now looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[MSDN page](&lt;a href="http://msdn.microsoft.com/en-us/library/dd633694%28v=exchg.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd633694%28v=exchg.80%29.aspx&lt;/a&gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which now renders and functions as expected: &lt;a href="http://msdn.microsoft.com/en-us/library/dd633694%28v=exchg.80%29.aspx"&gt;MSDN page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(By the way, who even uses stupid urls with parentheses in them? Microsoft, once again, making the web just a little bit harder to work with.  Thanks!)&lt;/p&gt;</description><link>http://ext.raneous.net/post/14580141233</link><guid>http://ext.raneous.net/post/14580141233</guid><pubDate>Wed, 21 Dec 2011 15:41:00 -0600</pubDate><category>m$</category><category>markdown</category><category>annoying</category></item><item><title>Github Font Issue on Chrome for Mac</title><description>&lt;p&gt;For weeks now, I’ve had the issue, only on the combination of Chrome 16 + Mac OSX 10.7 + Github + my MacBook Pro (I do not have this issue on my desktop Mac Pro, or in other browsers) where the font used for code on Github.com (e.g., for stuff like &lt;a href="https://github.com/bmoeskau/Extensible/blob/master/src/Extensible.js"&gt;this&lt;/a&gt;) was displaying as the default browser font of Times New Roman. Let me tell you, Times is a painful font for web viewing in any context, but for code it’s downright unreadable.&lt;/p&gt;

&lt;p&gt;After a bit of Googling, I ran across &lt;a href="http://apple.stackexchange.com/questions/16464/google-chrome-repeatedly-displays-monospaced-fonts-wrong-as-times-new-roman"&gt;this exact issue&lt;/a&gt; on the Ask Different site.  After using the recommended command line commands to reset my machine’s font cache (who knew such a thing even existed?) I was back to a default monospaced font, at least (Courier, ugh).&lt;/p&gt;

&lt;p&gt;The first-choice font for code on Github is &lt;a href="http://en.wikipedia.org/wiki/Bitstream_Vera"&gt;Bitstream Vera Sans Mono&lt;/a&gt;, a lovely monospaced font that (I thought) I had installed already, but apparently I didn’t (or it had gotten itself removed somehow). So I &lt;a href="http://www-old.gnome.org/fonts/"&gt;downloaded&lt;/a&gt; and installed it manually, re-cleared my font cache, restarted Chrome, and voilà, back to beautiful code.&lt;/p&gt;

&lt;p&gt;Random.&lt;/p&gt;</description><link>http://ext.raneous.net/post/14469893158</link><guid>http://ext.raneous.net/post/14469893158</guid><pubDate>Mon, 19 Dec 2011 14:40:00 -0600</pubDate><category>github</category><category>fonts</category><category>osx</category><category>chrome</category></item><item><title>Fixing a Stuck VM</title><description>&lt;p&gt;My Parallels virtual machine got stuck in a “stopping” state earlier (after an aborted reboot of my physical machine) but it would never stop, and could not be restarted. Luckily &lt;a href="http://kb.parallels.com/en/6338"&gt;this&lt;/a&gt; worked like a charm.&lt;/p&gt;</description><link>http://ext.raneous.net/post/14002398686</link><guid>http://ext.raneous.net/post/14002398686</guid><pubDate>Fri, 09 Dec 2011 23:14:46 -0600</pubDate><category>tips</category><category>random</category></item><item><title>Owning it</title><description>&lt;img src="http://30.media.tumblr.com/tumblr_lswpizKrse1qmracso1_500.png"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Owning it&lt;/p&gt;</description><link>http://ext.raneous.net/post/11317135076</link><guid>http://ext.raneous.net/post/11317135076</guid><pubDate>Tue, 11 Oct 2011 09:56:59 -0500</pubDate></item><item><title>Node Server Kill/Restart Script for OSX</title><description>&lt;p&gt;There are times when it would be convenient to kill a running node server and/or restart it in an automated fashion, by name rather than by process id.  It’s easy enough to kill a process in Linux, but first you have to find it. It’s simple to list all active process, filtering based on part of the process name like so, assuming a node server named “myserver”:&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
    ps ax | grep myserver
&lt;/pre&gt;

&lt;p&gt;If myserver is indeed still running you’ll see output like this:&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
45727 s000  T      0:00.02 sudo node myserver
45728 s000  T      0:00.15 node myserver
45794 s000  R+     0:00.00 grep myserver
&lt;/pre&gt;

&lt;p&gt;Once you know the process ID (PID) it’s a simple matter of killing it:&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
    sudo kill -9 45728
&lt;/pre&gt;

&lt;p&gt;So just kill the process by id, and then you’re good to restart myserver.  [&lt;em&gt;Note&lt;/em&gt;: The -9 (or -KILL) switch is not always required, but was in my case. YMMV.]&lt;/p&gt;

&lt;p&gt;Of course, each time you restart the server the process is assigned a unique PID, so if you have to kill the new process you first must find it then kill it by the new PID.  In some cases this can prove inconvenient, e.g. if you want an automated clean up or restart script, say as part of a CI process.&lt;/p&gt;

&lt;p&gt;But wait, I can hear you say, what about the awesome &lt;a href="http://linux.die.net/man/1/pkill"&gt;pkill&lt;/a&gt; command that can kill a process based on regex matching?  I agree, that is awesome indeed — unfortunately pkill is not available on OSX.  There are various &lt;a href="http://unix.stackexchange.com/questions/225/pgrep-and-pkill-alternatives-on-mac-os-x"&gt;alternatives&lt;/a&gt;, most of which seem hacky at best. You can also install an implementation of pkill (among other things) via &lt;a href="http://proctools.sourceforge.net/"&gt;proctools&lt;/a&gt;, but I really wanted to solve my problem without having to make modifications to my system first.&lt;/p&gt;

&lt;p&gt;I finally ran across &lt;a href="http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex/3510850#3510850"&gt;this answer&lt;/a&gt; on StackOverflow which gave me the basic command I needed, and from there it was a simple matter of wrapping that up into a reusable shell script.&lt;/p&gt;

&lt;h2&gt;&lt;a href="https://github.com/bmoeskau/node-kill"&gt;Node Kill&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;It’s a very simple shell script that kills a node server by name (not PID) and optionally restarts it in a single command.  For example:&lt;/p&gt;

&lt;pre class="brush: bash"&gt;
    sh kill.sh -r myserver
&lt;/pre&gt;

&lt;p&gt;That will terminate the ‘node myserver’ process(es) and automatically restart the server for you, simple as that.&lt;/p&gt;

&lt;p&gt;The code is &lt;a href="https://github.com/bmoeskau/node-kill"&gt;available on Github&lt;/a&gt;, and any suggestions for improvement are welcome.&lt;/p&gt;</description><link>http://ext.raneous.net/post/9449201654</link><guid>http://ext.raneous.net/post/9449201654</guid><pubDate>Sat, 27 Aug 2011 03:10:00 -0500</pubDate><category>node</category><category>bash</category></item></channel></rss>

