Skip to content

Instantly share code, notes, and snippets.

@earino
earino / joke_map.R
Created August 3, 2014 20:32
joke_map.R
joke_map <- function(states_to_highlight, title="", highlight_colors=c("#aaaaaa", "#ee0000")) {
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(maps)
highlighting = data.frame(region=tolower(state.name[match(states_to_highlight, state.abb)]),
highlight=TRUE)
d = map_data("state") %>% left_join(highlighting, by="region")
@earino
earino / holly_holm_opponents.csv
Created July 11, 2014 00:20
A CSV of Holly Holm's opponents, and the last year they were active according to the fightfinder
fighter wins losses last_year_fought
juliana werner 7 4 2014
angela hayes 6 7 2013
nikki knudsen 2 2 2013
allana jones 2 5 2014
katie merrill 1 1 2013
jan finney 8 10 2011
christina domke 4 2 2011
@earino
earino / kill_children.pl
Created May 23, 2014 01:44
how i just killed the children
#that title doesn't get me on a list...
use Parallel::ForkManager;
use Data::Dumper;
my @sleep = (
10,
60,
60,
60,
60,
print("start.207")
for (i in 1:5) {
t <- get(paste0("d", i));
y <- factor(t[,c("start.207")], levels=c("1", "0"))
x <- t[,c("stop.165","stop.166","stop.167","stop.168","stop.169","stop.185",
"stop.186","stop.187","stop.188","stop.189","stop.205","stop.206",
"stop.207","stop.208","stop.209","stop.225","stop.226","stop.227",
"stop.228","stop.229","stop.245","stop.246","stop.247","stop.248","stop.249")]
md <- train(x, y, method="rf", ntree=ntrees, trControl=trainControl(method="cv"))
@earino
earino / modern.pl
Created February 28, 2014 05:47
syntax highlighted version
package LedgerSMB::Currency;
use Moose;
with 'LedgerSMB::PGOSimple::Role', 'LedgerSMB::MooseTypes';
use PGObject::Util::DBMethod;
sub _set_prefix { 'currency__' }
has id => (is => 'rw', isa => 'Int', required => '0');
has symbol => (is => 'ro', isa => 'Str', required => '1');
@earino
earino / c_in.js
Created February 19, 2014 17:22
Why is there C in my javascript?!
/* from http://madebyevan.com/webgl-water/water.js
used in the awesome WebGL water demo
http://madebyevan.com/webgl-water/*/
this.dropShader = new GL.Shader(vertexShader, '\
const float PI = 3.141592653589793;\
uniform sampler2D texture;\
uniform vec2 center;\
uniform float radius;\
uniform float strength;\
@earino
earino / foo.py
Created February 4, 2014 03:34
Better Logistic Example in Apache Spark
from pyspark.mllib.classification import LogisticRegressionWithSGD
from numpy import array
# Load and parse the data
data = sc.textFile("mllib/data/sample_svm_data.txt")
parsedData = data.map(lambda line: array([float(x) for x in line.split(' ')]))
model = LogisticRegressionWithSGD.train(parsedData)
# Build the model
labelsAndPreds = parsedData.map(lambda point: (int(point.item(0)),
@earino
earino / foo.py
Created February 4, 2014 03:30
Logistic Regression Example from http://spark.incubator.apache.org/examples.html
points = spark.textFile(...).map(parsePoint).cache()
w = numpy.random.ranf(size = D) # current separating plane
for i in range(ITERATIONS):
gradient = points.map(
lambda p: (1 / (1 + exp(-p.y*(w.dot(p.x)))) - 1) * p.y * p.x
).reduce(lambda a, b: a + b)
w -= gradient
print "Final separating plane: %s" % w
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
my @records = ();
my $now = time();
my $weeks = 604800 * 52;
@earino
earino / calling.R
Created January 6, 2014 00:44
Calling C++ from R
sourceCpp('../src/string_slicer.cpp')
sliced_string <- string_slicer(s, cutpoints$start, cutpoints$end)