<?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>Belchak.com</title>
	<atom:link href="http://www.belchak.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.belchak.com</link>
	<description>Technology and Awesome</description>
	<lastBuildDate>Sat, 21 Jan 2012 19:25:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>JIRA and Campfire Integration</title>
		<link>http://www.belchak.com/2012/01/21/jira-and-campfire-integration/</link>
		<comments>http://www.belchak.com/2012/01/21/jira-and-campfire-integration/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 19:25:22 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[JIRA]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[campfire]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[jira]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=42</guid>
		<description><![CDATA[I have been working on migrating my company&#8217;s Pivotal Tracker to JIRA. We love most of the features of JIRA, but we were really missing the nice updates to our Campfire room to tell us what is going on with our issues. Sure, we could use an RSS feed plugin for Campy, but that is [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I have been working on migrating my company&#8217;s Pivotal Tracker to JIRA. We love most of the features of JIRA, but we were really missing the nice updates to our Campfire room to tell us what is going on with our issues.</p>
<p>Sure, we could use an RSS feed plugin for <a title="Campy: the Python Campfire Bot" href="http://www.belchak.com/2011/06/24/campy-the-python-campfire-bot/">Campy</a>, but that is not real-time enough.</p>
<p>I didn&#8217;t want to write a huge plugin just to send messages to Campfire (it seems like such a simple thing to do!). I was poking around for solutions, and came across <a title="Groovy Script Runner" href="https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner">this plugin</a>. It&#8217;s a plugin that runs scripts written in the <a title="Groovy" href="http://groovy.codehaus.org/">Groovy</a> dynamic language for Java. One nice thing about this plugin is that it lets you execute Python (Jython) or Ruby (Jruby). The only problem is that you can&#8217;t write a listener using Python, so I ended up having to learn Groovy.</p>
<p>Here&#8217;s what I came up with. It requires you to install the <a title="HTTPBuilder" href="http://groovy.codehaus.org/modules/http-builder/doc/index.html">HTTPBuilder</a> libraries for Groovy, and this script will require some customization to fit your environment. Right now it only supports sending messages when new issues are created and when a new comment is added to an existing issue, but other issue events would be easy enough to add &#8211; this is meant as an example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.atlassian.jira.event.issue.AbstractIssueEventListener</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.atlassian.jira.event.issue.IssueEvent</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.atlassian.jira.ComponentManager</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.apache.log4j.Category</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">groovyx.net.http.RESTClient</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">static</span> groovyx.<span style="color: #006600;">net</span>.<span style="color: #006600;">http</span>.<span style="color: #006600;">ContentType</span>.<span style="color: #006600;">JSON</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">static</span> com.<span style="color: #006600;">atlassian</span>.<span style="color: #006600;">jira</span>.<span style="color: #006600;">event</span>.<span style="color: #006600;">type</span>.<span style="color: #006600;">EventType</span>.<span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> CampfireListener <span style="color: #000000; font-weight: bold;">extends</span> AbstractIssueEventListener <span style="color: #66cc66;">&#123;</span>
&nbsp;
    @Override
    <span style="color: #993333;">void</span> workflowEvent<span style="color: #66cc66;">&#40;</span>IssueEvent event<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">def</span> Category log <span style="color: #66cc66;">=</span> Category.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;com.onresolve.jira.groovy.PostFunction&quot;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">def</span> campfire <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RESTClient<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'https://CAMPFIREID.campfirenow.com/room/ROOMID/'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">def</span> issueBaseUrl <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;http://yourjirahost:8080/path-to-jira/browse/&quot;</span>
        campfire.<span style="color: #006600;">auth</span>.<span style="color: #006600;">basic</span> <span style="color: #ff0000;">'CAMPFIRE AUTH TOKEN'</span>, <span style="color: #ff0000;">'X'</span> 
        <span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">getEventTypeId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">case</span> ISSUE_COMMENTED_ID:
                <span style="color: #000000; font-weight: bold;">def</span> resp <span style="color: #66cc66;">=</span> campfire.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span> path: <span style="color: #ff0000;">'speak.json'</span>,
                                      body: <span style="color: #66cc66;">&#91;</span> message: <span style="color: #66cc66;">&#91;</span> type: <span style="color: #ff0000;">&quot;TextMessage&quot;</span>, body:
                                          <span style="color: #aaaadd; font-weight: bold;">String</span>.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%s added a comment to %s (%s%s):&quot;</span>,
                                              event.<span style="color: #006600;">getUser</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getDisplayName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
                                              event.<span style="color: #006600;">issue</span>.<span style="color: #006600;">getKey</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
                                              issueBaseUrl,
                                              event.<span style="color: #006600;">issue</span>.<span style="color: #006600;">getKey</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span>,
                                      requestContentType: JSON<span style="color: #66cc66;">&#41;</span>
                resp <span style="color: #66cc66;">=</span> campfire.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span> path: <span style="color: #ff0000;">'speak.json'</span>,
                                      body: <span style="color: #66cc66;">&#91;</span> message: <span style="color: #66cc66;">&#91;</span> type: <span style="color: #ff0000;">&quot;PasteMessage&quot;</span>, body:
                                          <span style="color: #aaaadd; font-weight: bold;">String</span>.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%s&quot;</span>, event.<span style="color: #006600;">getComment</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getBody</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span>,
                                      requestContentType: JSON<span style="color: #66cc66;">&#41;</span>
                <span style="color: #000000; font-weight: bold;">break</span>
            <span style="color: #b1b100;">case</span> ISSUE_CREATED_ID:
                <span style="color: #000000; font-weight: bold;">def</span> resp <span style="color: #66cc66;">=</span> campfire.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span> path: <span style="color: #ff0000;">'speak.json'</span>,
                        body: <span style="color: #66cc66;">&#91;</span> message: <span style="color: #66cc66;">&#91;</span> type: <span style="color: #ff0000;">&quot;TextMessage&quot;</span>, body:
                            <span style="color: #aaaadd; font-weight: bold;">String</span>.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'%s created a new issue: &quot;%s&quot; (%s%s):'</span>,
                                event.<span style="color: #006600;">getUser</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getDisplayName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
                                event.<span style="color: #006600;">issue</span>.<span style="color: #006600;">getSummary</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
                                issueBaseUrl,
                                event.<span style="color: #006600;">issue</span>.<span style="color: #006600;">getKey</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span>,
                        requestContentType: JSON<span style="color: #66cc66;">&#41;</span>
                resp <span style="color: #66cc66;">=</span> campfire.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span> path: <span style="color: #ff0000;">'speak.json'</span>,
                      body: <span style="color: #66cc66;">&#91;</span> message: <span style="color: #66cc66;">&#91;</span> type: <span style="color: #ff0000;">&quot;PasteMessage&quot;</span>, body:
                          <span style="color: #aaaadd; font-weight: bold;">String</span>.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%s&quot;</span>, event.<span style="color: #006600;">getIssue</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getDescription</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#93;</span>,
                      requestContentType: JSON<span style="color: #66cc66;">&#41;</span>
                <span style="color: #000000; font-weight: bold;">break</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<div class="shr-publisher-42"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2012/01/21/jira-and-campfire-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with IPv4/6 hosts in OSX Lion</title>
		<link>http://www.belchak.com/2011/07/27/problems-with-ipv46-hosts-in-osx-lion/</link>
		<comments>http://www.belchak.com/2011/07/27/problems-with-ipv46-hosts-in-osx-lion/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 23:18:43 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=39</guid>
		<description><![CDATA[If you&#8217;re like me, you end up doing a lot of testing in virtual machines. I run several VMs that do various different tasks for me so that I don&#8217;t have to sully my Mac with packages I rarely need, etc. So what I do is create a VM and give it a local hostname [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>If you&#8217;re like me, you end up doing a lot of testing in virtual machines. I run several VMs that do various different tasks for me so that I don&#8217;t have to sully my Mac with packages I rarely need, etc. So what I do is create a VM and give it a local hostname defined in my /etc/hosts file.</p>
<p>Recently, after my upgrade to OSX Lion, I started running into an issue where it would take over 5 seconds to connect to any of my VMs using any protocol (SSH, HTTP, etc). After several hours of troubleshooting, and several Wireshark sessions later, the truth of the matter was plain:</p>
<p><a href="http://www.belchak.com/wp-content/uploads/2011/07/kdxf5y8qtaxh.png"><img class="aligncenter size-medium wp-image-40" title="kdxf5y8qtaxh" src="http://www.belchak.com/wp-content/uploads/2011/07/kdxf5y8qtaxh-300x15.png" alt="" width="300" height="15" /></a></p>
<p>OSX is now doing IPv6 by default with no way that I have found to disable it yet, and so that means that if you have hosts that you want to reference with locally defined hostnames, you are going to have to create an IPv6 entry for them as well.</p>
<p>Here is a great site that I found that helps with the conversion: <a href="http://www.subnetonline.com/pages/converters/ipv4-to-ipv6.php" target="_blank">SubnetOnline.com</a> </p>
<p>I am sure that there are better ways to do this, but I just wanted to share this quick little hack that I found with you. If you have a better way, please let me know!</p>
<div class="shr-publisher-39"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/07/27/problems-with-ipv46-hosts-in-osx-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re-enabling Key Repeat in OSX Lion</title>
		<link>http://www.belchak.com/2011/07/23/re-enabling-key-repeat-in-osx-lion/</link>
		<comments>http://www.belchak.com/2011/07/23/re-enabling-key-repeat-in-osx-lion/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 04:51:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[key-repeat]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=37</guid>
		<description><![CDATA[I have recently upgraded to OSX Lion, and I have to say that I love everything about it. Except for one thing. In many apps, the key repeat has been disabled in favor of the new press-and-hold popup for getting alternative characters. This is fine for most apps, but for apps like PyCharm where I use [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I have recently upgraded to OSX Lion, and I have to say that I love everything about it. Except for one thing. In many apps, the key repeat has been disabled in favor of the new press-and-hold popup for getting alternative characters.</p>
<p>This is fine for most apps, but for apps like <a href="http://www.jetbrains.com/pycharm/" target="_blank">PyCharm</a> where I use vi key maps, it becomes very, very frustrating.</p>
<p>I came across this little tip to re-enable the key repeat, and my life is measurably better (first world problems, I know&#8230;).</p>
<p>Run the following in your Terminal.app:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">defaults <span style="color: #c20cb9; font-weight: bold;">write</span> <span style="color: #660033;">-g</span> ApplePressAndHoldEnabled <span style="color: #660033;">-bool</span> <span style="color: #c20cb9; font-weight: bold;">false</span></pre></td></tr></table></div>

<p>Then reboot, and you should be good to go!</p>
<div class="shr-publisher-37"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/07/23/re-enabling-key-repeat-in-osx-lion/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Campy: the Python Campfire Bot</title>
		<link>http://www.belchak.com/2011/06/24/campy-the-python-campfire-bot/</link>
		<comments>http://www.belchak.com/2011/06/24/campy-the-python-campfire-bot/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 17:06:13 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=34</guid>
		<description><![CDATA[We use a Campfire at Needle for our day-to-day communication between our tech team members and other business members. We really like Campfire&#8217;s ability to store files, conference call and keep transcripts even when you are not logged in. We get GitHub commit messages, Pivotal Tracker story updates and more scattered in our conversations. These [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>We use a <a href="http://www.campfirenow.com" target="_blank">Campfire</a> at <a href="http://www.needle.com">Needle</a> for our day-to-day communication between our tech team members and other business members. We really like Campfire&#8217;s ability to store files, conference call and keep transcripts even when you are not logged in. We get <a href="http://github.com" target="_blank">GitHub</a> commit messages, <a href="http://pivotaltracker.com" target="_blank">Pivotal Tracker</a> story updates and more scattered in our conversations.</p>
<p>These one-way updates are very nice, but I thought it would be nice to be able to have a bot that sat in the channel and could take commands from anybody and do more complex tasks for us without us ever having to leave Campfire. To solve this problem, I wrote <a href="http://www.github.com/bbelchak/campy" target="_blank">Campy</a>, a pure Python Campfire bot with an extensible plugin system.</p>
<p>The first plugin I wrote as a proof of concept is a Google image search plugin. You tell the bot some search parameters that you would like it to search for, and you get back an image inline in your chat transcript. Don&#8217;t worry, safe search is on by default so you don&#8217;t get any NSFW images back.</p>
<p>The second plugin I wrote was the all-important Pivotal Tracker plugin. This plugin lets you do the following:</p>
<ul>
<li>pt story create &#8220;Title&#8221; &#8220;Description&#8221; bug|feature|chore|release &#8212; Create a story</li>
<li>pt getmine started|finished|delivered|accepted|rejected|unstarted|unscheduled &#8212; Get a list of all stories that belong to you</li>
<li>pt start #story_id &#8212; Start a particular story.</li>
<li>pt start|tell next bug|feature|chore [mine] &#8212; Start or tell the next story of a given type. Optionally supply &#8216;mine&#8217; at the end of the message to only work on your own stories.</li>
</ul>
<p>The plugins system is very extensible, so you can create a plugin to do pretty much anything!</p>
<p>You can get Campy here:  <a href="https://github.com/bbelchak/campy">https://github.com/bbelchak/campy</a></p>
<div class="shr-publisher-34"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/06/24/campy-the-python-campfire-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ergotron WorkFit-S Standing Desk Review</title>
		<link>http://www.belchak.com/2011/03/04/workfit-standing-desk/</link>
		<comments>http://www.belchak.com/2011/03/04/workfit-standing-desk/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 19:31:14 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[ergotron]]></category>
		<category><![CDATA[standing desk]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[workfit]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=29</guid>
		<description><![CDATA[A few months ago, I started investigating the health benefits of standing while I work at my computer. The benefits are myriad, and include: More calories burned. Standing at a desk while you work can actually burn around 300 calories per day more than sitting. Standing at a desk helps people with back problems. Humans [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>A few months ago, I started investigating the health benefits of standing while I work at my computer. The benefits are myriad, and include:</p>
<ul>
<li><strong>More calories burned</strong>. Standing at a desk while you work can actually burn around 300 calories per day more than sitting.</li>
<li><strong>Standing at a desk helps people with back problems</strong>. Humans were not made for sitting, and doing so for long periods of time can be really hard on your hips and lower back.</li>
<li><strong>Improved posture. </strong>Standing can help improve your posture, which can relieve pain in your lower and upper back, and neck.</li>
<li><strong>More breaks. </strong>I find that I take more breaks, which makes me happier and healthier. While standing, it is easier to just walk away instead of hauling yourself out of a chair.</li>
</ul>
<p>After my research, I decided to convert my cheap IKEA desk into a standing desk by raising the legs up as far as they could go and then stacking books and Rubbermaid bins to get the height on the keyboard and monitors right. Here&#8217;s what I ended up with:</p>
<div id="attachment_30" class="wp-caption aligncenter" style="width: 234px"><a href="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0042.jpg"><img class="size-medium wp-image-30" title="Old standing desk" src="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0042-224x300.jpg" alt="" width="224" height="300" /></a><p class="wp-caption-text">Old standing desk setup</p></div>
<p>As you can see, it is less than ideal. It forced me to stand 100% of the time, and in order to take a break from standing, I needed to disconnect my laptop from everything and take it to a chair. Not awesome.</p>
<p>I reverted back to a sitting desk, and kept wishing for a standing option that would allow me to quickly change to a sitting position if I got tired, without having to deal with completely rearranging my work area.</p>
<p>Then, I discovered the Ergotron WorkFit-S while searching around for standing desk options. I loved the youtube video I found here:</p>
<p><iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/lK4yYENEtHA" frameborder="0" allowfullscreen></iframe></p>
<p>I bought the WorkFit-S Combo (laptop + LCD) on Amazon with overnight shipping with my Amazon Prime account, and it arrived very quickly. I was a bit worried because the tech specs indicated that the maximum monitor size is 20&#8243; while using a laptop. I spoke with one of their marketing people on Twitter, and they were very helpful, checking with their support staff and product managers to provide me with any tips that they could dig up while I anxiously awaited the FedEx delivery guy.</p>
<p>When I received it, I immediately installed it on my desk. It took approximately 15 minutes to get it built and installed on my desk. My 24&#8243; LCD fit perfectly on the right, with my laptop on the left. I think the concern with the size of the monitor is not necessarily the size, but the weight. I could probably fit a 27&#8243; on here without a problem if it was light enough. My LCD and laptop are probably right on the edge of the maximum weight. Since the up and down motion is achieved with a pulley system, I had to adjust the tension a bit to get the balance right.</p>
<div id="attachment_32" class="wp-caption aligncenter" style="width: 234px"><a href="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0253.jpg"><img class="size-medium wp-image-32" title="WorkFit-S in &quot;sitting mode&quot;" src="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0253-224x300.jpg" alt="" width="224" height="300" /></a><p class="wp-caption-text">WorkFit-S in &quot;sitting mode&quot;</p></div>
<p>I did have to move it after I&#8217;d installed it in the center of my corner desk because the mouse tray kept hitting the desk where it curves.</p>
<p>The thing will attach to virtually any surface, but they also make a wheeled cart that has similar features.</p>
<div id="attachment_31" class="wp-caption aligncenter" style="width: 234px"><a href="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0252.jpg"><img class="size-medium wp-image-31 " title="WorkFit-S in &quot;standing mode&quot;" src="http://www.belchak.com/wp-content/uploads/2011/03/IMG_0252-224x300.jpg" alt="" width="224" height="300" /></a><p class="wp-caption-text">WorkFit-S in &quot;standing mode&quot;</p></div>
<p>I am very happy with it so far, and I look forward to reaping the benefits of standing, while having the option to sit!</p>
<p>The Ergotron WorkFit retails for around $399 and you can find them on <a href="http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;field-keywords=workfit-s&amp;x=0&amp;y=0">Amazon.com</a> or elsewhere.</p>
<div class="shr-publisher-29"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/03/04/workfit-standing-desk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing Django with a NoSQL Backend</title>
		<link>http://www.belchak.com/2011/02/07/unit-testing-django-with-a-nosql-backend/</link>
		<comments>http://www.belchak.com/2011/02/07/unit-testing-django-with-a-nosql-backend/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 02:44:24 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=27</guid>
		<description><![CDATA[In my previous post about unit testing for django, I laid the groundwork for how to unit test any django application. One nice feature that django includes with its test framework is the test database syncing. Even better is if you are using South to do database migrations &#8211; it will run the migrations in  your [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>In my previous post about <a href="http://www.belchak.com/2011/02/05/unit-testing-your-django-application/" target="_blank">unit testing for django</a>, I laid the groundwork for how to unit test any django application. One nice feature that django includes with its test framework is the test database syncing. Even better is if you are using <a href="http://www.belchak.com/2011/01/27/django-database-migrations-with-south/" target="_blank">South</a> to do database migrations &#8211; it will run the migrations in  your test environment for you.</p>
<p>However, what if you are using a NoSQL database backend like MongoDB, Cassandra, CouchDB or something similar and you aren&#8217;t using the Django ORM? How do you handle setting up and tearing down the database environments?</p>
<p>The good news is that Python&#8217;s unittest framework makes this easy. You can override the <code>setUp()</code> and <code>tearDown()</code> on each TestCase that you build. Here is a snippet to get you started:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pymongo
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: #dc143c;">test</span> <span style="color: #ff7700;font-weight:bold;">import</span> TestCase
&nbsp;
<span style="color: #808080; font-style: italic;"># It would be best to define this in a utility class somewhere</span>
<span style="color: #ff7700;font-weight:bold;">def</span> get_db<span style="color: black;">&#40;</span>db_name=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; GetDB - simple function to wrap getting a database 
    connection from the connection pool.
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> pymongo.<span style="color: black;">Connection</span><span style="color: black;">&#40;</span>
            host=settings.<span style="color: black;">MONGO_HOST</span>,
            port=settings.<span style="color: black;">MONGO_PORT</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #008000;">getattr</span><span style="color: black;">&#40;</span>
                settings, <span style="color: #483d8b;">&quot;MONGO_DBNAME_PREFIX&quot;</span>, <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span> + 
                <span style="color: black;">&#40;</span>db_name <span style="color: #ff7700;font-weight:bold;">or</span> settings.<span style="color: black;">MONGO_DBNAME</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MyTestCase<span style="color: black;">&#40;</span>TestCase<span style="color: black;">&#41;</span>:
    fixtures = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'test_data.json'</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> setUp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">db</span> = get_db<span style="color: black;">&#40;</span><span style="color: #483d8b;">'test'</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">db</span>.<span style="color: black;">create_collection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'mytestcollection'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_doc_published<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Set up a document to save</span>
        doc = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>text=<span style="color: #483d8b;">&quot;test&quot;</span>,
                      user_id=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">db</span>.<span style="color: black;">mytestcollection</span>.<span style="color: black;">save</span><span style="color: black;">&#40;</span>doc<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEqual</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">db</span>.<span style="color: black;">mytestcollection</span>.<span style="color: black;">find_one</span><span style="color: black;">&#40;</span>
            <span style="color: black;">&#123;</span><span style="color: #483d8b;">'user_id'</span>:<span style="color: #ff4500;">1</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'text'</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'test'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> tearDown<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">db</span>.<span style="color: black;">drop_collection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'mytestcollection'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>What this does is <code>setUp()</code> a collection in the <code>mytestcollection</code> collection, runs the <code>my_doc_published</code> test and then tears down the test database environment by dropping the <code>mytestcollection</code> collection.</p>
<p>Things to remember for <code>setUp()</code> and <code>tearDown()</code>:</p>
<ul>
<li><code>setUp()</code> is called before every test method in your TestCase class.</li>
<li><code>tearDown()</code> is called after every test method in your TestCase class.</li>
<li><code>tearDown()</code> is called even if your test methods fail or error out.</li>
</ul>
<p>And there you have it! Django makes testing even non-ORM datasources a snap, if you know how to wire it up.<br />
<strong>UPDATE:</strong> Some would say that database fixtures and setting up/tearing down database environments as part of your unit tests is not &#8220;unit testing&#8221;. This is not entirely accurate, because in order to do unit tests that rely on backend data, you <b>must</b> instantiate and tear down pristine database environments.</p>
<div class="shr-publisher-27"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/02/07/unit-testing-django-with-a-nosql-backend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing Your Django Application</title>
		<link>http://www.belchak.com/2011/02/05/unit-testing-your-django-application/</link>
		<comments>http://www.belchak.com/2011/02/05/unit-testing-your-django-application/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 04:33:40 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=24</guid>
		<description><![CDATA[Unit testing is a very important part of any software project. It helps you know that the new code you are deploying works, and isn&#8217;t going to blow up in your face. It also helps you feel good about changing large chunks of code without destroying everything you&#8217;ve done for the last 3 years. Unit [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Unit testing is a very important part of any software project. It helps you know that the new code you are deploying works, and isn&#8217;t going to blow up in your face. It also helps you feel good about changing large chunks of code without destroying everything you&#8217;ve done for the last 3 years.</p>
<p>Unit testing with django is as simple as pie. <a href="http://docs.djangoproject.com/en/dev/topics/testing/" target="_blank">The documentation</a> is very good, and you can learn a lot about more advanced testing methods from <a href="http://docs.python.org/library/unittest.html" target="_blank">the python documentation</a>. In this blog post, I aim to show a quick way to get up and running with testing your django application.</p>
<p>First, if you are just starting out, make sure you put a high emphasis on testing your application, otherwise you are going to end up with a bunch of code that has never been tested and you will find yourself writing code for weeks just to get partial coverage on the code you&#8217;ve already written. Starting off on the right foot is a much better approach, and you will find life much more enjoyable.</p>
<p>Let&#8217;s get started&#8230;<br />
<span id="more-24"></span></p>
<p>First of all, you need to define your models:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">db</span> <span style="color: #ff7700;font-weight:bold;">import</span> models
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> User
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Post<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    title = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=<span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span>
    body = models.<span style="color: black;">TextField</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    author = models.<span style="color: black;">ForeignKey</span><span style="color: black;">&#40;</span>User, related_name=<span style="color: #483d8b;">&quot;news_post&quot;</span><span style="color: black;">&#41;</span>
    date = models.<span style="color: black;">DateTimeField</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    users_read = models.<span style="color: black;">ManyToManyField</span><span style="color: black;">&#40;</span>User, related_name=<span style="color: #483d8b;">&quot;users&quot;</span>, blank=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>  
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__str__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">title</span></pre></td></tr></table></div>

<p>What we have done here is created a news post item. Let&#8217;s test it!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> PostTestCase<span style="color: black;">&#40;</span>TestCase<span style="color: black;">&#41;</span>:
    fixtures = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'test_data.json'</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> setUp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: #dc143c;">user</span> = User.<span style="color: black;">objects</span>.<span style="color: black;">create_user</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'newsposter'</span>, 
                                             <span style="color: #483d8b;">'newsposter@news.com'</span>, <span style="color: #483d8b;">'newspass'</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">post</span> = Post.<span style="color: black;">objects</span>.<span style="color: black;">create</span><span style="color: black;">&#40;</span>title=<span style="color: #483d8b;">&quot;Test Post #1&quot;</span>,
                body=<span style="color: #483d8b;">&quot;Test Post #1 Body&quot;</span>,
                author=<span style="color: #008000;">self</span>.<span style="color: #dc143c;">user</span>,
                date=<span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">c</span> = Client<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_post_creation<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        Tests that we can create a Post
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEqual</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">post</span>.<span style="color: black;">title</span>, <span style="color: #483d8b;">&quot;Test Post #1&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEqual</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">post</span>.<span style="color: black;">author</span>, <span style="color: #008000;">self</span>.<span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_user_can_read<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        Tests that a user is allowed to read.
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">c</span>.<span style="color: black;">login</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'newsposter'</span>, password=<span style="color: #483d8b;">'newspass'</span><span style="color: black;">&#41;</span>
        response = <span style="color: #008000;">self</span>.<span style="color: black;">c</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/news/get_post/1/'</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEqual</span><span style="color: black;">&#40;</span>response.<span style="color: black;">status_code</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertNotEqual</span><span style="color: black;">&#40;</span>response.<span style="color: black;">content</span>, <span style="color: #483d8b;">'{}'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>One of the really cool thing about testing with django is that it comes with a testing client that allows you to make requests just like a real user would. As you can see in our <code>test_user_can_read()</code> method, we have used the client to make a GET request against a URL. You can make a POST request just as easily:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">def</span> test_i_read_this<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        Tests a new user marking the story as read.
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">c</span>.<span style="color: black;">login</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'newsposter'</span>, password=<span style="color: #483d8b;">'newspass'</span><span style="color: black;">&#41;</span>
        response = <span style="color: #008000;">self</span>.<span style="color: black;">c</span>.<span style="color: black;">post</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/news/read/1/'</span>, <span style="color: black;">&#123;</span><span style="color: #483d8b;">'add'</span>:<span style="color: #008000;">True</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEqual</span><span style="color: black;">&#40;</span>response.<span style="color: black;">status_code</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEquals</span><span style="color: black;">&#40;</span>response.<span style="color: black;">content</span>, <span style="color: #483d8b;">'{<span style="color: #000099; font-weight: bold;">\n</span>    &quot;read&quot;: true<span style="color: #000099; font-weight: bold;">\n</span>}'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>In the previous code sample, the client sends a POST request to <code>/news/read/1/</code> with the <code>{'add':True}</code> data. This gets converted to form data and submitted via the POST. The request returns back JSON, which we match up against what we expect it to return.</p>
<p>Here are some things to remember when you are writing your test cases:</p>
<ul>
<li><code>setUp()</code> gets called before <strong>every</strong> test method in your TestCase.</li>
<li><code>tearDown()</code> gets called after <strong>every</strong> test method in your TestCase.</li>
<li>Test methods <strong>must</strong> start with &#8220;test&#8221; otherwise they will not be executed. It is safe to have other methods in your TestCase that do not begin with &#8220;test&#8221; if you want to abstract functionality for multiple test methods into a single function.</li>
<li>Django creates a test database for you, populates it, runs any south migrations (if you are using south), and then destroys it.</li>
<li>Do not expect that data that is available in one of your test methods will be available in another. Each test method starts with a blank data slate. If you need data instantiated before your tests are run, consider using the <code>setUp()</code> and <code>tearDown()</code> methods, or using fixtures. You can specify fixtures other than your initial_data fixtures by adding <code>fixtures = ['test_data.json']</code> to your TestCase class.</li>
</ul>
<p>Here is in-depth documentation about what assert methods are available to you in different versions of Python in <a href="http://docs.python.org/library/unittest.html#test-cases">the official Python unittest documentation</a>.</p>
<p>As you can see, testing with django is really really simple, but very powerful. In my next post, I will discuss how to test django with a MongoDB backend that does not use the ORM.</p>
<div class="shr-publisher-24"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/02/05/unit-testing-your-django-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Completion (IntelliSense) in VIM</title>
		<link>http://www.belchak.com/2011/01/31/code-completion-for-python-and-django-in-vim/</link>
		<comments>http://www.belchak.com/2011/01/31/code-completion-for-python-and-django-in-vim/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 15:58:05 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=21</guid>
		<description><![CDATA[VIM has been my editor of choice for at least 15 years. I love how fast I can edit files, perform menial tasks, and wreak general havoc on any code project I am working on at any given moment. One of the things that I have missed about VIM from an IDE perspective has been [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.vim.org/" target="_blank">VIM</a> has been my editor of choice for at least 15 years. I love how fast I can edit files, perform menial tasks, and wreak general havoc on any code project I am working on at any given moment. One of the things that I have missed about VIM from an IDE perspective has been code completion (a.k.a. &#8220;IntelliSense&#8221;). I have spent a lot of time on websites and man pages trying to figure out syntax and function names for several types of languages, and just recently discovered a long-included feature of VIM called omni completion, or Omnicomplete.</p>
<p>Since my life is mostly centered around <a href="http://www.djangoproject.com" target="_blank">django</a> these days, I will discuss how I&#8217;ve benefited from omnicomplete and how I&#8217;ve set it up in my own environment.</p>
<p>First, since django is a web development framework, I want to make sure that I can get omnicompletion for HTML, Python, JavaScript and CSS. Omnicompletion works for almost any programming language that VIM has syntax highlighting support for, and these languages are no exception.</p>
<p><span id="more-21"></span></p>
<p>Here&#8217;s what omnicomplete looks like for CSS files, for example:</p>
<div id="attachment_22" class="wp-caption alignnone" style="width: 310px"><a href="http://www.belchak.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-3.37.00-PM-1-30-11.png"><img class="size-medium wp-image-22" title="omnicomplete for css" src="http://www.belchak.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-3.37.00-PM-1-30-11-300x213.png" alt="omnicomplete for css" width="300" height="213" /></a><p class="wp-caption-text">omnicomplete for css</p></div>
<p>Setting this up for your django project is simple as pie. It is helpful to have all your django projects in one parent directory for the following setup. You can obviously customize this to your needs, but this is the way I&#8217;ve set it up in my environment.</p>
<p>Add the following to a script in a directory of your choosing (~/bin/vim_wrapper is where mine is):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PROJECT</span>=<span style="color: #000000; font-weight: bold;">`</span>python <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;import os; print os.path.basename(os.getcwd())&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PYTHONPATH</span>=<span style="color: #ff0000;">&quot;/path/to/your/projects/parent/directory/&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DJANGO_SETTINGS_MODULE</span>=<span style="color: #007800;">$PROJECT</span>.settings <span style="color: #c20cb9; font-weight: bold;">vim</span>
$<span style="color: #000000; font-weight: bold;">@</span></pre></td></tr></table></div>

<p>Then add the following line to your ~/.bash_profile or equivalent:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">vi</span>=<span style="color: #ff0000;">&quot;vim_wrapper&quot;</span></pre></div></div>

<p>Or, you can call your vim_wrapper script by hand. (<code>vim_wrapper file_to_edit.py</code>)</p>
<p>Next, add the following lines to your ~/.vimrc file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">filetype</span> <span style="color: #25BB4D;">plugin</span> <span style="color: #25BB4D;">on</span>
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">FileType</span> python <span style="color: #804040;">set</span> <span style="color: #668080;">omnifunc</span>=pythoncomplete#Complete
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">FileType</span> javascript <span style="color: #804040;">set</span> <span style="color: #668080;">omnifunc</span>=javascriptcomplete#CompleteJS
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">FileType</span> html <span style="color: #804040;">set</span> <span style="color: #668080;">omnifunc</span>=htmlcomplete#CompleteTags
<span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">FileType</span> css <span style="color: #804040;">set</span> <span style="color: #668080;">omnifunc</span>=csscomplete#CompleteCSS</pre></td></tr></table></div>

<p>I also prefer to re-map the default key binding (&lt;C-x&gt;&lt;C-o&gt;) to &lt;C-space&gt;, so I accomplish this by also adding the following line to my ~/.vimrc file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;">inoremap <span style="color: #000000;">&lt;</span>C<span style="color: #000000;">-</span>space<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>C<span style="color: #000000;">-</span>x<span style="color: #000000;">&gt;&lt;</span>C<span style="color: #000000;">-</span>o<span style="color: #000000;">&gt;</span></pre></td></tr></table></div>

<p>I also found <a href="http://blogs.gnome.org/lharris/2008/07/20/code-completion-with-vim-7/">this trick</a> today while searching around&#8230;</p>
<blockquote><p>What this function does is that if there is no completion that could happen it will insert a tab.  Otherwise it checks to see if there is an omnifunction available and, if so, uses it. Otherwise it falls back to Dictionary completion if there is a dictionary defined.  Finally it resorts to simple known word completion.  In general, hitting the Tab key will just do the right thing for you in any given situation.</p></blockquote>
<p>Add the following to your ~/.vimrc and you should be good to go. It works like a charm for me.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">function</span><span style="color: #000000;">!</span> SuperCleverTab<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #804040;">if</span> <span style="color: #25BB4D;">strpart</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">getline</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #25BB4D;">col</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'.'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> =<span style="color: #000000;">~</span> <span style="color: #C5A22D;">'^<span style="">\s</span>*$'</span>
        <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&quot;</span>
    else
        if &amp;omnifunc != ''
            return &quot;</span>\\<span style="color: #adadad; font-style: italic;">&quot;</span>
        <span style="color: #804040;">elseif</span> <span style="color: #000000;">&amp;</span>dictionary <span style="color: #000000;">!</span>= <span style="color: #C5A22D;">''</span>
            <span style="color: #804040;">return</span> <span style="color: #C5A22D;">&quot;<span style="">\&quot;</span>
        else
            return &quot;</span>\<span style="color: #adadad; font-style: italic;">&quot;</span>
        <span style="color: #804040;">endif</span>
    <span style="color: #804040;">endif</span>
endfunction
&nbsp;
inoremap <span style="color: #000000;">&lt;</span>Tab<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>C<span style="color: #000000;">-</span>R<span style="color: #000000;">&gt;</span>=SuperCleverTab<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #668080;">&lt;cr&gt;</span></pre></td></tr></table></div>

<p>If you find yourself writing code in other languages, the following lines in your vimrc should be adequate:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">filetype</span> <span style="color: #25BB4D;">plugin</span> <span style="color: #25BB4D;">on</span>
<span style="color: #804040;">set</span> <span style="color: #668080;">ofu</span>=syntaxcomplete#Complete</pre></td></tr></table></div>

<p>You can now test that your installation works by changing directories to one of your django projects, firing up vim and running the following command:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span>python from django import db</pre></td></tr></table></div>

<p>If you do not get a horrible error, you are good to go!</p>
<p>You can now access code completion by the following methods:</p>
<ul>
<li><code>&lt;C-p&gt;</code> &#8211; Shows a list of all local symbols. This is good if you do not have a tags file associated with the file you are editing.</li>
<li><code>&lt;C-space&gt;</code> &#8211; Shows a list of all available symbols. You need to set up a tags file, which is outside the scope of this blog post</li>
<li><code>&lt;C-x&gt;&lt;C-o&gt;</code> &#8211; The original keystroke sequence that we re-mapped C-space to.</li>
<li><code>&lt;Tab&gt;</code> &#8211; The all-powerful tab!</code>
</ul>
<p>I hope you enjoy your new-found power with vim as much as I do!</p>
<div class="shr-publisher-21"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/01/31/code-completion-for-python-and-django-in-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django database migrations with South</title>
		<link>http://www.belchak.com/2011/01/27/django-database-migrations-with-south/</link>
		<comments>http://www.belchak.com/2011/01/27/django-database-migrations-with-south/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 00:04:04 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[south]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=19</guid>
		<description><![CDATA[I have been using django for web development for almost a year now, and I just recently started using South to do database migrations. To be fair, most of the work that I have been doing with databases has centered around MongoDB and schema-less document stores instead of a traditional RDBMS. Since Django does not [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I have been using <a title="Django Project" href="http://djangoproject.com" target="_blank">django</a> for web development for almost a year now, and I just recently started using <a href="http://south.aeracode.org/" target="_blank">South</a> to do database migrations. To be fair, most of the work that I have been doing with databases has centered around <a title="MongoDB" href="http://www.mongodb.org" target="_blank">MongoDB</a> and schema-less document stores instead of a traditional RDBMS. Since Django does not come with any database migration tools, my standard approach was to make sure that my models are completely thought out before running the manage.py syncdb command. The lack of a good database migration tool was one of the things that originally had turned me off to django.</p>
<p>Enter South. South lets you manage your database in a way very similar to how <a href="http://rubyonrails.org" target="_blank">Ruby on Rails</a> works.</p>
<p><span id="more-19"></span></p>
<p>Converting a project to a South-managed project is very easy:</p>
<ol>
<li>Ensure that your database and models are completely synced up. (i.e. your models are not ahead of your database or vice-versa)</li>
<li>Install South by running <code>[sudo] pip install south</code></li>
<li>Add South to your <code>INSTALLED_APPS</code> list in the <code>settings.py</code> for your django project.</li>
<li>Run <code>./manage.py syncdb</code> in your project root directory to add the South database tables to your database.</li>
<li>If you have an existing application that you would like to conver to a South-managed application, run the following command: <code>./manage.py convert_to_south YOUR_APP_NAME</code> If not, go to the next step!</li>
<li>Now you are ready to go! You can change one of your models and then proceed to the next step.</li>
<li>Run the following command to get South to create an automatic migration for you: <code>./manage.py schemamigration YOUR_APP_NAME --auto</code></li>
<li>Now you can apply your newly created migration to your database:<code>./manage.py migrate YOUR_APP_NAME</code></li>
<li>Congratulations, you have performed your first database migration using South!</li>
</ol>
<p>South lets you apply up to or back to any migration point by running a command like: <code>./manage.py migrate YOUR_APP_NAME 0001</code> (that command would take you back to your initial migration point. You can get a list of all your migrations and a description about each one by running <code>./manage.py migrate YOUR_APP_NAME --list</code>. This lists all of the migrations you have available and denotes with a (*) which ones have been applied.</p>
<p>South is great for working in a team. All migrations are stored in YOUR_APP_NAME/migrations, so you can simply add these to your VCS and all of your team  members will get all of your migrations. If there is a conflict in some of the migrations that you and a team member have been working on, South will detect it and let you <a href="http://south.aeracode.org/docs/tutorial/part5.html#team-workflow" target="_blank">merge the conflicts</a>.</p>
<p>All in all, I am really loving South. It makes working with an RDBMS and Django much more pleasant!</p>
<div class="shr-publisher-19"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/01/27/django-database-migrations-with-south/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing old ssh fingerprints from your known_hosts the quick and easy way</title>
		<link>http://www.belchak.com/2011/01/27/removing-old-ssh-fingerprints-from-your-known_hosts-the-quick-and-easy-way/</link>
		<comments>http://www.belchak.com/2011/01/27/removing-old-ssh-fingerprints-from-your-known_hosts-the-quick-and-easy-way/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 19:38:05 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[*NIX]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[*nix]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.belchak.com/?p=16</guid>
		<description><![CDATA[Ever have this problem? You just rebuilt a machine, and when you go to SSH into it, you get the following message: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Many people just go edit their ~/.ssh/known_hosts file and carry on. But there is [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Ever have this problem? You just rebuilt a machine, and when you go to SSH into it, you get the following message:</p>
<pre>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!</pre>
<p>Many people just go edit their <code>~/.ssh/known_hosts</code> file and carry on. But there is a faster/better way!</p>
<p>OpenSSH comes with a command called <code>ssh-keygen</code> that allows you to generate and manage all your keys, including your ssh fingerprints.</p>
<p>Simple usage for this would be:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-R</span> HOSTNAME</pre></td></tr></table></div>

<div class="shr-publisher-16"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.belchak.com/2011/01/27/removing-old-ssh-fingerprints-from-your-known_hosts-the-quick-and-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

