Skip to content

Instantly share code, notes, and snippets.

@bgschiller
bgschiller / README.md
Last active July 12, 2017 15:32
Rectilinear Steiner Trees
from collections import namedtuple, Counter
import heapq
from pprint import pprint
from operator import attrgetter
import struct
Tree = namedtuple('Tree', 'weight left right')
Letter = namedtuple('Letter', 'weight char')
get_weight = attrgetter('weight') # same as def get_weight(o): return o.weight

Install postgresql

(The best SQL database)

Mac:

Best bet is to use http://postgresapp.com/ .

Make sure to set up your path once it's installed:

  1. Run atom ~/.bash_profile.
@bgschiller
bgschiller / cows_and_bulls.md
Last active November 22, 2016 01:11
Cows and Bulls exercise

Cows and Bulls

Create a program that will play the “cows and bulls” game with the user. The game works like this:

Randomly generate a 4-digit number. Ask the user to guess a 4-digit number. For every digit that the user guessed correctly in the correct place, they have a “cow”. For every digit the user guessed correctly in the wrong place is a “bull.” Every time the user makes a guess, tell them how many “cows” and “bulls” they have. Once the user guesses the correct number, the game is over. Keep track of the number of guesses the user makes throughout the game and tell the user at the end.

Say the number generated by the computer is 1038. An example interaction could look like this:

Welcome to the Cows and Bulls Game! 

Enter a number:

@bgschiller
bgschiller / index.html
Last active March 22, 2016 19:28
interactiveGuideline issue with nvd3
<head>
<link rel="stylesheet" href="https://rawgit.com/novus/nvd3/05cfaafa872ec8f941f7349bcf83fc7d344db857/build/nv.d3.min.css">
</head>
<body>
<svg class="chart-target"></svg>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/novus/nvd3/05cfaafa872ec8f941f7349bcf83fc7d344db857/build/nv.d3.min.js"></script>
<script type="text/javascript">
var data = [
{"data_key":"historical_entered_pipe","historical":true,"key":"Historical Entered Pipe","color":"#ff0000","values":[{"y":356447,"x":90},{"y":318113,"x":89},{"y":318113,"x":88},{"y":318113,"x":87},{"y":318113,"x":86},{"y":318113,"x":85},{"y":318113,"x":84},{"y":289780,"x":83},{"y":289580,"x":82},{"y":288347,"x":81},{"y":288347,"x":80},{"y":288347,"x":79},{"y":288347,"x":78},{"y":288347,"x":77},{"y":288347,"x":76},{"y":238347,"x":75},{"y":238347,"x":74},{"y":238347,"x":73},{"y":230013,"x":72},{"y":230013,"x":71},{"y":230013,"x":70},{"y":2300
@bgschiller
bgschiller / keybase.md
Created February 8, 2016 15:26
Verifying myself on keybase

Keybase proof

I hereby claim:

  • I am bgschiller on github.
  • I am bgschiller (https://keybase.io/bgschiller) on keybase.
  • I have a public key ASAX_KmZ-zLBMZUuVoVkT19ronpk7I-jxQ6_fbjQNO9NYwo

To claim this, I am signing this object:

@bgschiller
bgschiller / index.html
Last active August 29, 2015 14:13
Draw square spirals with a bit of noise all over the page
<head>
<style>
body {
background-color: #DFDECC;
}
svg path.walk {
fill: none;
stroke: #4b4b4b;
stroke-width:1.3;
}
@bgschiller
bgschiller / undecidable_club.md
Created October 28, 2014 01:55
The Undecidable Club

There is a club called Undecidable, but they don't let in just any old question. In order to be admitted to the Undecidable Club, a question has to prove that she's seriously hard. How hard? Well, let's talk about the membership process.

First, the applicant needs a sponsor (Let's call the sponsor S). Your sponsor is some question who's already in the club (so you know they're hard). In order to get into the club, an applicant has to show she's just as hard as her sponsor (Let's call the applicant A). How does A prove her difficulty? She has to show that if some Turing Machine could solve A's problem, it could solve S's problem as well. Since we know S is hard (he's in the club already!), A's problem must be just as hard.

Membership Roster

These problems are all known to be hard. You can choose whichever you like to be your sponsor.

  • function AcceptsOwnEncoding(T)
  • function AcceptsSomething(T)
@bgschiller
bgschiller / index.html
Created August 23, 2014 20:03
Grandpa's Dow Jones moving average graph
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {