Skip to content

Instantly share code, notes, and snippets.

View scottwb's full-sized avatar

Scott W. Bradley scottwb

View GitHub Profile
# Don't you feel like doing something like this when you use Ripple?
# Obviously there's more to it than this mockup, but man this would
# be nice, wouldn't it?
module Ripple
class Document
def self.method_missing(method, args)
if method.to_s =~ /^find_by_(.*)$/
return find_by_index($1.to_sym, *args)
end
super
# Generate a token by looping and ensuring does not already exist.
def generate_token(column)
loop do
token = Devise.friendly_token
break token unless to_adapter.find_first({ column => token })
end
end
signature = ""
signature << "id=#{id}"
signature << "carrier=#{carrier}"
signature << "wireless_number=#{wireless_number}"
signature << "status=#{status}"
signature << "secret=#{PUBLICATION_SECRET}"
signature = Digest::SHA1.hexdigest(signature)
puts signature
@scottwb
scottwb / chef-errors.sh
Created August 31, 2012 18:39
Hosted Chef Errors
swb-mbp% knife cookbook upload apache2
Uploading apache2 [1.1.12]
/Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/openssl/buffering.rb:174:in `sysread_nonblock': Connection reset by peer (Errno::ECONNRESET)
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/openssl/buffering.rb:174:in `read_nonblock'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
from /Users/scottwb/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
{
"candidate" : {
// Required Fields
"firstName" : "Scott",
"lastName" : "Bradley",
"email" : "scottwb@example.com",
"currentPosition" : "VP of Engineering",
"currentCompany" : "Validas, LLC",
"location" : "Kirkland, WA",
"message" : "You should hire me because...", // markdown
{
// Required Fields
"firstName" : "Scott",
"lastName" : "Bradley",
"email" : "scottwb@example.com",
"currentPosition" : "VP of Engineering",
"currentCompany" : "Validas, LLC",
"location" : "Kirkland, WA",
"message" : "You should hire me because...", // markdown
"resume" : "http://...",
swb-mbp% curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"candidate":{"firstName":"Scott","lastName":"Bradley","email":"scottwb@validas.com","currentPosition":"VP of Engineering","currentCompany":"Validas, LLC","location":"Kirkland, WA","message":"You should hire me because...","resume":"http://....","position":"linux","twitter":"@scottwb69","github":"scottwb","website":"http://scottwb.com/","blog":"http://scottwb.com/","otherLink1":"http://foo.com/","otherLink2":"http://bar.com/","test":true}}' http://jobsapi.validas.com/candidates.json
* About to connect() to jobsapi.validas.com port 80 (#0)
* Trying 23.22.208.238... connected
* Connected to jobsapi.validas.com (23.22.208.238) port 80 (#0)
> POST /candidates.json HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: jobsapi.validas.com
> Accept: application/json
> Content-type: application/json
> Content-Length: 444
wb-mbp% whereis gcc
/usr/bin/gcc
swb-mbp% gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
swb-mbp% /usr/bin/gcc-4.2 --version
i686-apple-darwin11-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
namespace :coffee do
task :compile, :filename do |t, args|
filename = args.filename
puts CoffeeScript.compile(File.open(filename))
end
end
@scottwb
scottwb / addthis_hack.js
Created June 10, 2012 15:40
Hack around URL hash conflicts between jQuery Mobile and AddThis
// Gracefully handle AddThis hashes with jQuery Mobile
$(function() {
if (window.location.hash != '') {
window.location.href = window.location.href.split('#')[0];
}
});