Skip to content

Instantly share code, notes, and snippets.

View cbrumelle's full-sized avatar

Colin Brumelle cbrumelle

View GitHub Profile
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mongodb startup script
# Description: Mongodb start stop daemon sends SIGINT to terminate
# say man signal to see details
# Please check the startup params and replication options
(function($) {
$.fn.tweet = function(o){
var s = {
username: ["your-twitter-username"],
count: 3,
loading_text: null
};
$.fn.extend({
var data = {"listendata" : {
"genre_id":0,
"genre_name":"all",
"counts":[112,32,12,312,43,1],
"total":30303030,
"children": {
"genre_id":12,
"genre_name":"rock",
"counts":[112,32,12,312,43,1],
"total":434,
<!-- include the data file. This dumps everything into a JS variable called 'data' -->
<script src="/data/genres.js" type="text/javascript"></script>
<!-- print out some trivial data to show that it's loaded -->
<script>
$('container').update("Total count from trackdata is: " +
data.trackdata.total +
" <br />and total count from listendata is: " +
data.listendata.total);
</script>
@cbrumelle
cbrumelle / kd-tree.rb
Created March 10, 2010 21:23
KD-TREE's in ruby
require 'pp'
class KDTree
attr_reader :root
attr_reader :points
def initialize(points, dim)
@dim = dim
@root = KDNode.new(dim).parse(points)
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="prototype.js"></script>
<script language="javascript" type="text/javascript" src="jsonp.js"></script>
<title>JSONP test page</title>
</head>
@cbrumelle
cbrumelle / ycombinator-example.js
Created June 28, 2010 19:49
ycombinator in Javascript
// From: http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/
//
// A "functional" is just a function that takes
// another function as input.
// The Y combinator finds the fixed point
// of the "functional" passed in as an argument.
// Thus, the Y combinator satisfies the property:
@cbrumelle
cbrumelle / sequel_to_json.rb
Created July 13, 2010 01:00
Add 'to_json' method to Sequel datasets
# Monkey patch/hack for adding in a to_json for Sequel datasets
# See http://sequel.rubyforge.org
class Sequel::Dataset
def to_json
naked.all.to_json #Note: 'naked' converts dataset to plain hash...
end
end
@cbrumelle
cbrumelle / Distance.sql
Created July 22, 2010 16:57
Calculate distance in MySQL from Points
DELIMITER $$
DROP FUNCTION IF EXISTS `test`.`distance` $$
CREATE FUNCTION `distance`(a POINT, b POINT) RETURNS double
DETERMINISTIC
COMMENT 'distance function'
BEGIN
RETURN round(glength(linestringfromwkb(linestring(asbinary(a), asbinary(b)))));
END $$
@cbrumelle
cbrumelle / humanize_large_number.rb
Created November 5, 2010 18:37
Format large numbers nicely for millions, billions and trillions
# Format large numbers nicely for Millions, Billions and Trillions
# Example:
# humanize_large_number(123456789) => 123.46M
# humanize_large_number(123) => 123
def humanize_large_number(i)
i = Integer(i)
case i
when 1000000..999999999
"%.2fM" % (i/1000000.0)