Skip to content

Instantly share code, notes, and snippets.

@gotascii
gotascii / hrm.rb
Created February 10, 2012 20:06
Hm
next unless delivery_message =
begin
Message.find_by_id(message.id)
rescue SecurityContextException => ex
logger.warn{ "message_broadcaster Could not load message #{message.id} for user #{subscription.user.id}" }
end
if subscription.client.delivery_appropriate?(delivery_message)
# logger.debug{ "SENDING mid: #{message.id} to uid:#{subscription.client.user_id} client_id:#{subscription.client}" }
subscription.client.deliver_message(delivery_message)
else
@gotascii
gotascii / Cakefile
Created September 14, 2011 13:35
Node in Max/MSP
# Compile the coffee in bare joined mode.
{exec, spawn} = require 'child_process'
fs = require 'fs'
util = require 'util'
print = (data) ->
console.log data.trimRight()
task 'build', 'Compile Coffeescript to Javascript', ->
@gotascii
gotascii / quiz.js
Created April 28, 2011 12:39
javascript quiz question
function House() {
this.vandalize = function() {
this.vandalized = true;
}
}
function Punk() {
this.onParty = function(handler) {
this.handler = handler;
}
@gotascii
gotascii / stubs.js
Created April 25, 2011 11:37
simple node stubs
stubs = []
module.exports =
stub: (obj, name, fun) ->
stubs.push({'obj':obj, 'name':name, 'fun':obj[name]})
obj[name] = if fun? then fun else ->
unstub: ->
for stubbed in stubs
stubbed.obj[stubbed.name] = stubbed.fun
stubs.length = 0
@gotascii
gotascii / rrt
Created April 14, 2011 18:01
command-line rails test runner
#!/usr/bin/env ruby
def run_testunit(runner, path)
path = path.gsub(/\/?test\/?/, '')
path.gsub!(/_test.rb/, '')
exec "#{runner} -I'test' test/#{path}_test.rb"
end
def run_unit(runner)
run_testunit runner, "unit/#{ARGV[1]}"
@gotascii
gotascii / campfire.rb
Created March 22, 2011 15:00
cap recipe to notify campfire on deploy
require 'uri'
require 'tinder'
class Campfire
attr_reader :config
def initialize(config)
@config = config
end
@gotascii
gotascii / simple_deployer.rb
Created March 22, 2011 14:46
cc.rb auto-deployer
# This plugin will deploy your app using capistrano.
# If the build fails the app won't de be deployed and if it passes it will try to deploy to a list of stages you can supply.
#
# Configuration
# In your project's cruise_config.rb file:
#
# Pass an array of stages you want to deploy to
# project.cap_deployer.stages = ['integration', 'staging']
#
# source ~/.rvm/scripts/rvm before deployment?
def PostsController < ActionController::Base
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path
else
render :action => "new"
end
end
class String
def named_matches(rx)
m = rx.match(self)
[Hash[m.names.collect{|n| [n, m[n]]}]]
end
end
Object.prototype.inspect = function () {
function pad(depth) {
return Array(depth).join(" ");
}
function down(attr, val, depth) {
var output = pad(depth) + attr + ': ';
output += (typeof(val) == 'object' ? "{" : val);
return output + "\n";
}