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 LRUCache | |
def initialize(size = 10) | |
@size = size | |
@store = {} | |
@lru = [] | |
end | |
def set(key, value = nil) | |
value = yield if block_given? |
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 AppConfig | |
instance_methods.each { |m| undef_method m unless m =~ /^__|is_a\?|empty?/ } | |
def initialize | |
@hash = Hash.new do |hash, key| | |
hash[key] = AppConfig.new unless @finalized | |
end | |
end | |
def method_missing(message, value = nil) |
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
IDEA 1 | |
(1..100).each {|i| puts [i,('foo' if i%3==0),('bar' if i%5==0)].join} | |
IDEA 2 | |
(1..100).each {|i| puts "#{i}#{'foo' if i%3==0}#{'bar' if i%5==0}"} | |
(1..100).each{|i|puts"#{i}#{'foo'if i%3==0}#{'bar'if i%5==0}"} #shortened | |
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
def foo | |
2.times do |i| | |
puts yield | |
puts "We will go here #{i}" | |
end | |
end | |
foo do | |
next "Next is the block's return" | |
"Never returns this" |
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 'stringio' | |
class Progress | |
def initialize(show) | |
@device = StringIO.new unless show | |
end | |
def device | |
@device ||= $stdout |
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
File Pattern: | |
!\.(log)|\.(sp?)|(/\.(?!htaccess)[^/]*|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$ | |
Folder Pattern: | |
!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|db/data.*|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$ |
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
if Rails.env.development? | |
GROWL = Growl.new("127.0.0.1", "ruby-growl", ["ruby-growl Notification"]) | |
GROWL.class_eval do | |
def log(object) | |
GROWL.notify "ruby-growl Notification", "AskWhat Debug", object.inspect | |
Rails.logger.debug { object.inspect } | |
end | |
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 'java' | |
# setup executor | |
java_import 'java.util.concurrent.ThreadPoolExecutor' | |
java_import 'java.util.concurrent.TimeUnit' | |
java_import 'java.util.concurrent.LinkedBlockingQueue' | |
java_import 'java.util.concurrent.FutureTask' | |
java_import 'java.util.concurrent.Callable' | |
core_pool_size = 5 |
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 'rubygems' | |
require 'eventmachine' | |
require 'fiber' | |
class TcpReceiver < EM::Connection | |
attr_accessor :blocker | |
def initialize(receiver) | |
@receiver = receiver | |
super |
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 A | |
def self.hello | |
p 'hello' | |
end | |
def class | |
(class << self; self; end) | |
end | |
end |
OlderNewer