Skip to content

Instantly share code, notes, and snippets.

View pabloh's full-sized avatar

Pablo Herrero pabloh

  • Buenos Aires, Argentina
View GitHub Profile
# Set up pool
SharedPool = Concurrent::ThreadPoolExecutor.new(
:max_threads => 50,
:idletime => 10.minutes
)
# Worker thread
results = inputs.map do |input|
Concurrent::Future.execute_on(SharedPool) { DB.run_some_query(input) }
end.map(&:value!)
@pabloh
pabloh / uber_raise.rb
Last active August 29, 2015 14:27
Resume from exception
class UberException < Exception
attr_reader :source
def initialize(source, context)
@source, @context = source, context
end
def resume(val = nil)
@context.call val # Method context lost: LocalJumpError
end
@pabloh
pabloh / gist:5107526
Last active December 14, 2015 15:28
Keyword arguments on Ruby 2.0
# Ruby 2.0.0 is needed for the following code to work
def foo value, **keywords
puts [value,keywords].inspect
end
foo("somthing") #This works
foo("somthing", key: 'value') #This also works
foo(Hash.new(something: 'else')) #This raises 'ArgumentError: wrong number of arguments (0 for 1)'
" Vim color scheme
" Name: vividchalk.vim
" Author: Tim Pope <vimNOSPAM@tpope.info>
" Version: 2.0
" GetLatestVimScripts: 1891 1 :AutoInstall: vividchalk.vim
" Based on the Vibrank Ink theme for TextMate
" Distributable under the same terms as Vim itself (see :help license)
if has("gui_running")
# Instant result methods w/block (and different arities)
[ [ %w[partition group_by sort_by min_by max_by minmax_by
any? one? all? none?], ""],
[ %w[each_slice each_cons each_with_object], "arg" ],
[ %w[each_with_index reverse_each each_entry find
detect find_index], "*args"] ].each do |methods, arguments|
methods.each do |method|
class_eval <<-METHOD_DEF
def #{method} #{arguments}