<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jathanism &#187; dongs</title>
	<atom:link href="http://jathan.com/tag/dongs/feed/" rel="self" type="application/rss+xml" />
	<link>http://jathan.com</link>
	<description>computers, robots, and other cool things.</description>
	<lastBuildDate>Fri, 28 May 2010 21:14:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Logical Meltdown</title>
		<link>http://jathan.com/2009/11/06/logical-meltdown/</link>
		<comments>http://jathan.com/2009/11/06/logical-meltdown/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 18:21:50 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Nerd Up]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dongs]]></category>
		<category><![CDATA[friday]]></category>
		<category><![CDATA[meltdown]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=229</guid>
		<description><![CDATA[x]]></description>
			<content:encoded><![CDATA[<p>I have been totally unable to accomplish any coding this week.  I&#8217;ve been rewriting this application at work and while I&#8217;ve made some decent progress, I haven&#8217;t gotten a damn thing done this week and it&#8217;s frustrating as hell!</p>

<p>Of course now that it&#8217;s Friday and I&#8217;m feeling the urge to start writing more code having to do with dongs.  What the fuck is wrong with me?  Don&#8217;t answer that.</p>

<p>I figured that by explaining some of what I&#8217;m struggling with, some magic will happen.  I need to blog more and work on my &#8220;explaining complex shit in a meaningful way&#8221; skills, so if this in any way interests you please read on.</p>

<p><strong>WARNING:</strong> TECHNICAL SHIT BELOW!</p>

<p>The application I am rewriting is a MySQL database-driven app that has two interfaces:
<ol>
    <li>A <a title="Description of CLI on Wikipedia" href="http://en.wikipedia.org/wiki/Command-line_interface" target="_blank">command-line interface</a> (CLI) utility written in Perl for direct manipulation (addition/removal of records) and querying (searching) of the database. Only engineers have access to this tool.</li>
    <li>A web application written in PHP for searching the database for non-engineers.  Mostly support and operations staff use this. This also provides a hacked up &#8220;API&#8221; that returns a list of comma-separated values (CSV) of matching records.</li>
</ol>
It&#8217;s something I wrote years ago using PHP &amp; MySQL that is way more complex than I remember it and double-dog dare you more complex than it needed to be. It&#8217;s strange going back in time with my code, especially PHP (<em>shame</em>), and realizing how competent I was even then, but how unnecessarily convoluted I made some things.</p>

<p>There are a shit-ton of logical pitfalls in that code that have really thrown me off.  Being that we have a Perl CLI tool and a PHP web app, the much of the code is duplicated for each language. The tool was originally written in Perl with the web app piece tacked on as an afterthought.  At the time I was really into PHP&#8217;s native support for MySQL but was pretty much a novice so ended up making some downright lazy and bad choices.</p>

<p>With PHP and it&#8217;s bloated cousin Perl, there are so many ways to do the same thing that there really isn&#8217;t one right way to do things.  Typically that means there are that many more <em>wrong</em> ways to do them.  For example, horrible crap like this where we have PHP making a <code>system()</code> call to execute a Perl script from within index.php:
<pre class="brush:php">&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr valign="top"&gt;
      &lt;td&gt;
        &lt;?
          system('perl body.pl column="' . $<em>POST['column'] . '" value="' . $</em>POST['value'] . '" netmask="' . $_POST['method'] . '"');
        ?&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</pre>
Couple that with my prior lack of regimented programming style because I originally learned to code from the back of a Cracker Jack box (aka the internet), and what I am working with is pretty much a nightmare.</p>

<p>&#8220;Why is that?&#8221;, you ask?  Well let me tell you!</p>

<p>First things first, the primary users of the app (aka the stakeholders) have been requesting some new features for a long time and with everything else going on it hasn&#8217;t really been a high priority for me.  Especially because it was written in Perl, which I have grown to hate passionately since I started using Python.</p>

<p>Next, the systems from which the CLI tool runs are being replaced, which means the app has to be moved to the new systems. We run a Red Hat offshoot distribution of Linux, so we use <a title="Short for &quot;Red Hat Package Manager&quot;" href="http://en.wikipedia.org/wiki/RPM_Package_Manager" target="_blank">RPMs</a> to manage what gets installed on machines.  What this means is that any Perl module dependencies need to be installed via RPM. With RPM and Perl there are always dependencies of your dependencies, and you can bet that some of those won&#8217;t be available in the repository. This opens a massive can of worms of having to download the module source and convert it to RPM.  For those of you who are familiar with <a href="http://cpan.org" target="_blank">Perl&#8217;s CPAN</a> and RPM, you&#8217;re probably thinking &#8220;Just use cpan2prm!&#8221;. Right, if only it were that simple&#8230;</p>

<p>You see, the new hosts are running a 64-bit kernel, which means that the subset of available packages is even smaller because packages have to be specifically built (or rebuilt) for 64-bit installation. Even if it&#8217;s the same files inside of the package, it still has to be re-packaged for 64-bit.</p>

<p>So, I was left with the choice of either uprooting the tool from its current location, wrangling package dependencies, rebuilding packages, modifying the Perl code to shoehorn it into the new systems all the while overlooking the implementation of the requested features; or rewriting it using Python &amp; Django.</p>

<p>Naturally, I chose to rewrite it because the thought of having to trudge through antiquated Perl hackery gave me diarrhea and I really don&#8217;t want to ever touch Perl or PHP again if I can help it. By rewriting the app in Python, I can implement the new features and bring the code into the present at the same time without having to go through bouts contemplating suicide. Annnddd&#8230; That leads us back to the nightmare that is Perl and PHP.</p>

<p>As I mentioned above, with Perl &amp; PHP there are so many ways to do things that most of them are convoluted, confusing, hard-to-read, and just plain fucking wrong. With Python&#8211;and Django for that matter&#8211;there is usually only one right way to do things, and that way is pretty much always elegant.  Plus, one of the most beautiful things about Django is that it <a title="Making database queries with Django " href="http://docs.djangoproject.com/en/dev/topics/db/queries/" target="_blank">wholly and completely abstracts the database interaction</a> from the source code.  That means not having to write complex SQL statements manually, and the less SQL I have to write, the better.</p>

<p>In meeting with the stakeholders on rewriting the application, we decided that all of the energy should be invested in replacing the web app with a real API with a <a title="Representational State Transfer" href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">RESTful interface</a>. If you don&#8217;t know the basic premise of REST (which is a methodology, not a protocol), it&#8217;s that URLs should be easy-to-read, self-describing and beautiful. Beautiful URLs? WTF? How can a URL be beautiful?  I&#8217;m glad you asked!</p>

<p>The old PHP version of the API is very heavy on the query string, requiring GET variables to be passed in the URL itself which is not only cumbersome, but can get confusing and hard to read very quickly:</p>

<p><code>http://server.whatever.com/api.php?show=all&amp;user=jathan</code></p>

<p>Compare that to a RESTful version of the same:</p>

<p><code>http://server.whatever.com/api/show/all/jathan/</code></p>

<p>This is where Django excels because it encourages pretty URLs by making it easier to use pretty URLs than not to.</p>

<p>So, cutting this post off at the knees, I&#8217;ve been pounding on this for the past few weeks, learning a lot about how NOT to do things from my old code and how TO do things using Django as my guide.  I made a lot of progress, got the API working, and a basic search interface that returns stuff all using the same code.</p>

<p>But this week, I&#8217;ve been stuck.  I haven&#8217;t made any progress, have been getting really confused, and just generally bashing my skull into the keyboard.  I think I&#8217;m just fried from trudging through all of Perl&#8217;s curly braces, semicolons, ampersands, dollar signs&#8230; OMG THE SYNTAX!  KILL ME NOW!!</p>

<p>Besides, it&#8217;s Fried-day anyways, so I hope that just by spelling this all out here that I&#8217;ll be able to dig back into the code after the weekend with a renewed perspective.</p>

<p>p.s. Fuck Perl.</p>

<p>p.p.s. Fuck PHP too, but wrap that rascal. She gets around!</p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/11/06/logical-meltdown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Dongs on a Friday.  Surprise!!</title>
		<link>http://jathan.com/2009/10/16/more-dongs-on-a-friday/</link>
		<comments>http://jathan.com/2009/10/16/more-dongs-on-a-friday/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 16:45:54 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[blue dongs]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[crack]]></category>
		<category><![CDATA[dongs]]></category>
		<category><![CDATA[friday]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=221</guid>
		<description><![CDATA[Due to popular demand, mkdong has been modularized!!  I present to you dong.py version 0.0.1. Enjoy: #!/usr/bin/env python ''' MKdong turned into a module. I think I was smoking crack and/or high on Red Bull this day. Dong goes into underpants Dong goes into boxers Dong goes into vagina Sperm comes out of dong Sperm [...]]]></description>
			<content:encoded><![CDATA[<p>Due to popular demand, mkdong has been modularized!!  I present to you dong.py version 0.0.1.</p>

<p>Enjoy:
<pre class="brush:py">#!/usr/bin/env python</pre></p>

<p>'''
MKdong turned into a module.  I think I was smoking crack and/or high on Red Bull this day.</p>

<p>Dong goes into underpants
Dong goes into boxers
Dong goes into vagina
Sperm comes out of dong
Sperm goes into vagina
Sperm goes into egg
Dong goes into mouth
Pee comes out of dong
Pee goes into toilet
Why am I iterating this crap?
'''</p>

<p>import os, sys</p>

<p>blue = '&#92;&#92;e[0;34m' # blue</p>

<p>class Dong:</p>

<pre><code>def __init__(self, maxlen=40, color=blue):
    self.maxlen = maxlen
    self.color  = color
    self.dong   = None

def mkdong(self):
    self.dong = '(_)/(_)'
    for i in range(self.maxlen): self.dong += '/'
    self.dong += 'D'
    os.system('echo -e "%s%s"' % (self.color, self.dong))
</code></pre>

<p>class Sperm(Dong):
    def <strong>init</strong>(self, count=500):
        self.count = count
        self.spermcount()
        Dong.<strong>init</strong>(self)</p>

<pre><code>def __repr__(self):
    return '' % self.count

def tighty_whities(self):
    print 'Tighty Whities lowered your sperm count!'
    self.count -= 50

def boxers(self):
    print 'Boxers raised your sperm count!'
    self.count += 50

def spermcount(self):
    print 'Sperm count is %d' % self.count

def bike_seat(self):
    print 'asdjfoisadjs'
    pass

def radiation(self):
    print ':-x'
    pass

def castration(self):
    print ':('
    pass

def smoke(self):
    print 'awwww yeahhhhh.'
    pass
</code></pre>

<p>class Egg(Sperm):
    pass</p>

<p>if <strong>name</strong> == '<strong>main</strong>':</p>

<pre><code>try:
    donglen = int(sys.argv[1])
except:
    print "usage: mkdong "
    sys.exit()

if donglen &amp;gt; maxlen:
    print 'warning: a %s" dong is too big! cannot be longer than %s"!' % (donglen, maxlen)
    sys.exit()
else:
    d = dong(donglen)
    d.mkdong()&lt;/pre&gt;
</code></pre>

<p>There&#8217;s really no excuse.  I should be ashamed of myself but I&#8217;m not.  </p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/10/16/more-dongs-on-a-friday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blue Dongs for a Friday Afternoon</title>
		<link>http://jathan.com/2009/09/04/blue-dongs-for-a-friday-afternoon/</link>
		<comments>http://jathan.com/2009/09/04/blue-dongs-for-a-friday-afternoon/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 01:08:08 +0000</pubDate>
		<dc:creator>jathan</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[absurd]]></category>
		<category><![CDATA[blue dong of justice]]></category>
		<category><![CDATA[blue dongs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dongs]]></category>
		<category><![CDATA[friday]]></category>
		<category><![CDATA[jughead]]></category>
		<category><![CDATA[mkdong]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://jathan.com/?p=154</guid>
		<description><![CDATA[Today I wrote an awesome program called mkdong that will make a dong of your desired length and print it to your terminal, like this: % ./mkdong usage: mkdong &#60;length&#62; % ./mkdong 5 ()/()/////D % ./mkdong 25 ()/()/////////////////////////D That last one is impressive, isn&#8217;t it? Hmm&#8230; Yeah, it&#8217;s Friday. What do you want from me? [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wrote an awesome program called <tt>mkdong</tt> that will make a dong of your desired length and print it to your terminal, like this:
<pre>% ./mkdong
usage: mkdong &lt;length&gt;
% ./mkdong 5
(<em>)/(</em>)/////D
% ./mkdong 25
(<em>)/(</em>)/////////////////////////D</pre>
That last one is impressive, isn&#8217;t it?  Hmm&#8230; Yeah, it&#8217;s Friday.  What do you want from me?  I still got work done!  Cool thing is if the dong is too big, well then it throws an error:
<pre>% ./mkdong 60
warning: a 60" dong is too big! cannot be longer than 40"!</pre>
&#8220;What is the point of this?&#8221;, you might ask yourself.  That&#8217;s a good question.  I&#8217;ve been so busy with other shit lately that I&#8217;ve barely had time to code.  I suppose I was itching to write <em>something</em>, anything&#8230; Dongs!!</p>

<p>It all started harmlessly enough with a silly AIM conversation with my coding buddy at work.  We were talking about a bug, and well, read on and you&#8217;ll see.  It regressed quickly.
<div id="chat" style="padding-left: 30px;margin-bottom:10px;">jughead: well there is the problem, now I just gotta figure out wtf
jathanism: what did you do!
jughead: nothing, it&#8217;s something in the rt stuff
jathanism: hmm, maybe with a certain ticket
jathanism: maybe one that is blank or something
jathanism: or missing xml data
jathanism: or might be a bug
jughead: ok from now on
jughead: bugs are not bugs
jughead: they are dongs
jathanism: ok
jughead: &#8220;I found a dong in this code&#8221;
jathanism: or might be a dong
jughead: #1 deterrent of all linux exploits
jughead: change root account to &#8220;poop&#8221;, chown -R poop.poop /
jughead: no uid 0
jughead: no user root
jathanism: what?
jathanism: you rename uid 0 to poop ?
jughead: poop will get it&#8217;s own uid
jughead: and gid
jathanism: oh
jathanism: would that work?
jathanism: there aren&#8217;t any hard-coded things to uid 0?
jughead: no idea, lets try it
jathanism: yeah let&#8217;s try it on marduk!
jughead: hahahahfdsaf
jughead: dsfa
jughead: hmm&#8230;. /dev/ would have to be rebuilt
jughead: MKNOD
jughead: hate that shit
jughead: MAKEDEV
jughead: FUCK YOU LINUX
jathanism: mkdong
jathanism: aww yeah
jathanism: i just made mkdong
jathanism: % ./mkdong 5
8====0
jathanism: % ./mkdong 15
8==============0
jathanism: % ./mkdong 25
8========================0
jathanism: % ./mkdong 41
warning: a 41&#8243; dong is too big! cannot be longer than 40&#8243;!
jughead: you should modify that
jughead: (<em>)/(</em>)&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;\D
jathanism: hahahlk
jughead: looks much better
jathanism: ok!
jathanism: % ./mkdong 40
(<em>)/(</em>)&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;&#92;\D
jathanism: aww yeah</div>
<br />So I took the stupidity and ran with it and mkdong was born!</p>

<p>The initial dongs were a little primitive and sickly looking.  So I took his suggestion and improved their visual style.  Here is how it turned out:
<pre class="brush:py">#!/usr/bin/env python</pre></p>

<p>import sys</p>

<p>maxlen = 40</p>

<p>try:
    donglen = int(sys.argv[1])
except:
    print "usage: mkdong &lt;length&gt;"
    sys.exit()</p>

<p>if donglen &gt; maxlen:
    print 'warning: a %s" dong is too big! cannot be longer than %s"!' % (donglen, maxlen)
    sys.exit()
else:
    dong = '(<em>)/(</em>)'
    for i in range(1, donglen): dong += "&#92;"
    dong += 'D'</p>

<p>print dong
We laughed.  We joked.  <a href="http://twitter.com/jathanism/status/3762448157" target="_blank">We Tweeted</a>.  And then it regressed even further:
<div id="chat" style="padding-left: 30px;margin-bottom:10px;">jughead: dude everyone loves mkdong
jathanism: aww yeah
jathanism: it needs easter eggs
jughead: DUDE
jughead: MAKE IT PRINT IN BLUE
jathanism: ok!
jughead: how exactly does one &#8220;suck a fuck&#8221;
jathanism: the ascii coloring fucks up the length
jughead: you can just put the blue at the beginning
jughead: and at the end
jughead: doesn&#8217;t have to be each char
jathanism: it&#8217;s not
jughead: is there a dong in the code?
jathanism: /tmp/mkdong 5
jathanism: will just use forward slashes instad
jathanism: released
jughead: man mkdong is the best ever</div>
<br />A feature request!  I had to make it print in blue!  But to do that I had to replace all of the &#8220;\&#8221; that make up the dong itself, with &#8220;/&#8221; so as to not have the <a href="http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html" target="_blank">ANSI escape codes</a> eat up the extra backslashes. (Backslashes are interpreted characters, duh.)  I also had to replace the <tt>print</tt> statement with a system call to <tt>echo -e</tt> so that the colorization would be interpreted.  This is high tech shit, man!!</p>

<p>And then I <a href="http://twitter.com/jathanism/status/3763185098" target="_blank">released it to the public</a>. So there you have it.  Here is the final release of mkdong 2.0 for your pleasure:
<pre class="brush:py">#!/usr/bin/env python</pre></p>

<p>import os, sys</p>

<p>maxlen = 40
color = '&#92;&#92;e[0;34m' # blue</p>

<p>try:
    donglen = int(sys.argv[1])
except:
    print "usage: mkdong &lt;length&gt;"
    sys.exit()</p>

<p>if donglen &gt; maxlen:
    print 'warning: a %s" dong is too big! cannot be longer than %s"!' % (donglen, maxlen)
    sys.exit()
else:
    dong = '(<em>)/(</em>)'
    for i in range(donglen): dong += '/'
    dong += 'D'</p>

<p>os.system('echo -e "%s%s"' % (color, dong))
Use it well.  And remember they aren&#8217;t bugs, they&#8217;re dongs!  Squish?  Gross.</p>
]]></content:encoded>
			<wfw:commentRss>http://jathan.com/2009/09/04/blue-dongs-for-a-friday-afternoon/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
