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 'active_record' | |
module ActsAsSplittable | |
def acts_as_splittable(options = {}) | |
options.reverse_merge!( | |
callbacks: true, | |
) | |
extend ClassMethods |
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 M1 | |
def nyan1 | |
run_callback(->(*args){ args.join }, '1', '2', '3') | |
end | |
private | |
def run_callback(callback, *args) | |
callback.(*args) | |
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() { | |
var Luhn = {}; | |
Luhn.valid = function(value) { | |
value = '' + value; | |
return this.generate(value.slice(- value.length, -1)) === value; | |
}; | |
Luhn.generate = (function() { |
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 'active_support' | |
module Definable | |
def definable(name) | |
define_method name do |value| | |
(const_get(:ClassMethods, false) rescue const_set(:ClassMethods, Module.new)) | |
.send(:define_method, name) { value } | |
send(:define_method, name) { self.class.send name } | |
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
OmniAuth.config.full_host = ->(env) { | |
scheme = if env['HTTPS'] == 'on' or env['HTTP_X_FORWARDED_SSL'] == 'on' | |
'https' | |
elsif env['HTTP_X_FORWARDED_PROTO'].present? | |
env['HTTP_X_FORWARDED_PROTO'].split(',').first.strip | |
else | |
env['rack.url_scheme'] | |
end | |
hostname = env['HTTP_X_FORWARDED_HOST'].present? ? env['HTTP_X_FORWARDED_HOST'] : env['HTTP_HOST'] |
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 'rack' | |
require 'net/http' | |
require 'uri' | |
pid = fork do | |
Rack::Handler::WEBrick.run ->(env){ [200, {'Content-Type' => 'plain/text'}, ['Nyan!']] }, Port: 9000 | |
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
#!/usr/bin/env ruby | |
require 'rack' | |
require 'net/http' | |
require 'uri' | |
unused_port = -> do | |
s = TCPServer.open(0) | |
port = s.addr[1] | |
s.close |
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 'rack' | |
require 'net/http' | |
require 'uri' | |
def request_test(request_timeout = 3) | |
unused_port = -> do | |
s = TCPServer.open(0) | |
port = s.addr[1] |
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
// その関数だけ実行するやつ | |
$.fn.onWithCall = function() { | |
var args = Array.prototype.slice.call(arguments), | |
listener = args[args.length - 1]; | |
return this.on.apply(this, args).each(function() { | |
listener.call(this, $.Event(args[0])); | |
}); | |
}; |