<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Brian Hicks</title>
 <link href="http://brianhicks.github.com/atom.xml" rel="self"/>
 <link href="http://brianhicks.github.com"/>
 <updated>2014-10-13T19:26:24+00:00</updated>
 <id>http://brianhicks.github.com</id>
 <author>
   <name>Brian Hicks</name>
   <email>brian@brianthicks.com</email>
 </author>

 
 <entry>
   <title>STL Python: Class Complete</title>
   <link href="http://brianhicks.github.com/development/2014/03/20/stl-python-class-complete"/>
   <updated>2014-03-20T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/development/2014/03/20/stl-python-class-complete</id>
   <content type="html">
&lt;p&gt;&lt;a href=&quot;http://meetup.com/stl-python&quot;&gt;STL Python&lt;/a&gt; has just finished it’s inaugural programming class: Intro to Programming with Python. With slightly more than a full class, I’d call it a success.&lt;/p&gt;

&lt;h2 id=&quot;why-offer-a-class-in-the-first-place&quot;&gt;Why offer a class in the first place?&lt;/h2&gt;

&lt;p&gt;As a whole, I think programming is an interesting career, and I’ve found enjoyment and employment there. But in a bigger picture, it’s a &lt;em&gt;great&lt;/em&gt; “secret weapon” in a non-tech field. Case in point, we had researchers from Washington University join the class because they needed to learn how to program in order to further their own research.&lt;/p&gt;

&lt;p&gt;There is a bigger reason to teach programming: tech is monocultural. Diversity of thought and opinion will make stronger people that do more good in their communities. (And as an aside, maybe we can stop making products that &lt;em&gt;only&lt;/em&gt; rich white guys will ever want and start doing some stuff that to the benefit of people outside the tech scene.) By teaching people outside our sphere how to program we’re not only increasing their economic opportunity but our own chances of survival. There are a lot of thoughts and organizations working on this: &lt;a href=&quot;http://adainitiative.org/faq/#why-focus-on-women-in-open-technology-and-culture&quot;&gt;The Ada Initiative’s FAQ&lt;/a&gt;, &lt;a href=&quot;http://www.ashedryden.com/&quot;&gt;Ashe Dryden’s Blog&lt;/a&gt;, &lt;a href=&quot;http://railsgirls.com/&quot;&gt;Rails Girls&lt;/a&gt;, and &lt;a href=&quot;http://colorlines.com/archives/2013/10/where_are_people_of_color_in_nycs_silicon_alley.html&quot;&gt;this article on Color Lines&lt;/a&gt; are a few good places to look if you’re interested in learning more about tech’s diversity problem.&lt;/p&gt;

&lt;p&gt;It would also show lack of care on my part to not mention that Tony Becker (my co-teacher for this class) has also published &lt;a href=&quot;http://fortpedro.com/2014/01/why-learn-to-code/&quot;&gt;some thoughts on this&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;hitting-the-ground-running&quot;&gt;Hitting the ground running&lt;/h2&gt;

&lt;p&gt;Tony approached me about co-teaching a introductory programming class early in 2014. I’ve wanted a class for St. Louis for a long time, but never had the gumption to do alone. We started planning out our curriculum right away. We chose &lt;a href=&quot;http://www.greenteapress.com/thinkpython/&quot;&gt;&lt;em&gt;How to Think Like a Computer Scientist&lt;/em&gt; by Allen B. Downey&lt;/a&gt; to teach the course with since it is written for beginner computer science students. We considered a number of ways to get Python installed on students’ computers and ended up settling on &lt;a href=&quot;https://store.continuum.io/cshop/anaconda/&quot;&gt;Anaconda Scientific Python Distribution&lt;/a&gt; which turned out to be a great option (although nothing is without it’s problems, as we’ll see later.)&lt;/p&gt;

&lt;p&gt;We also made a deal with &lt;a href=&quot;http://nebulastl.com/&quot;&gt;Nebula&lt;/a&gt;, a coworking space on Jefferson Street, to use their conference room. I’ve got to give Tony all the credit on this one: he hoofed it around town to find the best meeting place for our class and did the hard work of negotiating agreements, plus food for every week. Hats off!&lt;/p&gt;

