Skip to content

Instantly share code, notes, and snippets.

View thomasballinger's full-sized avatar

Tom Ballinger thomasballinger

View GitHub Profile
@thomasballinger
thomasballinger / gist:7555675
Created November 20, 2013 01:00
txws, websockets, classmethods vs staticmethods,
from twisted.python import log
from sys import stdout
log.startLogging(stdout)
from twisted.internet.protocol import Protocol, Factory
VisualizerClient.update_everybody()
class VisualizerClient(object):
clients = []
@thomasballinger
thomasballinger / gist:7522081
Created November 18, 2013 03:39
Three ways to wrap text
>>> wrap('hello there', 5)
['hello',
'there']
>>> wrap('home is where the heartwrenching angst is', 10)
['home is',
'where a',
'heartwrenc', #1
'hing',
@thomasballinger
thomasballinger / gist:7493494
Created November 15, 2013 23:30
Named pipes!
mkfifo inpipe
mkfifo outpipe
$ python ai.py < inpipe > outpipe &; node client.js < outpipe > inpipe
#!/usr/bin/env python
import sys
import urllib2
import json
def do_gist_json(s):
""" Use json to post to github. """
gist_public = False
gist_url = 'https://api.github.com/gists'
@thomasballinger
thomasballinger / opt.py
Created November 11, 2013 18:08
Pastebin helper for Online Python Tutor
#!/usr/bin/env python
import sys
import urllib
import webbrowser
def get_opt_url(s, from_bpython=True):
""" Use json to post to github. """
if from_bpython:
require 'rspec'
require 'forwardable'
require 'pry'
require 'set'
class ListyThing
extend Forwardable
def_delegators :@data, :<<, :empty?, :concat
def initialize
@data = []

Let's build a Bitly Clone!

Bitly is a url shortening service. Building a url shortener is a common interview question / take home project, because it's a minimal project that involves many aspects of web development. Build a website that allows you to submit a link, then gives you a new, hopefully shorter url to use for that link.

Advice and motivation

Typically at Hacker School understanding is emphasized over ability to throw things together - this is an exercise in the latter. It's also practice reading documentation to figure out how to do things quickly, and a guided way to gain exposure to web development concepts that you might research more after this sprint today. It reminds me (in good and bad ways) of a hackathon.

autoload compinit
compinit
autoload bashcompinit
bashcompinit
complete -C 'tu --get-bash-completion' tu
@thomasballinger
thomasballinger / genetic.py
Last active December 26, 2015 12:09
some TSM genetic algo stuff - crappy mate function currently
import random
import bisect
import math
from matplotlib import pyplot
def points(n):
return [(random.random(), random.random()) for _ in range(n)]
def random_path(n):

Recursion day

Talk to other people - this didn't happen enough last week! Many people are already good at using recursion, and but would still learn something by working through problems with you. Consider describing your strategy before actually implementing it. Try doing this on a whiteboard.

Some resource to come back to later:

  • The little schemer - a mindbending intro to programming and recursion
  • SICP section 1.2 - you might need to read 1.1 to get up to speed
  • Add some more! Is there a MOOC you really like the recursion section of, or a textbook that gives it a nice treatment? Add it on Zulip and I'll add it here.