Skip to content

Instantly share code, notes, and snippets.

@enriquez
enriquez / client_socket.coffee
Created April 4, 2011 21:47
Socket.IO wrapper using Microevent for binding/triggering custom events.
class ClientSocket
constructor: () ->
@socket = new io.Socket()
@socket.connect()
@socket.on 'connect', =>
this.trigger('connect.server', null)
@socket.on 'message', (response) =>
this.trigger(response.trigger, response.payload)
@socket.on 'disconnect', =>
this.trigger('disconnect.server', null)
Migrate Heroku app to 1.9.2
http://devcenter.heroku.com/articles/bamboo
> heroku stack:migrate bamboo-mri-1.9.2
> heroku config:add BUNDLE_WITHOUT="development:test"
require 'test/unit'
class Frame
attr_reader :rolls
def initialize(first_roll)
@rolls = [first_roll]
end
def << pins
Factory.define :post do |post_factory|
post_factory.user { Factory.build(:user) }
end
// inserting HTML that contains a script that contains document.write
$('a').first().html('<script>document.write("hey! don't be broken")</script>');
if (window.___dialogEncountered === undefined) {
window.___dialogEncountered = false;
}
if (window.___dialogReturnValue === undefined) {
window.___dialogReturnValue = false;
}
window.___dialogHandler = function(dialogType) {
window.parent.___dialogEncountered = dialogType;
require 'cucumber/step_definition_light'
class StepUsage
class StepDefKey < Cucumber::StepDefinitionLight
end
def initialize(step_mother, io, options)
@step_mother = step_mother
@io = io
@stepdef_to_match = Hash.new{|h,stepdef_key| h[stepdef_key] = []}
MySQL commands
mysql> create database [database_name];
mysql> show databases;
CREATE BACKUP
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
RESTORE BACKUP
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
module NumberFormat
def to_comma_separated
self.to_s.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
end
end
class Integer
include NumberFormat
end
class Float