Skip to content

Instantly share code, notes, and snippets.

View wolever's full-sized avatar

David Wolever wolever

View GitHub Profile
@wolever
wolever / output.txt
Created December 13, 2013 19:21
Tracing PyPy's numerically optimized factorial function: https://bitbucket.org/pypy/pypy/src/default/pypy/module/math/app_math.py#cl-1
> fact(100)
>> _fac1(100)
>>> _fac1(50)
>>>> _fac1(25)
>>>>> _fac1(12)
>>>>>> _fac1(6)
>>>>>>> _fac1(3)
>>>>>>>> _fac1(1) ==> (1, 1, 0)
>>>>>>>> _fac_odd(3, 4) ==> 3
>>>>>>> _fac1(3) ==> (3, 3, 1)
@wolever
wolever / counts.txt
Last active December 28, 2015 07:08
vcslog data
di: 7292
st: 7281
log: 3844
ci: 3660
rev-parse: 3192
push: 1880
config: 1670
nudge: 1441
for-each-ref: 1369
qref: 1287
@wolever
wolever / ShazChains.ipynb
Created November 12, 2013 21:56
ShazChains: very, very naive markov chains from @shazow's tweets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wolever
wolever / firewall.sh
Created October 10, 2013 15:55
The firewall script I wrote in highschool and have been copy+pasting around since then.
#!/bin/sh
# Script to manage iptables rules -- executed when eth1 is brought up. See
# also /etc/network/interfaces
if [[ `whoami` != 'root' ]]
then
echo "Sorry dude... Gotta be root."
exit 1
fi
@wolever
wolever / autodunder.py
Last active December 23, 2015 07:49
Short Python tips, sometimes with a Django bent, sometimes without unit tests.
def _autofmthelper(name, fmt, postprocess=None):
def fmtfunc(self):
result = fmt.format(self=self)
if postprocess is not None:
result = postprocess(self, result)
return result
fmtfunc.__name__ = name
return fmtfunc
def autounicode(fmt):
@wolever
wolever / profile
Created September 11, 2013 15:41
My very fast Bash prompt, which shows git branch, virtualenv, and background jobs
# prompt examples:
# [3 jobs master virtualenv] ~/code/myproject/foo
# [1 job my-branch virtualenv] ~/code/bar/
# [virtualenv] ~/code/
# ~
# Very, very fast, only requiring a couple of fork()s (and no forking at all to determine the current git branch)
if [[ "$USER" == "root" ]]
then
export PS1="\e[1;31m\]\u \[\e[1;33m\]\w\[\e[0m\] ";
@wolever
wolever / git-safemerge
Last active October 22, 2022 07:23
git-safemerge performs a "safer" merge, confirming the commits to be merged and the changes to be made before starting the commit process.
#!/bin/bash
# Performs a "safe" merge, confirming the commits to be merged, the merge
# strategy, any conflicts, etc.
# Useage:
# $ git safemerge master
# Commits:
# * bc911ef Fix bug in widget
# * e80f8d1 Clean things up
#
# Changes:
@wolever
wolever / main.go
Last active December 21, 2015 23:49
A simple, incomplete, peer-to-peer chat server in Go written at Go Toronto
package main
import (
"net"
"strings"
"bufio"
"fmt"
)
const (
@wolever
wolever / git-unpull
Last active December 21, 2015 04:08
git-unpull: undoes the merge commit created by an accidental 'git pull', plus some added helpful information!
#!/bin/bash
# Reverts HEAD back to ORIG_HEAD, for example after a 'git pull' accidentally
# creates a merge. This is identical to running 'git reset --hard ORIG_HEAD',
# except that unpull prints some helpful information along the way.
# Useage:
# $ git unpull
# HEAD: a0ac0fd Merge branch 'master' of /tmp/foo
# 2284c9d some remote commit
# ORIG_HEAD: 35431fd my local commit
# Really reset HEAD to ORIG_HEAD? (y/n) y
@wolever
wolever / first_four_chracters.sql
Last active December 20, 2015 11:59
An analysis of the first names of @pyconca attendees. The 'count' column is the number of times each of the names on the right appears in the database.
-- looking at the first 4 characters of names
-- count name
-- 1 197 names that appear once
-- 2 30 names that appear twice
-- 3 ryan, nick, just, juli, jess, jenn, fran, bria, bran, aaro
-- 4 matt, marc, jeff, anto, andr
-- 5 mike, dani, dan
-- 6 jame, davi
-- 7 jaso
-- 8 alex, adam