Skip to content

Instantly share code, notes, and snippets.

http://www.mikeperham.com/2010/11/22/the-ruby-stdlib-is-a-ghetto/
http://architecturalatrocities.com/post/23659800703/the-ruby-standard-library-is-a-disgrace
http://apocryph.org/archives/579
http://devblog.avdi.org/2015/09/04/poll-whats-your-favorite-ruby-http-client-library/
http://www.jstorimer.com/pages/ruby-core-classes-arent-thread-safe
http://iamserg.io/writings/2014/queue-and-sized-queue/
http://blog.skylight.io/bending-the-curve-writing-safe-fast-native-gems-with-rust/
https://robm.me.uk/ruby/2014/01/25/pstore.html
http://www.rubydoc.info/stdlib/set
require "./src/benchmark"
def repetition1(ary, times)
ary = typeof(ary).new(ary.length * times)
times.times do
ary += ary
end
ary
end
@porras
porras / log.txt
Created May 6, 2015 12:44
Compiling Crystal 0.7.1 with Crystal 0.6.1 in Mac OSX 10.8.5
$ ~/Downloads/crystal-0.6.1-1/bin/crystal
Usage: crystal [command] [switches] [program file] [--] [arguments]
Command:
build compile program file
browser open an http server to browse program file
deps install project dependencies
docs generate documentation
eval eval code
hierarchy show type hierarchy
@porras
porras / gist:e8604cb46c710244a948
Last active August 29, 2015 14:19
Lazy comprehension
def comprehend(*enums)
cycles = enums.map(&:cycle)
Enumerator.new do |comprehended|
loop do
value = cycles.map(&:peek)
value = yield value if block_given?
comprehended << value
(cycles.length - 1).downto(0) do |index|
cycles[index].next
@porras
porras / gist:75926319d9e157fd4000
Created November 6, 2014 16:18
Wrapping an object that reads in a wrapper you can write to
class ObjectThatInsistsOnCallingRead
def initialize(io)
while s = io.read(10)
print s
end
end
end
class WrapperToWhichYouCanWrite
def initialize
@porras
porras / config.ru
Created October 2, 2014 13:35
Run your objects as web apps in an insanely decoupled way
class Object
def to_app
lambda do |env|
_, method, args = env['REQUEST_PATH'].split('/')
[200, {}, [self.send(method, *args).to_s]]
end
end
end
class HelloWorld
@porras
porras / gist:5d4010a254635cedbb6e
Created August 19, 2014 07:59
Fun with dates
>> require 'date'
=> true
>> Date.today.next_month
=> #<Date: 2014-09-19 (4913839/2,0,2299161)>
>> Date.today.next_month - 1
=> #<Date: 2014-09-18 (4913837/2,0,2299161)>
>> Date.today.next_month -1
=> #<Date: 2014-07-19 (4913715/2,0,2299161)>
class A
private
def self.a
:a
end
end
class B
class << self
irb(main):001:0> class A; private; attr_reader :a; end
=> nil
irb(main):002:0> A.new.a
NoMethodError: private method `a' called for #<A:0x007fbbca0403c0>
from (irb):2
from /Users/sergiogil/.rbenv/versions/1.9.3-p448/bin/irb:12:in `<main>'
class FancyDSL
def initialize(&block)
instance_eval(&block)
end
def setup(value)
@setup = value
end
end