Skip to content

Instantly share code, notes, and snippets.

View danielevans's full-sized avatar

Daniel Evans danielevans

  • Anfract
  • Seattle, WA
View GitHub Profile
@danielevans
danielevans / create_callback.js
Created March 12, 2012 18:12
Bindings Problem
//This responds to a click in the DOM
var newList = App.List.createRecord({});
if(newList.get("valid")) {
newList.store.commit();
} else {
// my most recent attempt to prevent the bindings
App.store.deleteRecord(newList);
@danielevans
danielevans / output.txt
Created March 16, 2012 21:46
capybara-webkit pushState issue demonstration
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
http://127.0.0.1:54850/
/
--------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
http://127.0.0.1:54850/
/
--------------------------------------------------------------------------------
@danielevans
danielevans / gist:2416927
Created April 18, 2012 22:06
A Shim for allowing jQuery UI to handle touch events for sortable/draggable
/*
* Content-Type:text/javascript
*
* A bridge between iPad and iPhone touch events and jquery draggable,
* sortable etc. mouse interactions.
* @author Oleg Slobodskoi
*
* modified by John Hardy to use with any touch device
* fixed breakage caused by jquery.ui so that mouseHandled internal flag is reset
* before each touchStart event
puts "Hello World!"
@danielevans
danielevans / gist:2563717
Created April 30, 2012 23:49
prototype test in therubyracer
therubyracer> Person.prototype.test = function() { return "hello world"; }
function () { return "hello world"; }
therubyracer> var Hippo;
therubyracer> Hippo = Person.prototype.constructor;
function () {}
therubyracer> var mystery = new Hippo();
therubyracer> mystery.test();
hello world
therubyracer> mystery instanceof Hippo
true
@danielevans
danielevans / model_json.rb
Created June 6, 2012 19:23
Converting Serialized YAML to Serialized JSON in Rails models
class Medium < ActiveRecord::Base
serialize :payload, JSON
end
Run filtered excluding {:skip_on_windows=>false}
...............F..................................F..F.FF............FF....................F..............................................F.....................................FF..........................F.............FFFF........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Failures:
1) Capybara::Driver::Webkit::Browser#set_proxy uses URLs changed by javascript
Failure/Error: browser.requested_url.should == 'http://example.org/blah'
expected: "http://example.org/blah"
got: "http://example.org/" (using ==)
# ./spec/br
@danielevans
danielevans / decoder.rb
Created July 8, 2012 05:31
String decoder in Ruby
# build a hash that links number to char, so { "1" => "a", "2" => "b", ... }
CODES = (0..25).reduce Hash.new do |memo, code|
memo[(code + 1).to_s] = (code + 'a'.ord).chr
memo
end
# recursive method
def decode(str)
# terminal case if the string given is empty
@danielevans
danielevans / gist:3352015
Created August 14, 2012 19:31
Weechat helper
def yourls_shorten(url)
# use yourls shortener
# need to provide url config option
require 'rubygems'
require 'json/pure'
params = ['action=shorturl']
params << 'format=simple'
params << 'url=' + URI.encode(url)
yourls_url = Weechat.config_get_plugin('yourls_url')
api_url = [yourls_url, params.join('&')].join(yourls_url.include?('?') ? '&' : '?')
(0..25).to_enum.reduce({}) do |memo,i|
memo[(i + 'a'.ord).chr] = i + 1
memo
end