Skip to content

Instantly share code, notes, and snippets.

View wheeyls's full-sized avatar

Michael Wheeler wheeyls

View GitHub Profile
@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 / 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
;
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
# 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)
@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'));
})
(function () {
var initializing = false
, superPattern = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
Object.subClass = function (properties) {
var _super = this.prototype;
initializing = true;
var proto = new this();
initializing = false;
(function () {
var initializing = false
, superPattern = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/;
Object.subClass = function (properties) {
var _super = this.prototype;
initializing = true;
var proto = new this();
initializing = false;
@wheeyls
wheeyls / example.js
Last active December 14, 2015 20:40
Export a library for commonjs, nodejs, and browser.
function myLib() {
return {
code: function () {}
, goes: function () {}
, here: function () {}
}
}
exporter('myLib', myLib);
require 'stringio'
class RedisSubscribe < EM::Connection
def self.connect(host, port, pass = '')
Rails.logger.debug host
Rails.logger.debug port
client = EM.connect host, port, self
client.auth pass if pass.present?