Skip to content

Instantly share code, notes, and snippets.

@alexkay
alexkay / pycon.py
Created April 16, 2013 20:34
Thumbtack PyCon 2013 challenge
#!/usr/bin/env python
import collections
import itertools
import re
import sys
words = {
word
for word in re.split(r'\W+', sys.stdin.read().lower())
@alexkay
alexkay / gist:2566869
Last active March 27, 2020 08:36
Mirrored encrypted FreeBSD install
# Start with the setup normally, then select "Shell" at the partitioning step.
# Check device names
camcontrol devlist
# Create a gpt and a bootstrap partition
gpart destroy -F ada0
gpart create -s gpt ada0
gpart add -a 4k -t freebsd-boot -s 64k ada0
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
@alexkay
alexkay / gist:1600742
Created January 12, 2012 14:13
Code Sprint 2 - Quora Nearby
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
struct Topic {
@alexkay
alexkay / gist:1600725
Created January 12, 2012 14:11
Code Sprint 2 - Subsequence Weighting
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
struct Node {
int a;
long long w;
Node *prev;
@alexkay
alexkay / gist:1600704
Created January 12, 2012 14:08
Code Sprint 2 - Fraud Prevention
#!/usr/bin/env python
import re
def normalise_email(email):
email = email.lower()
i = email.find("@")
prefix = email[:i]
j = prefix.find("+")
if j != -1:
@alexkay
alexkay / gist:1600579
Created January 12, 2012 13:40
Code Sprint 2 - Coin Tosses
#!/usr/bin/env python
memo = {}
def calc(n, m):
key = n * 10000 + m
if key in memo:
return memo[key]
if n == 0 or n == m:
res = 0
elif m == 0:
@alexkay
alexkay / gist:1600348
Created January 12, 2012 12:56
Code Sprint 2 - Picking Cards
#!/usr/bin/env python
def calc(a, n):
res = 1
m = 1
for i in xrange(n):
m -= 1
for k in xrange(i + m, n):
if a[k] > i:
break