Skip to content

Instantly share code, notes, and snippets.

View felixyz's full-sized avatar

Felix Holmgren felixyz

View GitHub Profile
felixyz / sidekiq_unique_jobs_bug_spec.rb
Created February 3, 2014 09:43
RSpec script attempting (and failing) to reproduce sidekiq-unique-jobs issue #27.
View sidekiq_unique_jobs_bug_spec.rb
require 'spec_helper'
require 'sidekiq'
require 'sidekiq/middleware/chain'
require 'sidekiq/fetch'
require 'sidekiq/processor'
require 'redis/namespace'
redis_url = 'redis://localhost/15'
client = Redis.connect(:url => redis_url)
felixyz / runflora log
Last active August 29, 2015 14:11
Flora-2 failures on OSX
View runflora log
$ ./flora2/runflora
% Specialising partially instantiated calls to flora_assert_directories/1
[Compiling Foreign Module /Users/felix/Documents/code/flora2/flora2bundle/flora2/cc/prolog2hilog (Prolog compiler options are ignored)]
[prolog2hilog compiled, cpu time used: 0.0010 seconds]
[Compiling C file /Users/felix/Documents/code/flora2/flora2bundle/flora2/cc/prolog2hilog.c using gcc]
/Users/felix/Documents/code/flora2/flora2bundle/flora2/cc/prolog2hilog.c:365:9: warning: comparison of 0 > unsigned expression is always false [-Wtautological-compare]
if (0 > length_diff) return FALSE;
~ ^ ~~~~~~~~~~~
1 warning generated.
gcc -dynamiclib -undefined dynamic_lookup -fPIC -o /Users/felix/Documents/code/flora2/flora2bundle/flora2/cc/prolog2hilog.dylib /Users/felix/Documents/code/flora2/flora2bundle/flora2/cc/prolog2hilog.c -Wall -fPIC -I/Users/felix/Documents/code/flora2/flora2bundle/XSB/emu -I/Users/felix/Documents/code/flora2/flora2bundle/XSB/config/i386-apple-darwin13.2.0 -O3 -fno-strict-aliasing -
felixyz / gist:872d0567e0d58d6e6aac
Created March 16, 2015 16:06
dokku nginx config http + https
View gist:872d0567e0d58d6e6aac
server {
listen [::]:80;
listen 80;
server_name $NOSSL_SERVER_NAME;
location / {
proxy_pass http://$APP;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
felixyz / pretty-date.rb
Created September 17, 2012 21:23 — forked from rjz/pretty-date.rb
Pretty Date in Ruby
View pretty-date.rb
# Nothin' special here: just Resig's pretty date function ported to Ruby
def pretty_date(stamp)
now =
diff = now - stamp
day_diff = ((now - stamp) / 86400).floor
day_diff == 0 && (
diff < 60 && "just now" ||
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…
View crash_burn_symbols.rb
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)
def crash
puts "crash"
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!
View gist:5679768
require 'thread'
def provider()
threads = []
queue =
1.upto(10).each do |n|
threads << {
sleep rand(0.1..2)
queue << n
felixyz / celluloid_redis_bug.rb
Last active December 18, 2015 10:59
This illustrates celluloid-redis issue #9: A repo containing the below code and branches with variations that variously provoke the same bug or not can be found here:
View celluloid_redis_bug.rb
require 'thread'
require 'celluloid/io'
require 'celluloid/redis'
KEY = "magic_key"
VALUE = {a: 1, b:2}
class RedisActor
include Celluloid::IO
felixyz / gist:5788375
Created June 15, 2013 14:44
MRI pipe limit (on OS X). This script fails on my Mac after creating 125 x 2 pipe endpoints, raising "Too many open files (Errno::EMFILE)" This is the cause of the problem illustrated here:
View gist:5788375
wakeups = []
wakers = []
puts "Creating pipes..."
200.times do |n|
puts "[#{n}]"
wakeup, waker = IO.pipe
wakeups << wakeup
wakers << waker
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
View gist:5788285
# 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 / item_insert_benchmark.rb
Created September 16, 2013 15:40
Compares speed of two different methods of inserting items in an array.
View item_insert_benchmark.rb
require 'benchmark'
def insert_then_sort(results, missing_items)
missing_items.each do |id|
results << {id: id, val: nil}
results.sort_by!{|item| item[:id] }