Skip to content

Instantly share code, notes, and snippets.

View ndbroadbent's full-sized avatar

Nathan Broadbent ndbroadbent

View GitHub Profile
@ndbroadbent
ndbroadbent / skype-libnotify.sh
Created March 24, 2012 11:03
Skype notifications using libnotify on Linux
#!/bin/bash
if [ "$1" = "--help" ]; then
echo "Usage: $0 <skype username> (if omitted, will detect default username)"
exit 1
fi
if [ -n "$1" ]; then
# skype username from arg
skype_username="$1"
~/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:3030358
Created July 2, 2012 01:16
Tiny Umbrella Crash
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.semaphore.os.UIHandlerManager.getSystemUIHandler(UIHandlerManager.java:22)
at com.semaphore.TinyUmbrella.<clinit>(TinyUmbrella.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.semaphore.TinyLoader.loadTiny(TinyLoader.java:248)
at com.semaphore.TinyLoader.access$000(TinyLoader.java:29)
at com.semaphore.TinyLoader$1.run(TinyLoader.java:42)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
@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 / deploy.rake
Created September 28, 2012 22:18
Rake task for precompiling assets locally before deploying to Heroku
require 'fileutils'
# Warning: The following deploy task will completely overwrite whatever is currently deployed to Heroku.
# The deploy branch is rebased onto master, so the push needs to be forced.
desc "Deploy app to Heroku after precompiling assets"
task :deploy do
deploy_branch = 'heroku'
remote = 'heroku'
deploy_repo_dir = "tmp/heroku_deploy"
@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
@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.