Skip to content

Instantly share code, notes, and snippets.

View pqcfox's full-sized avatar
🦊
bouncing around between projects

kat watson pqcfox

🦊
bouncing around between projects
  • zeroRISC
  • los angeles
  • 20:21 (UTC -07:00)
View GitHub Profile
@pqcfox
pqcfox / halftau.py
Last active August 29, 2015 13:57
Happy 1/2 Tau Day! Here's a 1/2 tau generator for those of you who enjoy such things.
n = 9001
total = 0.0
for k in range(1, n+1):
total += (-1.0)**(k+1.0)/(2.0*k-1.0)
print "Using {0} terms of the series:".format(n)
print "Half-tau (a.k.a. pi) ≈ {0}".format(total * 4)
print "Tau ≈ {0}".format(total * 8)
@pqcfox
pqcfox / brew_prefix
Created September 28, 2014 00:43
Output from my homebrew configuration.
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: 44a59fb8e2575651714d8de186a312ab8f4336bf
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit haswell
OS X: 10.9.4-x86_64
Xcode: 6.0.1
CLT: 6.0.0.0.1.1410400753
Clang: 6.0 build 600
@pqcfox
pqcfox / classify.py
Last active August 29, 2015 14:07
A program to set up the Caltech101 corpus for classification with Glimpse and SVM-Light.
import copy, itertools, os, random, re, shutil, string
from PIL import Image
dirs = [ f for f in os.listdir('.') if os.path.isdir(f) and '-' in f ]
# Split pairwise data into individual classes.
for d in dirs:
classes = d.split('-')
@pqcfox
pqcfox / costFunction.m
Last active August 29, 2015 14:07
A simple function from the Coursera Machine Learning class to calculate logistic regression cost.
function [J, grad] = costFunction(theta, X, y)
%COSTFUNCTION Compute cost and gradient for logistic regression
% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the
% parameter for logistic regression and the gradient of the cost
% w.r.t. to the parameters.
% Initialize some useful values
m = length(y); % number of training examples
% You need to return the following variables correctly
@pqcfox
pqcfox / dehash.py
Created November 7, 2014 18:22
A cute little dehasher.
import hashlib, sys
words = open('/usr/share/dict/words', 'r').read().splitlines()
hashes = [ hashlib.md5(w).hexdigest() for w in words ]
dictionary = dict(zip(hashes, words))
try:
print dictionary[sys.argv[1]]
except:
print "Could not decrypt hash."
@pqcfox
pqcfox / bingo.py
Created November 22, 2014 18:53
A piece of code to find the optimal strategy for placing tokens on a n by n board without getting a n-token line on a row or diagonal.
import itertools, math
# Determines the width/height of a square board.
def size(board):
return int(math.sqrt(len(board)))
# Determines whether a flat bingo board (list of length size**2) has five
# in a row on any row, column, or diagonal.
def bingo(board):
s = size(board)
@pqcfox
pqcfox / namesum.py
Created January 19, 2015 06:04
Adding together nicknames - mixed results may output...
import string
a = "fouric"
b = "nocyno"
name_sum = ""
name_difference_ab = ""
name_difference_ba = ""
alphabet = string.ascii_lowercase
for index in range(len(a)):
@pqcfox
pqcfox / markov.py
Created January 19, 2015 06:50
A simple Markov chain to generate nicknames or fake English words.
import collections
import random
import re
import string
alphabet = string.ascii_lowercase
# Make a counter for each lowercase letter, and add a count to it
# whenever a letter follows it in /usr/share/dict/words
counters = {letter: collections.Counter() for letter in alphabet}
@pqcfox
pqcfox / 8a.py
Created January 27, 2015 04:22
An exercise in my Number Theory class.
n = int(input("Enter a number: "))
def perfect(n):
total = 0
for k in range(1, n):
if n % k == 0: total += k
return total == n
message = 'yes' if perfect(n) else 'no'
@pqcfox
pqcfox / 8b.py
Created January 27, 2015 04:22
An exercise in my Number Theory class.
highest = int(input("Enter a number: "))
def perfect(n):
total = 0
for k in range(1, n):
if n % k == 0: total += k
return total == n
for n in range(1, highest+1):