Skip to content

Instantly share code, notes, and snippets.

View wheeyls's full-sized avatar

Michael Wheeler wheeyls

View GitHub Profile
@wheeyls
wheeyls / RiffleWatchClicks.js
Created February 9, 2013 03:11
riffle.js is a little nicer and more transparent than bacon.js
// call this separately to load the lib...
$.getScript('https://rawgithub.com/flowgrammer/Riffle/master/riffle.js').then(function () {
var clicks = stream(function (outFn, selector) {
$(selector).on('click', function (ev) {
outFn($(this));
});
})
, hrefs = stream(function (outFn, $element) {
outFn($element.attr('href'));
})
# don't tell me
# don't tell me not to tell you
# don't tell me not to tell you not to tell me
# don't tell me not to tell you not to tell me not to tell you
def dont(subject, times)
"Don't" + tell_me(subject, times)
end
def tell_me(subject, times)
# don't tell me
# don't tell me not to tell you
# don't tell me not to tell you not to tell me
# don't tell me not to tell you not to tell me not to tell you
def dont(times)
"Don't" + tell_me("me", times)
end
def tell_me(subject, times)
class BulkUpdater
def bulk_update(models)
errors = {}
models.each do |model_id, model_attrs|
model = self.class.find(model_id)
unless model.update_attributes(model_attrs)
errors[model_id] = model.errors
end
end
errors
@wheeyls
wheeyls / curve.js
Created December 12, 2012 14:09
Playing around with scaling a domain against a range. Dropped it into firebug console for a quick and dirty visualization.
var range = [0, 1000],
domain = [0, 25],
power = 2;
function calc(v) {
var normal_domain = domain[1] - domain[0]
, normal_range = range[1] - range[0]
, normal_num = v - domain[0]
, inter = normal_num / normal_domain
;
@wheeyls
wheeyls / lib.rb
Created October 11, 2012 05:26
Simple DSL to safely traverse a hash with unknown values, performing specific actions with selected values along the way.
class Dsl
attr_accessor :hash
def initialize(hash, &block)
@hash = hash
instance_eval(&block)
end
def method_missing(key_name, *args)
key_name = prepare_key(key_name)
@wheeyls
wheeyls / tween.js
Last active October 10, 2015 05:08
function tween(start, end, fn) {
var duration = end - start
;
fn = fn || function (v) { return v; };
return function (continuation, now) {
var relativeNow = now - start
, normalNow
, res
category.posts
#=> [] # list of all posts
posts.categories
#=> [] # list of all categories
@wheeyls
wheeyls / floaters.html
Created August 17, 2012 05:35
A bare bones Tumblr Template.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{block:Description}<meta name="description" content="{MetaDescription}" />{/block:Description}
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<title>{Title}</title>
<link rel="shortcut icon" href="{Favicon}" />
<link rel="apple-touch-icon" href="{PortraitURL-128}"/>
@wheeyls
wheeyls / doc_instance.rb
Created August 14, 2012 00:56
Document/Paragraph Data Model
def process_paragraphs(paragraphs_attrs)
paragraphs_attrs.select do |key, value|
# make changes and filter out existing attributes
end
end
def assign_attributes(attr, options = {})
paragraphs_attrs = attr.delete :paragraphs_attributes
# manually update any existing paragraphs here
paragraphs_attrs = process_paragraphs(paragraphs_attrs)