Skip to content

Instantly share code, notes, and snippets.

def combs(array, n)
if array.length < n
[]
elsif n == 0
[[]]
else
(combs(array[1..-1], n-1).map{|comb| [array[0]] + comb} +
combs(array[1..-1], n))
end
end

Practice for Job Fair / Thanksgiving

This is the last job prep day before two important interrogative events: a job fair December 5th, and American Thanksgiving, November 28. We're going to practice responding to questions in pairs. Explicitly state who you are before starting to ask questions - you'd say different things to your uncle over mashed potatoes than you would to an engineer at the job fair from Etsy.

We'll also share solutions to interview questions / programming problems we're finding tough - I want to check in with some people on recursion in particular.

Here's a script to choose questions from:

  • What's Hacker School? (Try telling this to a skeptical interviewer - it's not your job to defend Hacker School! Just to tell your story)
  • What language did they teach you there?
import poplib
USERNAME = 'mailclientdemo@gmail.com'
PASSWORD = 'nevergraduate'
M = poplib.POP3_SSL('pop.gmail.com')
M.user(USERNAME)
M.pass_(PASSWORD)
numMessages = len(M.list()[1])
for i in range(numMessages):
google_homepage = lambda: [
globals().__setitem__('s', __import__('socket').socket()),
globals()['s'].connect(('www.google.com', 80)),
globals()['s'].send('GET /\r\n\r\n'),
''.join(globals()['s'].recv(1000000) for _ in range(100))
][-1]
print google_homepage()
@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 = []
#!/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'
# This is a standard python config file
# Valid values can be True, False, integer numbers, strings
# By default bpython will look for ~/.config/bpython/config or you
# can specify a file with the --config option on the command line
# General section tag
[general]
# Display the autocomplete list as you type (default: True).
# When this is off, you can hit tab to see the suggestions.
@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
@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: