Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
@jimsynz
jimsynz / das-0050-shorter-class-syntax.rb
Created April 5, 2012 02:50
Response to das-0050-shorter-class-syntax.mov
class UClass
def self.<(*keys)
define_method(:initialize) do |*args|
keys.each_with_index do |key,i|
instance_variable_set("@#{key}".to_sym,args[i])
end
end
self
end
def self.>(method,&block)
Error: In features/step_definitions/inMemoryAdapter.coffee, Parse error on line 10: Unexpected 'POST_IF'
at Object.parseError (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:473:11)
at Object.parse (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:522:22)
at Object.compile (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:43:20)
at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:182:33
at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:152:18
at [object Object].<anonymous> (fs.js:123:5)
at [object Object].emit (events.js:64:17)
at Object.oncomplete (fs.js:1181:12)
TypeError: Object #<World> has no method 'visit'
at World.<anonymous> (/Users/jnh/Dev/ember-newsflash/features/step_definitions/inMemoryAdapter.coffee:8:19)
at Object.invoke (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:29:14)
at Object.execute (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/ast/step.js:142:22)
at Object.acceptVisitor (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/ast/step.js:133:12)
at Object.executeStep (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:170:12)
at Object.processStep (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:165:14)
at /Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:67:16
at callUserFunctionAndBroadcastAfterEvent (/Users/jnh/Dev/ember-newsflash/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:91:9)
class LongPoller
def self.go(&block)
self.new(block)
end
def initialize(block)
@block = block
end
def each(&sender)
EM.defer do
sender.call @block.call
@jimsynz
jimsynz / vault.html
Created June 22, 2012 03:29
@jcoglan's Vault project as a squashed html file for quick downloads and cacheability.
<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0"><title>Vault</title><script type="text/javascript">var CryptoJS=CryptoJS||function(e,t){var n={},r=n.lib={},i=r.Base=function(){function e(){}return{extend:function(t){e.prototype=this;var n=new e;return t&&n.mixIn(t),n.$super=this,n},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.$super.extend(this)}}}(),s=r.WordArray=i.extend({init:function(e,n){e=this.words=e||[],this.sigBytes=n!=t?n:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,e=e.sigBytes;this.clamp();if(r%4)for(var i=0;i<e;i++)t[r+i>>>2]|=(n[i>>>2]>>>24-8*(i%4)&255)<<24-8*((r+i)%4);else if(65535<n.le
@jimsynz
jimsynz / why.md
Created June 25, 2012 23:12
Hamlbars nested conditions

You wrote:

= hb 'if content.condition1' do
  = hb 'if content.condition2' do
    %p Some paragraph
    = hb 'else'
      %p another paragraph
  = hb 'else'
 %p third paragraph
[21:01][jnh@Bucket]~/Dev/bw-midi(master)$ rake spec --trace
** Invoke spec (first_time)
** Execute spec
** Invoke simulator (first_time)
** Invoke build:simulator (first_time)
** Execute build:simulator
/usr/bin/env VM_KERNEL_PATH="/Library/RubyMotion/data/5.1/iPhoneSimulator/kernel-i386.bc" /Library/RubyMotion/bin/ruby --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/RubyMotion.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/CoreGraphics.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/CoreFoundation.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/CoreMIDI.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/Foundation.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/MobileCoreServices.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/CFNetwork.bridgesupport" --uses-bs "/Library/RubyMotion/data/5.1/BridgeSupport/SystemConfiguration.bridgesupport" --uses-bs "/Library/RubyMotion/dat
Welcome to the Ruby Enterprise Edition installer
This installer will help you install Ruby Enterprise Edition 1.8.7-2012.02.
Don't worry, none of your system files will be touched if you don't want them
to, so there is no risk that things will screw up.
You can expect this from the installation process:
1. Ruby Enterprise Edition will be compiled and optimized for speed for this
system.
2. Ruby on Rails will be installed for Ruby Enterprise Edition.
@jimsynz
jimsynz / qu_em_worker.rb
Created August 24, 2012 07:15
Qu worker that uses EventMachine.
class QuEmWorker < Qu::Worker
def start
EM.next_tick do
Thread.new do
logger.warn "Worker #{id} starting"
Qu.backend.register_worker(self)
EM.add_shutdown_hook do
Qu.backend.unregister_worker(self)
logger.debug "Worker #{id} done"
@jimsynz
jimsynz / impl.rb
Created September 18, 2012 22:01
This may seem like a contrived example but it comes from the moustache compatibility tests in Handlebars.js' acceptance suite.
require 'flavour_saver'
# User's helper code:
FS.register_helper(:link) do |prefix,&block|
"<a href='#{prefix}/#{url}'>#{text}</a>"
end
Link = Struct.new(:url, :text)
Context = Struct.new(:prefix, :links)