Skip to content

Instantly share code, notes, and snippets.

View alexstorer's full-sized avatar

Alex Storer alexstorer

View GitHub Profile
@alexstorer
alexstorer / distance_matrix.m
Created March 20, 2012 21:06 — forked from sjaffe/distance_matrix.m
Sonia's matlab code
%Generate neighbors and relations matrix for each MSA
%system(rename msa*.mat msa.mat);
%filename=strcat('\nsf\usr\S\sjaffe\Work\Segregation\Matlab\msa', str2int(job_instance))
missing=importdata('/nfs/home/S/sjaffe/Work/Segregation/Matlab/missing.txt');
%16 34
path(path, '/nfs/projects_nobackup/s/sjaffe')
path(path, '/nfs/home/S/sjaffe/Work/Segregation/Matlab')
cd '/nfs/projects_nobackup/s/sjaffe'
for file_num=10:52
@alexstorer
alexstorer / vectorize.m
Created March 20, 2012 21:07
Vectorized Distance
%d=6378.1*acos(sin(2*pi*lat(i)/360)*sin(2*pi*lat(j)/360)+cos(2*pi*(lng(i)-lng(j))/360)*cos(2*pi*lat(i)/360)*cos(2*pi*lat(j)/360));
tic
N = 4000;
% test some distances
lat = rand(N,1)*180;
lng = rand(N,1)*180;
% the loopy way
d = zeros(N);
@alexstorer
alexstorer / gist:2241411
Created March 29, 2012 18:16
Titled Bar Plots
hsb2 <- read.table('http://www.ats.ucla.edu/stat/R/faq/hsb2.csv', header=T, sep=",")
attach(hsb2)
sesmeans <- tapply(math, ses, mean)
femaleses = tapply(math, list(as.factor(ses), as.factor(female)), mean)
bp <- barplot(femaleses, beside = TRUE, main = "Math by SES and gender",
col = c("lightblue", "mistyrose", "lavender"),
xlab = "Gender", names = c("Male", "Female"),
ylab = "Mean Math Score", legend = c("Low", "Medium", "High"),
args.legend = list(title = "SES", x = "topright", cex = .7), ylim = c(0, 90))
@alexstorer
alexstorer / plotDecision.m
Created April 12, 2012 17:32
Plot the distributions of two gaussians along with a criterion, in the style of decision theory.
function h = plotDecision(dprime,sdnoise,criterion)
% h = plotDecision(dprime, sdnoise, criterion)
%
% plotDecision makes a plot of two Gaussian functions, inspired by signal
% detection theory. The inputs are given in terms of standard deviates of
% the signal distribution:
%
% dprime - d', the distance between the means of the Gaussians
% sdnoise - $\sigma$, the ratio of the standard deviation of the noise to
% the standard deviation of the signal.
@alexstorer
alexstorer / copyandrename.py
Created April 30, 2012 20:46
copying files and renaming them
import fnmatch
import os
import shutil
import re
for file in os.listdir('.'):
flist = os.path.basename(file).split('.')
fname = flist[0]
fext = '.blah'
@alexstorer
alexstorer / labelImages.m
Created June 18, 2012 13:30
labelImages - a small tool to do image labeling in Matlab
% labelImages(impath)
% ---------------------------------------
% Places labels on an image, and saves the marker locations and a 3x3
% square pixel neighborhood of RGB values.
%
% Usage:
% labelImages('/Users/astorer/Desktop/test.jpg')
% LEFT CLICK - Add a point
% RIGHT CLICK - Delete a point
% 's' - Save progress
@alexstorer
alexstorer / gist:3251327
Created August 3, 2012 20:41
Scraper for ANC Press Releases
from lxml import etree
import csv
import urllib2
import urllib
import re
def downloadallarticles(tree,year):
articles = tree.xpath('.//*[@id="middle2level"]/table[2]//a')
destpath = '/Users/astorer/Work/sgrossman/output/'
for a in articles:
@alexstorer
alexstorer / gist:3295676
Created August 8, 2012 15:00
Pseudo-code for Matt's Experiment
num_statements = 5;
num_blocks = 9;
for run = 1:8
% 150 statements, 50 of each type
physical_order = Shuffle(1:50);
mental_order = Shuffle(1:50);
emotional_order = Shuffle(1:50);
physical_num = 1
@alexstorer
alexstorer / gist:3297899
Created August 8, 2012 19:30
How to submit a basic matlab job to the RCE using condor_submit
Universe = vanilla
Executable = /usr/local/bin/matlab
Arguments = -nodisplay -r \"addpath('/nfs/home/A/astorer/Work/dchan');
test($(Process))\"
when_to_transfer_output = ON_EXIT_OR_EVICT
transfer_output_files = out.$(PROCESS)
input =
output = out.$(Process)
error = error.$(Process)
@alexstorer
alexstorer / gist:3307317
Created August 9, 2012 19:24
Convert relevant html docs to text!
# open the files in the directory, parse them and get the text.
#eg.text_content()
import glob
from lxml import etree
import lxml.html
import csv
import urllib2