Skip to content

Instantly share code, notes, and snippets.

View jugglebird's full-sized avatar

Chris Hunter jugglebird

View GitHub Profile
@jugglebird
jugglebird / gist:1807
Created July 23, 2008 16:22
Turning a string into a class
# Turning a string into a class.
def class_from_string(class_string)
clazz = class_string.split("::").inject(Object) { |obj, const| obj.const_get(const) }
instance = clazz.new
end
>> "day_threshold".camelize.constantize
=> DayThreshold
>> "day_threshold".camelize.constantize.new
=> #<DayThreshold:0xb7a6cbd0>
class Report < ActiveRecord::Base
%w[hits uniques].each { |const| const_set(const.upcase, const) }
end
var inject = function(iterable, initial, func) {
var cur = initial
for(var i = 0;i < iterable.length;i++) {
cur = func(cur, iterable[i])
}
return cur
}
var map = function(arr, func) {
return inject(arr, [], function(memo, val) {
# Factory girl, relaxed.
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
@jugglebird
jugglebird / index.html
Created October 11, 2011 04:15 — forked from jeffpflueger/index.html
Experiment 1 with d3 and svgweb
<!DOCTYPE html>
<html>
<head>
<!-- SVG web to turn svg into flash for IE
This might not be working on bl.ocks.org for the following reasons:
1) MIME types not added to the bl.ocks.org webserver:
AddType text/x-component htc
AddType application/x-shockwave-flash swf
AddType image/svg+xml svg
@jugglebird
jugglebird / gexf.xml
Created November 16, 2011 18:55
D3 Loading a GEXF XML file
<?xml version="1.0" encoding="utf-8"?><gexf version="1.1"
xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/
1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<graph defaultedgetype="directed" mode="static">
<nodes>
<node id="A" label="A" />
<node id="B" label="B" />
</nodes>
<edges>
@jugglebird
jugglebird / _.md
Created March 20, 2013 15:11
hello
@jugglebird
jugglebird / _.md
Created April 11, 2013 16:56
Word wrap with foreignObject
@jugglebird
jugglebird / jquery-plugin-template
Created January 10, 2014 15:28
A good, minimal template for creating a jQuery plugin.
;(function($) {
// multiple plugins can go here
(function(pluginName) {
var defaults = {
color: 'black',
testFor: function(div) {
return true;
}
};
$.fn[pluginName] = function(options) {