Skip to content

Instantly share code, notes, and snippets.

View nanaze's full-sized avatar

Nathan Naze nanaze

View GitHub Profile
nanaze /
Created November 6, 2020 07:30
Calculate x intercept for Pennsylvania ballot counting
#!/usr/bin/env python3
# Calculates expected time that Biden will overtake Trump in Pennsylvania
# base on time series data: margin over time.
# Example usage:
# $ curl "" | ./
import csv
import datetime
nanaze / scala.bzl
Created March 29, 2015 02:41
bazel genrule definition to compile scala to a .jar
def scala_jar(name, srcs, visibility=None):
name = name,
srcs = srcs,
outs = ['%s.jar' % name],
cmd = 'touch $@ && scalac -d $@ $(SRCS)',
visibility = visibility
nanaze /
Created February 23, 2015 00:19
make a DVD image automatically
def main():
print 'hello'
if __name__ == '__main__':
import HTMLParser
class LinkParser(HTMLParser.HTMLParser):
def __init__(self):
self.hrefs = []
nanaze /
Last active December 13, 2015 22:39
Copies files into a directory by SHA hash. This allows flat archival of files without worrying about filename clashes.
#!/usr/bin/env python
"""Utility to archive files by hash.
Gets the shasum of each file and copies the file to the specified dest_dir
with the hash inserted into the name. For example, IMG_011.JPG would become
IMG_011.ab98feb.JPG, etc This is useful for image files that might share the
same filename but have differing contents (such as after editing).
nanaze / gist:4749750
Last active December 12, 2015 09:09
convert video files to mp4
import os
import logging
import subprocess
import tempfile
import shutil
def convert(src, dest):
_, temp_dest = tempfile.mkstemp(suffix='.mp4')
assert os.path.exists(src), src + ' does not exist'
nanaze / download stanford class videos
Last active December 12, 2015 08:48
simple script to pull stanford lecture videos locally
import xml.dom
import os
import re
import urllib2
import logging
import urllib
import mechanize
import getpass
import html5lib
import string