Skip to content

Instantly share code, notes, and snippets.

View felixyz's full-sized avatar

Felix Holmgren felixyz

View GitHub Profile
@felixyz
felixyz / gist:5788285
Created June 15, 2013 14:15
Creating and running >120 Celluloid::IO actors raises an error on MRI, even when doing NO I/O
# Running on OS X
# JRuby + Celluloid = OK
# MRI + Celluloid = OK
# JRuby + Celluloid::IO = OK
# MRI + Celluloid::IO = Too many open files - pipe (Errno::EMFILE)
require 'celluloid/io'
class SimpleActor
# include Celluloid # Creating regular Celluloid actors works on MRI
@felixyz
felixyz / celluloid_redis_bug.rb
Last active December 18, 2015 10:59
This illustrates celluloid-redis issue #9: https://github.com/celluloid/celluloid-redis/issues/9 A repo containing the below code and branches with variations that variously provoke the same bug or not can be found here: https://github.com/Felixyz/celluloid-redis-bug
require 'thread'
require 'celluloid/io'
require 'celluloid/redis'
KEY = "magic_key"
VALUE = {a: 1, b:2}
class RedisActor
include Celluloid::IO
@felixyz
felixyz / gist:5679768
Created May 30, 2013 17:57
Use Queue to keep synchronous interface while performing work in parallel. Queue is thread-safe, and extremely easy to use!
require 'thread'
def provider()
threads = []
queue = Queue.new
1.upto(10).each do |n|
threads << Thread.new {
sleep rand(0.1..2)
queue << n
}
@felixyz
felixyz / crash_burn_symbols.rb
Last active December 13, 2015 17:38
Crash caused by archiving/dearchiving symbols in RubyMotion. I can't get an interesting stack trace out of this, and NSZombiesEnabled doesn't give me anything either, but the original bug that set me hunting did result in "-[Symbol methodSignatureForSelector:]: message sent to deallocated instance" (with zombies turned on). It doesn't seem to me…
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@stuff = []
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "crash", userInfo:nil, repeats: true)
NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "burn", userInfo:nil, repeats: true)
true
end
def crash
puts "crash"
@felixyz
felixyz / pretty-date.rb
Created September 17, 2012 21:23 — forked from rjz/pretty-date.rb
Pretty Date in Ruby
# Nothin' special here: just Resig's pretty date function ported to Ruby
# http://ejohn.org/blog/javascript-pretty-date/
def pretty_date(stamp)
now = Time.new
diff = now - stamp
day_diff = ((now - stamp) / 86400).floor
day_diff == 0 && (
diff < 60 && "just now" ||