Tag Archives: programming

Some notes from PyGotham (corrections welcome)

Getting Rich with Comparison Methods 

Matt Story

the truth of x == y does not imply that x != y is false […] Mind == blown and mind != blown.

pro tip: when defining ‘__eq__’ also define ‘__ne__’ its reflection method

operators like ‘<‘ have reflection properties to handle ‘>’ when overridden
right-side reflection for left-side method

how much of life is wasted by not reading documentation first?

keep-calm-and-rtfm

python has a NotImplemented error. singleton constant

MRO –> method resolution order –> use the more specific class’s methods, regardless on which side of comparison
this is the reason to use mix-ins as opposed to normal inheritance

test ALL the things
import operator module to test all the cases for bitwise and arithmetic operators

eq, ne, lt, le, gt, ge – check for existence, return the thing or NotImplemented

@functools.total_ordering – may drastically reduce the code

comparison methods are well documented. fairly robust methodology to learn which method to use on right/left side. complex so need to test.

comparison methods do not need to return bools, so you can do whatever you want. harness asymmetrical and non-boolean comparisons… useful for lazy-loaded filtering, iteration

Continue reading

100 Days later

How to Git good

TL;DR: To get better at something, practice. To form a habit, commit to do it often.

This is a story about challenging myself to get into a good habit.  About a hundred days and a week ago, I started Hacker School.  The first day there, I learned how to use GitHub.  That same day I decided to commit to committing, as part of my quest to become a drastically better programmer.

A week later, I realized that I messed up my streak, by forgetting to commit over the weekend. Doh!

Continue reading

How to train your neural network using a genetic algorithm

Artificial neural networks can be used to solve a wide variety of tasks that are hard to solve using rule-based programming. A genetic algorithm (GA) is a search technique used in computing to find exact or approximate solutions to optimization and search problems.

xkcd: Genetic Algorithms

xkcd: Genetic Algorithms

Working with rgho to basically implement what’s described in the following paper for our project babelbrain: a machine learning algorithm to classify language of a given input.

Continue reading

Survival Guide for a Hackathon, Part: the Second

During the fourth annual TimesOpen Hack Day, hosted at the NYTimes, my team developed an application called SayWhat.

Sunlight Foundation

The main goal of SayWhat was to take advantage of the illuminating work done by the Sunlight Foundation, a nonpartisan nonprofit promoting government transparency. Sunlight harnesses the power of the internet, using technology to encourage democratic participation by creating tools and connections to open data through their APIs, so that anyone can access vital government information. Call to action of the Sunlight Foundation:

[…] we know that as government grows ever-more complex, we will all need better tools to navigate it to ensure democracy thrives. Get involved in helping us open up government, one data set at a time.

SayWhat

SayWhat is my first attempt to get involved with government data. Teaming up with 3 other attendees at the hack day, we formed a team named “Python Super PAC.” We sought a way to analyze government bills measuring various metrics of relevance, complexity and transparency. It’s a work-in-progress, but the code is up on GitHub.

Continue reading

Survival Guide for a Hackathon, Part: the First

Thinking about joining a hackathon but aren’t sure where to start?

Hackathon participation sounds awesome. But…it can also feel intimidating. Much of the ritual appears to be tribal knowledge among its veterans.  So how are newcomers able to get involved and benefit the most from their experience?

The trick is to just go: have a great time hacking, making friends and learning!

I participated (and won a prize!) in my first hackathon yesterday.  By reflecting on my experience, I’m hoping to demystify the process and provide some encouragement for other hackathon newbies.

definition of a hackathon

Continue reading

How hackers learn… (for fun_and_profit in life):

Perhaps the most interesting thing I learned so far in Hacker School is that you should design learning like you design code.  This was inspired by a presentation that Mel Chua gave to our batch.  It’s a very powerful idea that I feel is worth exploring, analyzing and sharing.

In this post, I will attempt to cover how and why programmers learn, how they design code and why everyone could benefit from adopting the “design to learn” model.

Why developers learn:

In The Dark Knight, the Joker said, “If you’re good at something, never do it for free”.  Programming can be a very profitable career choice.  So it’s safe to say that some developers do it for the $money.  They understand the supply-demand curve of market economics.  To most people, computers are highly useful magic black-boxes of awesomeness, so those who wield the power to create and control them are wizards.  Mastering a language, technology stack or project implementation yields great rewards when those skills solve real-world problems.  Just imagine how much XYZ Company will pay for a level-60 Java wizard!

  1. Learn to code
  2. Profit

But what about software engineers who aren’t in it for the money? Their motivation is probably a bit more interesting and complex.  For some, it is the autonomy and creativity of creating novel code.  Or maybe it’s the competence felt when basking in the praise of technophobes whose desktops always need rescuing (Mom, I promise I’ll fix your Internet as soon as I get some free time).

Continue reading

There is no such thing as a best solution, be it a tool, a language, or an operating system. There can only be systems that are more appropriate in a particular set of circumstances.