Skip to content

Instantly share code, notes, and snippets.

View ndbroadbent's full-sized avatar

Nathan Broadbent ndbroadbent

View GitHub Profile
@ndbroadbent
ndbroadbent / .gitattributes
Created January 11, 2012 08:35 — forked from tpope/.gitattributes
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundleinstall
db/schema.rb merge=railsschema
@ndbroadbent
ndbroadbent / readme.md
Created January 31, 2012 02:52 — forked from mislav/readme.md
CLI tool that checks the build status of current branch on Travis CI

Check build status of a project on the command line

Install (copy & paste):

curl -sL https://raw.github.com/gist/1708408/travis.rb > ~/bin/travis-ci \
  && chmod +x ~/bin/travis-ci

gem install hub | tail -2
ruby -e 'require "json"' 2>/dev/null || gem install json
~/code/rails/fat_free_crm [cloudfuji±|1.9.3p194]$ tane event customer created "{:email => 'cordies@gmail.com'}"
{"category"=>"customer", "event"=>"created", "data"=>{:email=>"cordies@gmail.com"}}
/home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 404 Resource Not Found (RestClient::ResourceNotFound)
from /home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
from /home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
from /home/masha/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
from /home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
from /home/masha/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from
@ndbroadbent
ndbroadbent / gist:3494714
Created August 28, 2012 03:31
Stack trace for Capybara / Selenium / ChromeDriver
Failure/Error: Unable to find matching line from backtrace
Timeout::Error:
Timeout::Error
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
# /home/ndbroadbent/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
@ndbroadbent
ndbroadbent / precompile_static_pages.rake
Created October 10, 2012 21:56
Rake task to precompile static pages in app/views/static/ folder
module StaticHelpers
def action_for_template(template)
File.basename(template).sub(/\.html\.haml$/, '')
end
end
namespace :static do
desc "Precompile static pages at public/*.html"
task :precompile do
include StaticHelpers
@ndbroadbent
ndbroadbent / gist:3910785
Created October 18, 2012 09:48
Lamda Calculus question
This was one of the winners of the recent International Obfuscated C Code Contest: http://www.ioccc.org/2012/tromp/hint.html
(code at http://www.ioccc.org/2012/tromp/tromp.c)
It's a [Binary Lambda Calculus](http://en.wikipedia.org/wiki/Binary_lambda_calculus) implementation, and it's absolutely incredible. I'm no computer scientist, but he wrote a program that can run an implementation of itself in only 29 bytes.
One of the example lambda calculus programs was:
\a a ((\b b b) (\b \c \d \e d (b b) (\f f c e))) (\b \c c)
... which is assembled into the following BLC code:
@ndbroadbent
ndbroadbent / rails
Created December 20, 2012 00:51
script/rails with --editor option
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
# Add --editor option to open generated files in editor
# -----------------------------------------------------
module Rails
module Generators
@ndbroadbent
ndbroadbent / json_munging_patch.rb
Created February 12, 2013 00:24
Save this to config/initializers/json_munging_patch.rb until https://github.com/rails/rails/pull/8862 or an alternative fix is merged.
# Patch from https://github.com/rails/rails/pull/8862
module ActionDispatch
Request.class_eval do
# Remove nils from the params hash
def deep_munge(hash)
hash.each do |k, v|
case v
when Array
module Sq
class Template < Sequel::Model
one_to_many :fields
def mapped_template_ids
FieldMapping.as(:m).
join(Field.named(:f), id: :field_id, template_id: id).
join(Field.named(:mf), id: :m__mapped_field_id).
distinct.select_map(:mf__template_id)
end
@ndbroadbent
ndbroadbent / gist:5097601
Last active April 29, 2016 02:35
Wrap jQuery events and callbacks with try...catch blocks. Original code from: https://github.com/airbrake/airbrake-js/blob/master/src/notifier.js#L173
/*
* Add hook for jQuery.fn.on function, to manualy call window.Airbrake.captureException() method
* for every exception occurred.
*
* Let function 'f' be binded as an event handler:
*
* $(window).on 'click', f
*
* If an exception is occurred inside f's body, it will be catched here
* and forwarded to captureException method.