Skip to content

Instantly share code, notes, and snippets.

View jphastings's full-sized avatar
⌨️
Contracting at Yomly

JP Hastings-Edrei jphastings

⌨️
Contracting at Yomly
View GitHub Profile
@jphastings
jphastings / jsonp_helper.rb
Created September 17, 2012 16:49
JSONP helper for active record
# Now when you do `User.to_json(:jsonp => 'method')` you will get `method({id:1,username:'jphastings'})`
#
# Needs some sanitization of the javascript method name to prevent nastiness.
module ActiveSupport
# == Active Model JSON Serializer
module JSON
def self.encode(value,options = {})
if options.has_key?(:jsonp)
method_name = options.delete :jsonp
@jphastings
jphastings / 1. proposal.md
Created September 23, 2011 04:30
Proposal for sinatra 'view routes'

Sinatra View Routes

View routes would allow people to define different views for different devices without using any logic.

Anyone got any thoughts?

@jphastings
jphastings / explanation.markdown
Created July 15, 2011 05:50
Adding hashtags to headings - as an example (useless in the real world!)

This bookmarklet demonstrates adding IDs to headings, so that places on a page can be linked to directly.

Bookmark the following address in a non-IE browser (tested in Firefox) and click it when you're browsing a page with headings in the hub.

Then hover over a heading, and double click to change the URL in your browser bar to the one which will go straight to that point.

Bookmarklet:

javascript:(function(){$('h1,h2,h3,h4,h5,h6').each(function(i,e){try{var%20hash=%22%3E%22+$(e).first().text().replace(/[^a-zA-Z\%20]/g,'').replace(/%20/g,'_');$(e).attr('title','Double%20click%20to%20get%20the%20URL%20for%20this%20point%20on%20the%20page:%20%23'+hash);$(e).attr('id',hash);$(e).dblclick(function(){window.location.hash=hash;})}catch(e){}})})();

Problem with Sinatra-Template

I've forked sinatra-template and (having followed the instructions to install the required gems etc) immediately tried to rake db:migrate only to end up with the following error.

Any ideas what's going on? It looks like the problem lies with DataMapper, but I'm not having any luck bug hunting.

@jphastings
jphastings / Carnivore_in_Ruby_Processing.rb
Created January 25, 2011 20:35
Carnivore in Ruby Processing
require 'ruby-processing'
class ProcessingTest < Processing::App
load_library 'carnivore'
require 'packet_listener'
include Java::PacketListener
def setup
@carnivore = org.rsg.carnivore.CarnivoreP5.new(self)
@jphastings
jphastings / cattr_accessor.rb
Created October 29, 2010 17:25
Use cattr_accessor, reader and writer without active_support
class Class
def cattr_accessor(*syms)
cattr_reader(*syms)
cattr_writer(*syms)
end
def cattr_reader(*syms)
syms.flatten.each do |sym|
class_eval("unless defined? @@#{sym}\n@@#{sym} = nil\nend\n\ndef self.#{sym}\n@@#{sym}\nend\n\ndef #{sym}\n@@#{sym}\nend\n", __FILE__, __LINE__)
end
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.10 (Darwin)
mQMuBEzAn6ERCACLSb2NlvVmKa8zcFE+GsAY9iRiI1wux+ZtxCspO/Qv9hvxolKw
osPX1GfJx8p9XOSm5EqqlTcrO1mJw8Xl1cthNSMX1ZGW9LnDsSzXdf2EMYy3ZvDG
DNsMJ/WTdRaBeMtYAZbWe2OrjOEslW0eMDHcwKyiWGmP/OsnrAp8NRf/BR2w5wOd
lNtdCnAzwhKudWfAmdoIMNzydDj/2ylPlj33A3xqvC/h68a3HfODkypo1rQ0j1CH
B34gWHUIBiLhRcqF58cmYVzWhNbamdHkbMbgSz+x449hrqsUY5yvkoNyKevCfHMY
YQT5N2sC9SKxjImvraZ+A+G/TI/8IHzzP3B/AQDyNbgSwE1BK+tjl7fdcLC1hqTz
hZJaLdrfMR8hYeDL4wf/Sx2uIFX1Sx/AwpPVzCFTZxnAWHpsb3uGCuBxurHbH2LB

Problem

Clicking on 'Lightbox' link opens the lightbox - but the link inside the lightbox isn't clickable.

Any ideas?

@jphastings
jphastings / 1.readme.md
Created September 22, 2010 22:41
Got bored, wrote a Yaml parser (ish) in javascript.

Usage

console.log(YAML.eval("Yaml!"))

New features

  • Now does comments (& --- lines)
  • Deals with booleans (yes, no, true, false)
  • Handles multi-line strings (both types!)
  • Single-line hashes now supported
Johnson::Error: setting a property that has only a getter
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:2702 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:2134 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:2168 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:3261 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:1464 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:1808 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:1815 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:252 [JavaScript]
from /Users/jp/Downloads/rightjs-200-rc2/javascripts/right-src.js:3615:in `event_support_for' [JavaScript]