Skip to content

Instantly share code, notes, and snippets.

@wrgoldstein
wrgoldstein / match_example.R
Created September 20, 2013 15:39
Efficient lookups in R
ids <- sample(c(9999,1021,4000),10, replace = TRUE)
lookup <- list(ix = c(9999,1021,4000), val = c('apple','pear','orange'))
print(lookup$val[match(ids,lookup$ix)])
import numpy as np
import pandas as pd
a = pd.DataFrame({'user_id': [8993,8994,8994,9009,9009],\
'amount' : [50.00, 72.00, 72.00, 21.99, 21.99]})
a.set_index('user_id').amount.min()
real_ids = [8993,8994,8994,9009,9009]
fake_ids = [999999,999998]
ids = real_ids+fake_ids
@wrgoldstein
wrgoldstein / index.html
Last active August 29, 2015 14:10
kmeans
<!DOCTYPE html>
<html>
<head>
<style>
.title {
margin-left: 25%;
margin-right: 25%;
font-family: georgia;
margin-top: 40px;
Verifying that +wrgoldstein is my openname (Bitcoin username). https://onename.io/wrgoldstein
@wrgoldstein
wrgoldstein / dob_scraper.py
Created December 5, 2014 01:24
quick and dirty scraping script for DOB landmark violations
import urllib2
import re
import sys
def open_url(url):
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
raw_html = opener.open(url).read()
return raw_html
require 'active_support/concern'
module A
extend ActiveSupport::Concern
module ClassMethods
@@a = 2
def a
@@a
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wrgoldstein
wrgoldstein / pipeable_data.rb
Created September 19, 2015 21:22
Pseudo-summary of Hadley Wickham talk on pipeable data in R. I've been generally interested in trying to find clearer patterns for describing data pipelines
# Say we want to tell a story like the following:
"the bunny Foofoo went to the forest and ate a mouse"
# we build up the pieces to tell the story:
def the_bunny(name)
"The bunny #{name}"
end
@wrgoldstein
wrgoldstein / pipeable_data.rb
Last active September 19, 2015 21:32
Pseudo-summary of Hadley Wickham talk on pipeable data in R. I've been generally interested in trying to find clearer patterns for describing data pipelines in ruby.
# Say we want to tell a story like the following:
"the bunny Foofoo went to the forest and ate a mouse"
# we build up the pieces to tell the story:
def the_bunny(name)
"The bunny #{name}"
end
<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script>
var width = 960,
height = 500,