Skip to content

Instantly share code, notes, and snippets.

View apendleton's full-sized avatar

Andrew Pendleton apendleton

  • Mapbox
  • Washington, DC
View GitHub Profile
@apendleton
apendleton / gabon_test.py
Created August 24, 2015 17:56
Link grabbing example
# first you need to make sure you have the libraries installed; I'm using pyquery and requests:
# pip install pyquery requests
import requests
from pyquery import PyQuery as pq
from urlparse import urljoin
URL = "http://www.stat-gabon.org/"
response = requests.get(URL)
void setup() {
pinMode (2,OUTPUT);//attach pin 2 to vcc
pinMode (5,OUTPUT);//attach pin 5 to GND
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
digitalWrite(2, HIGH);
var ocemail = function(url, domain) {
var capitalize = function(s) { return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(); }
// url parser from http://jsperf.com/url-parsing
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var hostname = urlParseRE.exec(url)[11];
if (hostname) {
var domainMatch = /^(?:www[.])?([-a-z0-9]+)[.](house|senate)[.]gov$/;
var match = domainMatch.exec(hostname.toLowerCase());
use std::num::pow;
pub struct Point { x: int, y: int }
struct Line { p1: Point, p2: Point }
impl Line {
pub fn length(&self) -> f64 {
let xdiff = self.p1.x - self.p2.x;
let ydiff = self.p1.y - self.p2.y;
((pow(xdiff, 2) + pow(ydiff, 2)) as f64).sqrt()
@apendleton
apendleton / cherry_almond_fudge.md
Created May 11, 2014 19:29
Cherry-almond fudge

Cherry-almond Fudge

Adapted from Cook's Illustrated 15-minute walnut fudge.

Ingredients

  • 16oz bittersweet chocolate (I use Ghirardelli 60% bittersweet bars)
  • 2oz unsweetened chocolate (again, I use Ghirardelli, 100% bars)
  • 1 can sweetened condensed milk (whole)
@apendleton
apendleton / baked_steelcut_oatmeal.md
Created May 11, 2014 19:19
Baked steel-cut oatmeal

Baked steel-cut oatmeal

This is kind of inspired by this recipe. Amounts are what I did, but if I do it again I might slightly decrease the nutmeg and maybe slightly increase the sugar.

Ingredients

  • 1.5 cups steel cut oatmeal
  • 2.5 cups boiling water
  • 2tsp baking powder
import csv, re
SEARCH_TERMS = [re.compile(term, re.I) for term in [r"(?<!white )house", "HFAC", "Congressman", "Congresswoman", "Congressional", "Senate", "Senator"]]
SEARCH_COLS = ["contact_title", "contact_name", "contact_office", "contact_agency"]
csv_infile = open('contacts.csv', 'rb')
csv_in = csv.DictReader(csv_infile)
csv_outfile = open('contacts_filtered.csv', 'wb')
csv_out = csv.DictWriter(csv_outfile, csv_in.fieldnames)
@apendleton
apendleton / curried_pear_pie.md
Last active August 29, 2015 13:57
Curried pear pie

Curried Pear Pie

Ingredients

Note: these are amounts for a nine-inch round pie. For the 13x9 rectangular pie, I used a double batch of filling and a 1.5x batch of crust.

  • One batch pie crust for a double crust pie (I'm a fan of this one)
  • 1/2 cup golden raisins
  • 2Tbsp garlic-ginger paste (recipe follows)
  • 1Tbsp ground coriander
@apendleton
apendleton / gigya_snippet.html
Created August 7, 2012 20:05
Gigya integration snippet
<script>
(function() {
var insertScript = function(url) {
var elem = document.createElement('script');
elem.src = (document.location.protocol == "https:" ? "https://cdns" : "http://cdn") + ".gigya.com/js/" + url;
elem.async = true;
elem.type = "text/javascript";
$('script').eq(0).before(elem);
}
window.onGigyaServiceReady = function(type) {
@apendleton
apendleton / letter_breakdown.py
Created May 8, 2012 19:57
Optimal alphabetical breakdown of registration lines
"""
This script ingests a CSV of last names and builds JSON output on the
percentage of last names that begin with each letter of the alphabet.
I initially ran it on a CSV-ified version of the US Census's list of all last
names with more than 100 occurrences, and used the frequency field within that
file to weigh the output, but absent that field, it assigns equal weight to
each name, allowing us to also process our TCamp 2012 attendence list.
Using the script on the Census data available in: