This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collapse_intervals(intervals): | |
'''intervals is an iterable of 2-tuples representing the start and end of | |
closed intervals. returns a list of 2-tuples after collapsing any | |
overlapping intervals. For example: | |
collapse_intervals([(1,5), (9,10), (4,7)]) -> [(1,7), (9,10)] | |
The algorithm doesn't care if intervals are out of order, or if two points | |
of the same interval are out of order. It also doesn't require the points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat ~/.ssh/id_rsa.pub | ssh $USER@$SERVER "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://en.wikipedia.org/wiki/RSA_(algorithm) | |
p = 61 | |
q = 53 | |
n = p*q | |
totient = (p-1)*(q-1) | |
# here, e is 2^4 + 1; in real world applications, e is often 2^16 + 1 | |
e = 17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example using Python's itertools and generators to implement the classic FizzBuzz problem using pythonic iterators. | |
Output looks like this: | |
$ python fizz_buzz_with_iterator.py | |
1 | |
2 | |
Fizz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
Simple wrapper around Github's gist HTTP API. | |
""" | |
import argparse | |
import logging | |
import requests | |
import json | |
from getpass import getuser, getpass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Oran Looney, November 2011 | |
""" GENERAL SECTION """ | |
" turn on automatic syntax highlighting. | |
syntax on | |
filetype plugin on | |
set directory=/tmp | |
""" WHITESPACE """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Select | |
sum(size) AS total_size_on_disk, | |
sum(size) / (select count(*) from individual) AS per_individual | |
FROM ( | |
SELECT | |
pg_relation_size(C.oid) AS "size" | |
FROM pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
WHERE 1=1 -- relname in (...) | |
ORDER BY pg_relation_size(C.oid) DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <tuple> | |
#include <algorithm> | |
#include "xtensor/xarray.hpp" | |
#include "xtensor/xio.hpp" | |
#include "xtensor/xmath.hpp" | |
#include "xtensor/xrandom.hpp" | |
#include "xtensor/xbuilder.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Markdown==2.6.10 | |
numpy==1.6.1 | |
ordereddict==1.2 | |
pandas==0.14.1 | |
patsy==0.4.1 | |
python-dateutil==2.6.1 | |
pytz==2017.3 | |
requests==2.18.4 | |
six==1.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compare_histograms <- function(sn) { | |
sample_means <- function(r,n) { sqrt(n)*rowMeans(matrix(r(n*10000), ncol=n)) } | |
center_scale <- function(v) (v - mean(v))/sd(v) | |
exp_sample <- center_scale(sample_means(rexp, sn)) | |
unif_sample <- center_scale(sample_means(runif, sn)) | |
max_break = ceiling(max(c(unif_sample, exp_sample))) | |
min_break = floor(min(c(unif_sample, exp_sample))) | |
breaks = seq(min_break,max_break,length.out=(max_break-min_break)*8+1) |