This file contains hidden or 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/python | |
""" | |
python resize_files.py folder_of_input_images output_file.gif | |
""" | |
import os, sys, re | |
RESIZE_PERCENT = 12 | |
QUALITY = 40 | |
folder = sys.argv[1] |
This file contains hidden or 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
values <- c('a', 'b', 'c') | |
probs <- c(.2, .5, .3) | |
sample(values, 10, replace=TRUE, prob=probs) | |
# [1] "a" "b" "a" "a" "c" "a" "c" "b" "c" "b" |
This file contains hidden or 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
{block:Posts} | |
<script language="JavaScript"> | |
var source_url = '{block:ContentSource}{SourceURL}{/block:ContentSource}'; | |
var reblogged_from = '{block:RebloggedFrom}{ReblogParentName}{/block:RebloggedFrom}' + '.tumblr.com'; | |
if (source_url.indexOf(reblogged_from) == -1) { | |
document.write('Your attribution string!'); | |
} | |
</script> | |
{/block:Posts} |
This file contains hidden or 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
""" | |
Input is one number per line | |
Output is json of the form: | |
[ | |
{ | |
'bin' : bin1, | |
'value' : value1 | |
}, | |
{ |
This file contains hidden or 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
y | x | |
---|---|---|
23 | 1 | |
26 | 1 | |
444 | 0.583333333333333 | |
15 | 1 | |
34 | 1 | |
17 | 1 | |
37 | 1 | |
139 | 0.0359712230215827 | |
300 | 0.183333333333333 |
This file contains hidden or 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
my.reduce <- function(df.in, f1, f2){ | |
x <- ddply(df.in, .(f1, f2), summarize, | |
value=sum(value) | |
) | |
x | |
} | |
df <- data.frame( | |
state=rep(c("MA", "NY", "CA"), each=10), | |
year=rep((2001:2010), 3), |
This file contains hidden or 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
import numpy as np | |
import random | |
# dict to hold results | |
counts = {} | |
# a hack to generate random key, value pairs. | |
# 5k keys, 100k values | |
x=[i%5000 for i in xrange(100000)] | |
random.shuffle(x) |
This file contains hidden or 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
from numpy.random import uniform | |
import numpy | |
import random | |
def slice_sampler(px, N = 1, x = None): | |
""" | |
Provides samples from a user-defined distribution. | |
slice_sampler(px, N = 1, x = None) | |
This file contains hidden or 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
plotmatrix2 <- function (data, mapping = aes()) | |
{ | |
grid <- expand.grid(x = 1:ncol(data), y = 1:ncol(data)) | |
grid <- subset(grid, x != y) | |
all <- do.call("rbind", lapply(1:nrow(grid), function(i) { | |
xcol <- grid[i, "x"] | |
ycol <- grid[i, "y"] | |
data.frame(xvar = names(data)[ycol], yvar = names(data)[xcol], | |
x = data[, xcol], y = data[, ycol], data) | |
})) |
This file contains hidden or 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
from __future__ import division | |
import numpy as np | |
from pylab import * | |
from warnings import warn | |
class OutlierDetector(object): | |
def __init__(self, N=10): | |
""" | |
Generates some simple statistics on the previous N data points |