Skip to content

Instantly share code, notes, and snippets.

@jspillers
jspillers / input.png
Created June 29, 2011 13:32
Solution for codebrawl PNG pixelation challenge
input.png
#var $context, $input, $shadow, current_tags, tag_name, template, view;
initialize: () ->
template = $('script.tag_mustache').html()
$context = $('span.tagging_container')
$hidden_input = $context.find('.tags_value')
if $context
$shadow = $context.find('.input_shadow')
$input = $context.find('.tag_input')
@jspillers
jspillers / backbone.rails.js
Created December 1, 2011 23:52 — forked from tmarek/backbone.rails.js
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
@jspillers
jspillers / backbone_sync_hack.coffee
Created December 2, 2011 00:17 — forked from jumski/backbone_sync_hack.coffee
BackboneJS sync hack to namespace params when saving/updating model
###
Usage:
* add model.name property that will be used as a namespace in the json request
* put this code before your Backbone app code
* use toJSON() as usual (so there is no namespacing in your templates)
* your model's data will be sent under model.name key when calling save()
###
# save reference to Backbone.sync
Backbone.oldSync = Backbone.sync
@jspillers
jspillers / run_spec_multiple.rb
Created January 19, 2012 16:48
run specs multiple times with truncated output
#!/usr/bin/env ruby
ARGV[0].to_i.times do |i|
puts "run #{i+1}"
result = `rake SPEC=#{ARGV[1]}`
puts result.match(/(Finished in \d+.\d+ seconds)/)[1]
puts result.match(/(\d+ examples, \d+ failures?)/)[1]
if result.match(/Failed examples:/)
puts ''
puts 'Failed examples:'
require 'rest_client'
def import(service_url, uri, data)
JSON.parse(
RestClient.post(
"#{service_url}#{uri}",
data.to_json,
content_type: :json,
accept: :json
)
>> hsh = { :foo => ->(x){ {x: x } }}
=> {:foo=>#<Proc:0x007ff2c20320c0@(irb):9 (lambda)>}
>> hsh[:foo]
=> #<Proc:0x007ff2c20320c0@(irb):9 (lambda)>
>> hsh[:foo].call('qwerasdf')
=> {:x=>"qwerasdf"}
@jspillers
jspillers / vcr_webmock_and_live_http_simultaneously.rb
Created June 9, 2015 20:13
Sandbox test to get VCR, WebMock, and "real" http all working side by side in the same spec suite
require 'rubygems'
require 'rspec'
require 'webmock'
require 'vcr'
require 'pry'
# in a Rails app, this would be in an initializer
WebMock.disable_net_connect!(
allow_localhost: true,
net_http_connect_on_start: true
@jspillers
jspillers / gtk3_error.sh
Created June 12, 2015 17:17
gtk3 error when requiring gem
➜ ruby gtk3_test.rb
/Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-13/2.2.0-static/glib2-2.2.5/glib2.bundle, 9): Library not loaded: @@HOMEBREW_PREFIX@@/opt/gettext/lib/libintl.8.dylib (LoadError)
Referenced from: /Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-13/2.2.0-static/glib2-2.2.5/glib2.bundle
Reason: image not found - /Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-13/2.2.0-static/glib2-2.2.5/glib2.bundle
from /Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/glib2-2.2.5/lib/glib2.rb:105:in `rescue in <top (required)>'
from /Users/jarrod/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/glib2-2.2.5/lib/glib2.rb:101:in `<top (required)>'
from /Users/jarrod/.rbenv/version