Skip to content

Instantly share code, notes, and snippets.

@matsadler
matsadler / project.js
Created October 7, 2012 20:29
JavaScript mercator projection
/*jslint vars: true */
// adapted from http://wiki.openstreetmap.org/wiki/Mercator#JavaScript
(function () {
var project = {};
if (typeof exports === "object") {
module.exports = project;
} else {
this.project = project;
@matsadler
matsadler / pr_geohash_ext.rb
Created August 2, 2012 11:51
Additions to the pr_geohash gem for distance calculation
require "pr_geohash"
module GeoHash
RADIUS_OF_THE_EARTH = 6371
RADIANS_CONVERSION_FACTOR = 180 / Math::PI
# decode geohash to a latitude/longitude point in the centre of the
# bounding box described by the geohash
def decode_point(geohash)
import System.IO
import Data.List
import qualified Data.Map as M
import System.Random
import Data.Maybe
import Control.Applicative
main = do
contents <- readFile "messages.txt"
gen <- getStdGen
class Markov
attr_reader :order, :phrases
def initialize(corpus=[], order=3)
@order = order
@phrases = Hash.new {|h,k| h[k] = []}
add(corpus)
end
def add(corpus)
@matsadler
matsadler / jruby-1.6.8.dev
Created June 20, 2012 09:03
ruby-build definition for jruby-1.6.8.dev
install_package "jruby-1.6.8.dev" "http://ci.jruby.org/snapshots/release/jruby-bin-1.6.8.dev.tar.gz" jruby
@matsadler
matsadler / Gemfile
Created June 18, 2012 16:34
ActiveRecord slowdown with Threads
source :rubygems
gem "activerecord", "3.1.4"
platforms :mri do
gem "mysql2"
end
platforms :jruby do
gem "activerecord-jdbcmysql-adapter"
@matsadler
matsadler / em-statsd-ruby.rb
Created May 29, 2012 16:14
EventMachine connectivity for the statsd-ruby client
require "eventmachine"
require "statsd" # statsd-ruby gem
module EventMachine
class Statsd < ::Statsd
class ConnectionWrapper
def initialize(em_connection)
@em_connection = em_connection
end
require "securerandom"
class RollingCounter
# :call-seq: RollingCounter.new(redis_client, max_window_seconds) -> counter
#
# Create a new counter instance, that will store/retrieve counts with
# +redis_client+ and return counts within the last +max_window_seconds+
# seconds.
#
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>untitled</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
require 'thread'
require 'rubygems'
require 'net/irc'
# undo weirdness in the net/irc library, so that we get NoMethodError when we
# call a method that doesn't exist
class Net::IRC::Client
remove_method :method_missing if defined? method_missing
end