&lt;p&gt;Once we had secured the space and time, we made a launch announcement on @STLPython and our personal Twitter accounts. Several high profile accounts retweeted and shared our message all over the internet, and within three days we had our initial slate of 40 students filled. I thought we would maybe get half of our cap, but apparently there are an enormous amount of people looking to learn to code. I’m still getting emails at least once a week asking how to join or when the next class starts.&lt;/p&gt;

&lt;h2 id=&quot;the-class&quot;&gt;The Class&lt;/h2&gt;

&lt;p&gt;We went into this knowing that our ideas were not going to be all good. Unsurprisingly, not all of them were! &lt;/p&gt;

&lt;h3 id=&quot;what-worked&quot;&gt;What worked&lt;/h3&gt;

&lt;p&gt;Anaconda was a major win. We asked people to download the software before class, then simply distributed a couple of USB sticks around the classroom the first night and we were finished in 15 minutes. Everyone had the same environment and tools. Easy!&lt;/p&gt;

&lt;p&gt;The thought behind &lt;a href=&quot;http://www.lighttable.com&quot;&gt;Light Table&lt;/a&gt; as a next-generation IDE means that it works great as a teaching tool. Define something, hit &lt;code&gt;cmd+enter&lt;/code&gt;, and  see the output right there next to your code. I cranked the font size up so everyone could see, and it suddenly became a giant interactive chalkboard.&lt;/p&gt;

&lt;p&gt;Nebula is a great space for a large(ish) group to meet. Jason (the owner) and everyone there were friendly and welcoming, and even agreed to host a regular STL Python meeting while T-REX was moving.&lt;/p&gt;

&lt;h3 id=&quot;what-was-not-so-great&quot;&gt;What was not so great&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;How to Think Like a Computer Scientist&lt;/em&gt; turned out to make some assumptions about our students that weren’t valid. Specifically, it assumes that students come from a strong mathematics background, which almost none of our class (including me) had. As an example, one of the exercises had students implementing &lt;a href=&quot;https://en.wikipedia.org/wiki/Fermat&#39;s_Last_Theorem&quot;&gt;Fermat’s Last Theorem&lt;/a&gt;. It was difficult to teach that and then have to explain to my students that yes, their code did in fact work, but there were no known inputs to get it to do that branch of the conditional. Not a great demonstration of conditionals, which the exercise taught. In addition, there were a number of times when the authors taught an older or obscure way to approach a problem and then in a footnote said something along the lines of “it’s much simpler if you just do it like this” which nearly always turned out to be the way real world code (the goal) would implement the feature.&lt;/p&gt;

&lt;p&gt;We tried to set up Google Hangouts for office hours, thinking that the Hangouts On-Air would work and that people would be able to stream it even if they couldn’t join the call. It turns out that office hours need to be much more interactive because beginner students require a tight feedback loop (or at least, tighter than Hangouts On-Air can provide.) We ditched that in favor of &lt;a href=&quot;https://www.fuzebox.com/&quot;&gt;Fuzebox&lt;/a&gt; which worked a little better.&lt;/p&gt;

&lt;h2 id=&quot;for-next-time&quot;&gt;For next time&lt;/h2&gt;

&lt;p&gt;This seemed to be a great experience for everyone who participated. We ended up with about 25% of the people we started out with, but most of those who dropped out emailed us to say “it’s not you, I have other commitments on my time and can’t finish the course.”&lt;/p&gt;

&lt;p&gt;For the next class, we’ll be making a few changes. First, we’ll be trying to find a new textbook. &lt;em&gt;How to Think&lt;/em&gt; is a good textbook for introductory CS students, but it’s not too great for what we’re doing and some of the examples and code samples are a little dated. In addition, we want to be teaching our students “real world” Python. &lt;em&gt;How to Think&lt;/em&gt; alludes a little bit to the idea of something idiomatic Python but didn’t define the concept to our satisfaction. If we can’t find one we’ll write our own (but we’d much prefer to use an established book. If you know of any, &lt;strong&gt;please&lt;/strong&gt; drop me a line.) This is intended to be more of a reference material, because…&lt;/p&gt;

