Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
@rjungemann
rjungemann / sample.coffee
Created September 12, 2011 02:30
Generate WebSocket frames in CoffeeScript
hexToBuffer = (hex, padding) ->
n = lpad hex.toString(16), '0', padding
list = []
while n.length > 0
head = n.substr 0, n.length - 2
tail = n.substr n.length - 2
list.unshift parseInt tail, 16
@rjungemann
rjungemann / gist:1210409
Created September 12, 2011 01:23
Enforce a timeout in CoffeeScript
timeout = (interval, callback) ->
setTimeout callback, interval
interval = (interval, callback) ->
setInterval callback, interval
enforce = (interval, options) ->
t = timeout interval, ->
options.onfail() if options.onfail?
@rjungemann
rjungemann / galaxy_column
Created September 11, 2011 06:50
Example R code
#!/usr/bin/env Rscript
# -----
# USAGE
# -----
# ./galaxy_column ~/desktop/galaxy1014.txt SVZ_conf_lo DG_conf_hi
# ---------
# FUNCTIONS
@rjungemann
rjungemann / data.rb
Created August 30, 2011 00:54
DATA in Ruby
f = File.open __FILE__, 'w'
f.seek DATA.pos
puts f.gets
__END__
'tasty!'
@rjungemann
rjungemann / r.markdown
Created August 25, 2011 05:42
Quick Intro to Manipulating Tabular Data in R

Quick Intro to Manipulating Tabular Data in R

Getting Started

Download R here.

Run R. You will be greeted by the R console. You can interactively type in commands and it will respond, allowing you to experiment quickly.

@rjungemann
rjungemann / oneway2.coffee
Created August 6, 2011 02:38
Normalize an angle in CoffeeScript
normalizeAngle = (a) ->
if a < 0 || a > Math.PI * 2
Math.abs Math.PI * 2 - Math.abs(angle)
else
angle
@rjungemann
rjungemann / jquery.autoResize.coffee
Created July 18, 2011 18:54
Auto-Resizing Text Area
# Auto-Resizing Text Area
# Works in Chrome, Firefox, and IE7+
# notes:
# * 'rows' and 'cols' attributes should be set on the textarea
# * 'rows' becomes the minimum number of rows
# * 'overflow' should be set to 'hidden' and 'height' should be set to 'auto'
# sass:
@rjungemann
rjungemann / gist:1080833
Created July 13, 2011 17:39
Use Koala to send a SWF attachment to Facebook
SocialProperty.first.facebook_client.put_object '119328154811026', 'feed', {
"message" => 'cool',
"type" => "swf",
"source" => "http://dl.dropbox.com/u/2293356/swf_sample/Viking_Kittens.swf",
"picture" => "http://dl.dropbox.com/u/2293356/swf_sample/Viking_Kittens.png",
"width" => "160",
"height" => "120",
"expanded_width" => "320",
"expanded_height" => "240"
}
@rjungemann
rjungemann / sinatra_boilerplate.rb
Created July 10, 2011 09:54
sinatra_boilerplate.rb—some potentially interesting CoffeeScript and cache ideas
require 'sinatra/base'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/integer/time'
require 'active_support/core_ext/time/acts_like'
require 'haml'
require 'sass'
require 'compass'
require 'uglifier'
require 'coffee_script'
@rjungemann
rjungemann / caramelize.rb
Created May 12, 2011 07:31
Load a spreadsheet exported as CSV into MySQL
#!/usr/bin/env ruby
# USAGE:
# caramelize mysql://root:root@localhost:8889/sample samples sample.csv
require 'csv'
require 'mysql'
require 'sequel'
def sluggerize string