Skip to content

Instantly share code, notes, and snippets.

@michael-groble
michael-groble / example.rb
Last active March 27, 2023 14:55
Small anonymized databases for local development
class CleanAndAnonymize
def initialize(connection_url, weeks: 2, vacuum_full: false, dry_run: true)
@connection_url = case connection_url
when URI
connection_url
else
URI.parse(connection_url)
end
@weeks = weeks
@vacuum_full = vacuum_full
@michael-groble
michael-groble / divvy.py
Created May 2, 2014 00:54
Exploring Chicago and New York bike share data with Pandas
import pandas as pd
import numpy as np
import collections
import ggplot
import json
from ggplot import *
def load_stations_json(json_file):
""" load station info from the JSON web API
@michael-groble
michael-groble / generate_point_clouds.cpp
Created January 21, 2013 19:26
Simulate point clouds of packages loaded in trailers
#include <iostream>
#include <fstream>
#include <Eigen/Eigen>
#include <limits>
#include <vector>
typedef Eigen::Vector3f Vector3;
typedef Vector3::Scalar Length;
enum class Normal {INTERIOR, EXTERIOR};
@michael-groble
michael-groble / location_history.rb
Last active December 11, 2015 01:49
circular buffers with Redis
# Example showing how to create a circular history buffer in redis. This example stores a location
# history in a packed binary representation that can be sent to a browser to unpack with DavaView.
# If the browser has local storage, it can request to catch up to the history from where it left off.
#
# We use a string to store the history and setrange/getrange to manipulate individual records
# Another string serves as a counter to know where to insert the next record
# Finally, a sorted set is used to track the timestamp associated with each record to support
# the 'since' query
#
# Note, this doesn't support dynamically changing the capacity
@michael-groble
michael-groble / dynamic.js
Last active December 11, 2015 01:49
dynamic trajectories with D3
extend = function(proto, properties) {
for (var key in properties) {
proto[key] = properties[key];
}
return proto;
}
Object.getPrototypeOf(d3.map()).length = function() {
var length = 0;
this.forEach(function(key) {++length;});
@michael-groble
michael-groble / RegionIndex.java
Created January 13, 2013 21:59
Look up enclosing regions with JTS
package example.gists;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
@michael-groble
michael-groble / example.R
Last active August 9, 2017 20:40
plot Chicago crime data
source('plot_crime.R')
city <- read.city_boundary('chicago/City_Boundary.shp')
crimes <- read.crimes('chicago/Crimes_-_2011.csv')
png('chicago/crimes_2011.png', width=835, height=1295)
plot_crime(crimes, city, max_rank=20, ncol=4)
dev.off()
@michael-groble
michael-groble / autocorrelation.R
Created January 13, 2013 21:39
autocorrelation
# fast auto-correlation
acf.II <- function(x)
{
n <- length(x)
x <- c(x, rep.int(0, n))
transform <- fft(x)
x <- fft(Conj(transform) * transform, inverse = TRUE)
Re(x)[1:n]/(2*n)
}
@michael-groble
michael-groble / methods.js
Created August 23, 2012 20:37
Ruby's "methods" in JavaScript
// Almost just like ruby, lets you do the following:
//
// "".methods().grep(/__/)
// [ '__defineGetter__()',
// '__defineSetter__()',
// '__lookupGetter__()',
// '__lookupSetter__()' ]
//
// I would prefer to define this as getter, but node throws the following when I try
// TypeError: Property 'hasOwnProperty' of object #<error> is not a function
@michael-groble
michael-groble / postinstall.sh
Created August 4, 2012 13:52
veewee ubuntu postinstall for ruby 1.9.3
# postinstall.sh created from Mitchell's official lucid32/64 baseboxes
#
# Significant modifications:
# ruby 1.9.3 with libyaml and ffi
# no puppet
# g++
# use existing guest additions iso instead of re-download
date > /etc/vagrant_box_build_time