&lt;p&gt;Second, I’d like to try different kinds of assignments. Practical application of Python being a core tenet of the course it seems necessary to do similar things to what you’d create in real life. Or at least, things the students find interest in doing. The last night of class we did a group exercise on &lt;a href=&quot;https://gist.github.com/BrianHicks/9655533&quot;&gt;Markov Chains&lt;/a&gt; which everyone in the class got a laugh out of (we used &lt;em&gt;The Adventures of Sherlock Holmes&lt;/em&gt; as source text.) Things like that will probably play a more central role in future versions of the course.&lt;/p&gt;

&lt;p&gt;And lastly, we intended the in-class sessions to be Q&amp;amp;A about the material covered during independent study. That turned out to be an OK fit but throwing someone into a new field and expecting them to ask good questions in a group setting is maybe a little daunting for the learner. We will be carefully considering our course format, and maybe making a few changes there.&lt;/p&gt;

&lt;p&gt;To finish up, if you were in the class: thank you for coming. I learned as much from you as (I hope) you did from me and Tony. And of course &lt;em&gt;tons&lt;/em&gt; of thanks to Tony, who did so much of the administration for this class. We’ll see you again soon!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Temptation of Pypy</title>
   <link href="http://brianhicks.github.com/2013/09/24/temptation-of-pypy"/>
   <updated>2013-09-24T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/2013/09/24/temptation-of-pypy</id>
   <content type="html">&lt;p&gt;So last week I attended &lt;a href=&quot;https://thestrangeloop.com/&quot;&gt;Strangeloop&lt;/a&gt; (which was
excellent, by the way, and you should go if you ever have the slightest
chance.) I had a couple conversations with people about performance and JIT
compilers and stuff like that, and right now I’m really tempted to try out
Pypy. The target project which I’m thinking about has the following properties:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Mostly Python (i.e. few C extensions)&lt;/li&gt;
  &lt;li&gt;Needs to be &lt;em&gt;fast&lt;/em&gt;. (last week NewRelic measured it at 11.9ms response time)&lt;/li&gt;
  &lt;li&gt;Calls the same methods over and over with the same types.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;BUT, it also has this going on:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The DB persistence is pymongo/hiredis (the only two C extensions here)&lt;/li&gt;
  &lt;li&gt;Those few methods are called with complex types (specifically, Django’s
request objects.) I’ve heard this can be a problem for JIT compilers, and if
it is I don’t know that we’ll fully realize the speed gains.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I’m torn, and that’s why I’m putting it up here: can anyone with experience
running Pypy in production shed some light on these concerns, or am I going to
have to just try it and measure performance?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Post Script</title>
   <link href="http://brianhicks.github.com/2013/09/03/post-script"/>
   <updated>2013-09-03T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/2013/09/03/post-script</id>
   <content type="html">&lt;p&gt;After reading &lt;a href=&quot;http://www.hanselman.com/blog/DoTheyDeserveTheGiftOfYourKeystrokes.aspx&quot;&gt;this Scott Hanselman post on
keystrokes&lt;/a&gt;
I’ve realized that while I’ve tweeted quite a bit in the past couple of years
I’ve hardly ever blogged, when that would be much more useful (not to mention
sustainable.)&lt;/p&gt;

&lt;p&gt;So, here’s a little script wrapper for posting &lt;em&gt;quickly&lt;/em&gt; to a Jekyll blog
hosted on your filesystem.&lt;/p&gt;

&lt;p&gt;Aliases are helpful to use this - I have this particular blog aliased as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;alias blog=&quot;post ~/code/sideprojects/brianhicks.github.com/_posts -c -p &#39;git push&#39;&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then I can just &lt;code&gt;blog &quot;Post Script&quot;&lt;/code&gt; to generate some boilerplate for this
post, for instance. When I save and quit vim, it’ll get pushed to GitHub pages
automatically.&lt;/p&gt;

&lt;p&gt;Hopefully I can remember to “post more in the future” although that’s an empty
promise of many a personal tech blog.&lt;/p&gt;

