This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
if (window.setImmediate) return; | |
var timeouts = []; | |
var messageName = "zero-timeout-message"; | |
// Like setTimeout, but only takes a function argument. There's | |
// no time argument (always zero) and no arguments (you have to | |
// use a closure). | |
function setZeroTimeout(fn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chart | |
@initAll: -> | |
Bar.init() | |
Spark.init() | |
@init: -> | |
for element in $(@selector) | |
do (element) => | |
setImmediate => | |
unless $(element).data('initialized') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'epath' | |
bom = "\xEF\xBB\xBF".force_encoding('binary') | |
Path.glob('**/*.rb') do |file| | |
next if file.binread(3) == bom | |
previous = file.binread | |
file.write bom + previous | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rvm_current=`rvm current` | |
echo "Installing ruby-debug with $rvm_current ..." | |
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem | |
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem | |
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem ruby-debug19 -- --with-ruby-include=$rvm_path/src/$rvm_current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.subclasses. | |
map {|model| model.reflections.values.select {|association| [:has_many, :has_one].include? association.macro }}.flatten. | |
each {|association| association.options[:dependent] = :destroy } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# heredocs are quite flexible | |
without_initial_indentation = <<-END.gsub(/^ {4}/, '') | |
foo | |
bar | |
foo | |
bar | |
END | |
# another example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get backtrace for each thread | |
# ruby 1.9 | |
Thread.list.map(&:backtrace) | |
# ruby enterprise edition | |
# http://www.rubyenterpriseedition.com/documentation.html#_obtaining_the_backtrace_of_all_threads | |
require 'thread' | |
caller_for_all_threads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# call methods like constants | |
module Foo | |
def self.bar | |
'tadam' | |
end | |
end | |
Foo::bar # => tadam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# power of extend | |
# can be used to add methods only to top-level object | |
module Rake | |
def task | |
:executed | |
end | |
end | |
extend Rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "python-like" import | |
load path, true # => will load new constants and methods under anonymous module | |
Module.nesting.first # => inside loaded file will return the current namespace | |
### | |
module PythonImport | |
def import(path) | |
load 'importer.rb', true |