Skip to content

Instantly share code, notes, and snippets.

==========================================

fmtstr annotates portions of strings with terminal colors and formatting str(yourstring) will be the string with [ANSI escape codes] (http://en.wikipedia.org/wiki/ANSI_escape_code) specifying color and other formatting to a terminal.

fmtstr.FmtStr

@thomasballinger
thomasballinger / gist:6979684
Created October 14, 2013 18:13
blackjack chart parsing
s = open('chart.txt')
s = s.read()
s
# OUT: ' Dealer\xe2\x80\x99s Up Card\nYour\nHand 2 3 4 5 6 7 8 9 10 A\n8 H H H H H H H H H H\n9 H D D D D H
# OUT: H H H H\n10 D D D D D D D D H H\n11 D D D D D D D D D H\n12 H H S S S H H H H H\n13
# OUT: S S S S S H H H H H\n14 S S S S S H H H H H\n15 S S S S S H H H H H\n16 S S S S S H
# OUT: H H H H\n17 S S S S S S S S S S\n \nA,2 H H H D D H H H H H\nA,3 H H H D D H H H H H\nA,4
# OUT: H H D D D H H H H H\nA,5 H H D D D H H H H H\nA,6 H D D D D H H H H H\nA,7 S D D D D S
# OUT: S H H H\nA,8 S S S S S S S S S S\nA,9 S S S S S S S S S S\n\nA,A P P P P P P P P P

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.
@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):
autoload compinit
compinit
autoload bashcompinit
bashcompinit
complete -C 'tu --get-bash-completion' tu

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.

require 'rspec'
require 'forwardable'
require 'pry'
require 'set'
class ListyThing
extend Forwardable
def_delegators :@data, :<<, :empty?, :concat
def initialize
@data = []
@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:
#!/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 / gist:7493494
Created November 15, 2013 23:30
Named pipes!
mkfifo inpipe
mkfifo outpipe
$ python ai.py < inpipe > outpipe &; node client.js < outpipe > inpipe