This file contains hidden or 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
#encoding: utf-8 | |
# Patches async sinatra to use Fiber.new{}.resume for every request | |
require "sinatra/async" | |
require "fiber" | |
module Sinatra | |
module Async | |
module Helpers |
This file contains hidden or 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
set timeout 5 | |
spawn telnet [lindex $argv 0] [lindex $argv 1] | |
expect "Connected" | |
send "PING\n" | |
expect "+PONG" | |
send "QUIT" | |
#usage: expect redis.expect <host> <port> |
This file contains hidden or 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-redis' | |
require 'redis' | |
require 'redis/distributed' | |
require "fiber_pool" | |
class Redis | |
class Distributed | |
def initialize(urls, options = {}) | |
@tag = options.delete(:tag) || /^\{(.+?)\}/ |
This file contains hidden or 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
echo -e ".backup\nlogs\nvendor" | xargs -d# -Ixx svn propset svn:ignore 'xx' . --recursive |
This file contains hidden or 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 'mysql2' | |
require 'mysql2/em' | |
class MysqlConnectionPool | |
def initialize(conf) | |
@pool_size = conf[:size] || 10 | |
@connections = [] | |
@query_queue = EM::Queue.new | |
start_queue conf |
This file contains hidden or 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
str.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse |
This file contains hidden or 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 'hpricot' | |
require 'open-uri' | |
doc = open('http://www.articlesbase.com/investing-articles/tips-for-successful-private-placement-trading-4339216.html') {|f| Hpricot(f)} | |
doc.search("script").remove | |
doc.search("style").remove | |
puts doc.search("body").text |
This file contains hidden or 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
// definition | |
$.fn.customFunction = function(options) { | |
var defaults = { | |
width: 650, | |
height: 450 | |
}; | |
var opts = $.extend(defaults, options); | |
var self = $(this[0]); // if working on first/single element | |
// functionality here |
This file contains hidden or 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
var self = $('#mydiv'); | |
// define | |
self.unbind('my-event'); | |
self.bind('my-event', function() {alert('yes')}); | |
// trigger | |
self.trigger('my-event'); |
This file contains hidden or 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
#usage | |
a = [1,2] | |
b = [1,nil] | |
a.extend(ArrayWithNilCompareHack) | |
b.extend(ArrayWithNilCompareHack) | |
a<=>b # works | |
# code | |
module ArrayWithNilCompareHack | |
def <=>(other) |
OlderNewer