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
require 'fiddle' | |
A = Class.new | |
B = Class.new | |
C = Class.new A | |
p C.superclass # => A | |
(Fiddle::Pointer[Fiddle.dlwrap C] + 16)[0, 8] = Fiddle::Pointer[Fiddle.dlwrap B].ref | |
p C.superclass # => B |
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
require 'eventmachine' | |
class Request < EM::P::HeaderAndContentProtocol | |
CRLF = "\r\n" | |
def receive_request(headers, body) | |
receive_full_request headers.join(CRLF) << CRLF*2 << body | |
end | |
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
require 'em-proxy' | |
Proxy.start host: '0.0.0.0', port: ENV['PORT'] do |connection| | |
connection.server :github, host: 'api.github.com', port: 443 | |
ok_response = "HTTP/1.1 200 Ok\r\n\r\n" | |
connect_verb = /\Aconnect/i | |
connection.on_data do |data| | |
if data =~ connect_verb |
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
cd $rvm_path/src/${MY_RUBY_HOME##*/}/ext/openssl | |
rvm pkg install openssl | |
ruby extconf.rb -- --with-openssl-dir="$rvm_path/usr" | |
make install | |
cd $rvm_path/usr/ssl | |
curl http://curl.haxx.se/ca/cacert.pem > cert.pem |
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
module A | |
# prefer when there are less than three class methods | |
# and there are instance methods | |
def self.boo | |
end | |
def self.soo | |
end | |
def fuuu |
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
# eval with method definition is used to prevent warnings in some situations | |
DEFINEE = <<-CODE | |
eval 'def __; end' | |
it = method(:__).owner rescue instance_method(:__).owner | |
eval 'undef __' | |
it | |
CODE | |
self # => main |
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
# Usually normalization is performed during `before_validation` | |
# or in a setter. But neither would help with normalization of | |
# where conditions. | |
# | |
# This will add `normalize` to ActiveRecord with support for | |
# where conditions. For example, | |
# | |
# class User | |
# normalize(:email) { email.downcase } | |
# 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
(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 |