&lt;p&gt;Without further ado, the wrapper (the irony of this being written in Python is
not lost on me, for the record):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env python
&quot;Wrapper for posting to a Jekyll blog from the command line&quot;
import argparse
from datetime import datetime, timedelta
import operator
import os
import re
from subprocess import call

parser = argparse.ArgumentParser(__doc__)

parser.add_argument(
    &#39;where&#39;,
    help=&#39;Which directory to post to&#39;
)
parser.add_argument(&#39;title&#39;, help=&#39;Title of the post&#39;)
parser.add_argument(
    &#39;-d&#39;, &#39;--date&#39;,
    default=datetime.now().strftime(&#39;%Y-%m-%d&#39;),
    help=&#39;Date the post should be published (ex: 2013-06-19)&#39;,
)
parser.add_argument(
    &#39;-o&#39;, &#39;--offset&#39;,
    help=&#39;Days to offset post by, based on latest post (ex: +2 or -5)&#39;,
)
parser.add_argument(
    &#39;-n&#39;, &#39;--offset-now&#39;,
    action=&#39;store_true&#39;,
    help=&#39;If present, offset from current date instead of last post&#39;
)
parser.add_argument(
    &#39;-c&#39;, &#39;--commit-after&#39;,
    action=&#39;store_true&#39;,
    help=&#39;If present, add and commit to git afterward&#39;
)
parser.add_argument(
    &#39;-p&#39;, &#39;--post&#39;,
    help=&#39;Extra command to run after hook, if committed&#39;
)

if __name__ == &#39;__main__&#39;:
    args = parser.parse_args()

    # transform the parsed arguments
    slug = re.sub(&#39;[^\w-]&#39;, &#39;&#39;, re.sub(&#39;\s+&#39;, &#39;-&#39;, args.title).lower())

    date = args.date

    # do relative posting dates, from the latest post. Override date if provided.
    if args.offset:
        if args.offset_now:
            base = datetime.now()
        else:
            latest = sorted([x.split(&#39;-&#39;) for x in os.listdir(args.where)], reverse=True)[0]
            base = datetime(int(latest[0]), int(latest[1]), int(latest[2]))

        op = operator.sub if args.offset.startswith(&#39;-&#39;) else operator.add

        date = datetime.strftime(op(base, timedelta(int(args.offset[1:]))), &#39;%Y-%m-%d&#39;)

    title = &#39;%s-%s.md&#39; % (date, slug)
    filename = os.path.expanduser(os.path.join(args.where, title))

    text = &quot;---\ntitle: %s\ndate: %s\nlayout: default\n---&quot; % (args.title, date)

    if not os.path.exists(filename):
        with open(filename, &#39;w&#39;) as post:
            post.write(text)

    call([os.environ.get(&#39;EDITOR&#39;, &#39;/usr/local/bin/vim&#39;), filename])
    if args.commit_after:
        os.chdir(args.where)
        call([&#39;git&#39;, &#39;add&#39;, title])
        call([&#39;git&#39;, &#39;commit&#39;, &#39;-m&#39;, &#39;Add %s&#39; % title])

        if args.post:
            os.chdir(os.path.abspath(
                os.path.join(args.where, &#39;..&#39;) if &#39;_posts&#39; in args.where else args.where
            ))
            call(args.post.split())
&lt;/code&gt;&lt;/pre&gt;
</content>
 </entry>
 
 <entry>
   <title>Graph Task Dependencies with Python</title>
   <link href="http://brianhicks.github.com/development/2012/05/29/graph-task-dependencies-with-python"/>
   <updated>2012-05-29T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/development/2012/05/29/graph-task-dependencies-with-python</id>
   <content type="html">
&lt;p&gt;I’ve finished a little script for graphing taskwarrior dependencies with
GraphViz and Python. Have fun with it.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/2769821.js&quot;&gt;&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>Notes</title>
   <link href="http://brianhicks.github.com/meta/2012/05/02/notes"/>
   <updated>2012-05-02T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/meta/2012/05/02/notes</id>
   <content type="html">
&lt;p&gt;I’m taking the Coursera machine learning course, and I will be taking notes and
putting them up here. Access them at the notes section in the navigation.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>javascript dates</title>
   <link href="http://brianhicks.github.com/development/2012/03/19/javascript-dates"/>
   <updated>2012-03-19T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/development/2012/03/19/javascript-dates</id>
   <content type="html">
&lt;p&gt;I’ve just spent half an hour wrestling with this, and for the benefit of
those to come…&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2011&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;08&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Will produce a new datetime object, right? No biggie, if you look inspect it,
it displays like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Thu Dec 08 2011 11:33:05 GMT-0600 (CST)&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But lo, the beast lurks. calling &lt;code&gt;getFullYear&lt;/code&gt; and &lt;code&gt;getDate&lt;/code&gt; work fine,
and return &lt;code&gt;2011&lt;/code&gt; and &lt;code&gt;8&lt;/code&gt;, respectively. But &lt;code&gt;getMonth&lt;/code&gt; is a bit
different. See, the &lt;code&gt;Date&lt;/code&gt; object thinks of January as month 0, February
as month 1, etc. So converting from one date to another (to get the
first of the month at midnight, for example) would be done like this in
Python:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
   &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;month&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;year&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;month&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But has to be done like this in Javascript:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
   &lt;span class=&quot;nx&quot;&gt;month&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getYear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getMonth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Yes, I know that methods like &lt;code&gt;setDate&lt;/code&gt; exist, but constructing a new
object with only what I need seems more efficient.&lt;/p&gt;

&lt;p&gt;By the way, here’s the way that &lt;a href=&quot;http://www.mongodb.org/&quot;&gt;MongoDB&lt;/a&gt; deals
with this in their &lt;code&gt;ISODate&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;year&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1970&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;month&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</content>
 </entry>
 
 <entry>
   <title>Django test settings</title>
   <link href="http://brianhicks.github.com/development/2012/03/19/django-test-settings"/>
   <updated>2012-03-19T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/development/2012/03/19/django-test-settings</id>
   <content type="html">
&lt;p&gt;Recently I was setting up &lt;a href=&quot;http://sentry.readthedocs.org/&quot;&gt;Sentry logging&lt;/a&gt; for an app I was working on, and
needed to turn it off for tests, as it was sending logs to a remote
server. Here’s how I ended up doing that:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;LOGGING&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&amp;#39;version&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&amp;#39;disable_existing_loggers&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&amp;#39;root&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&amp;#39;level&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;WARNING&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&amp;#39;handlers&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;sentry&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# ... snip formatters ...&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&amp;#39;handlers&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&amp;#39;sentry&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;level&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;DEBUG&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;class&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;raven.contrib.django.handlers.SentryHandler&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;formatter&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;verbose&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&amp;#39;console&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;level&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;DEBUG&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;class&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;logging.StreamHandler&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;#39;formatter&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;verbose&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# ... snip loggers ...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;test&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# redirect default errors to NullHandler&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;LOGGING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;root&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;handlers&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;console&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;LOGGING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;handlers&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;console&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;class&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;logging.NullHandler&amp;#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now I don’t get logging messages in my test output when tests pass, and
the tests don’t spam the logging server with messages.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>dict syntax</title>
   <link href="http://brianhicks.github.com/development/2012/03/19/dict-syntax"/>
   <updated>2012-03-19T00:00:00+00:00</updated>
   <id>hhttp://brianhicks.github.com/development/2012/03/19/dict-syntax</id>
   <content type="html">
&lt;p&gt;I just found out something neat about Python’s &lt;code&gt;dict&lt;/code&gt; syntax. First of
all, of course this works:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;But you can also stick dictionaries in there as the first argument. Go
ahead, try it:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d2&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It’s as if you called &lt;code&gt;update&lt;/code&gt; on the dictionary. Neato, eh? It’s
especially useful in &lt;a href=&quot;http://merciless.sourceforge.net/tour.html#specifying-a-migration&quot; title=&quot;Specifying a migration&quot;&gt;ming migrations&lt;/a&gt;.&lt;/p&gt;

</content>
 </entry>
 
 
</feed>