A quick experiment trying to replicate the cake pattern example from Jonas Bonér's post Real-World Scala: Dependency Injection (DI) in ruby.
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
web: (while true; do echo MARK $(date --iso-8601=seconds); sleep 5; done) & ruby --version; bin/rackup -Ilib -s puma rackup.ru -p $PORT | |
# Or slightly more clearly | |
web: rake resqueue:worker & ruby --version; bin/rackup -Ilib -s puma rackup.ru -p $PORT |
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 'zlib' | |
require 'socket' | |
require 'thread' | |
WORKERID_BITS = 10 | |
MAX_WORKER_ID = -1 ^ (-1 << WORKERID_BITS) | |
SEQUENCE_BITS = 12 | |
MAX_SEQUENCE = -1 ^ (-1 << SEQUENCE_BITS) | |
SINCE_MILLIS = Time.utc(2012, 1, 1).to_f * 1000 |
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
Mutant configuration: | |
Matcher: #<Mutant::Matcher::Method::Instance identification="SRSRB::CardEditorApp#card_models_as_dictionary"> | |
Filter: Mutant::Mutation::Filter::ALL | |
Strategy: #<Mutant::Strategy::Rspec::Full> | |
Subject: SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110 | |
Alive: rspec:noop:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:24ec0 (0.71s) | |
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:3e242 (0.43s) | |
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:5d14b (0.43s) | |
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:3aca1 (0.42s) | |
Killed: rspec:SRSRB::CardEditorApp#card_models_as_dictionary:/Users/cez/projects/srs-rb/lib/srsrb/rackapp.rb:110:d8c97 (0.45s) |
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
1.9.3p0 :004 > require 'pp' | |
=> true | |
1.9.3p0 :002 > p = proc { |a| pp proc_args: a } | |
=> #<Proc:0x0000010090b838@(irb):2> | |
1.9.3p0 :010 > p.call(1,2) | |
{:proc_args=>1} | |
1.9.3p0 :008 > stabby = ->(a) { pp stabby_args: a } | |
=> #<Proc:0x00000101099410@(irb):8 (lambda)> | |
1.9.3p0 :009 > stabby.call(1,2) | |
ArgumentError: wrong number of arguments (2 for 1) |
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
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
void | |
handler(int signum) | |
{ | |
printf("Catching signal %d\n",signum); | |
sleep(1); |
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
(* See http://matt.might.net/articles/cek-machines/ *) | |
type var = string | |
type term = | |
Ref of var | |
| Lam of lambda | |
| App of term * term | |
and lambda = L of var * term |
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
user=> (doseq [f [(fn [& r] r) list vector]] (time (dotimes [_ 10000000] (f 1 2)))) | |
"Elapsed time: 89.534 msecs" | |
"Elapsed time: 1619.788 msecs" | |
"Elapsed time: 659.573 msecs" | |
nil | |
user=> (doseq [f [(fn [& r] r) list vector]] (time (dotimes [_ 100000000] (f 1 2)))) | |
"Elapsed time: 284.97 msecs" | |
"Elapsed time: 16061.555 msecs" | |
"Elapsed time: 6207.421 msecs" | |
nil |
It's quite easy to draw parallels between the Alan Kay's definition of objects (ie: the important part is messaging) and actors as found in Erlang (independent processes communicating via messages). And one parallel seems to be between the supervisor, and factories (as supervisors are responsible for the lifecycle of it's child processes, as a factory can be for objects, I think).
So, if you have processes A and B supervised by S, but B needs to send messages to A, then it might seem like a good idea to dynamically create both in Module:start_link, eg:
-module(something_sup).
-behavior(supervisor).
start_link() ->
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
: cez@rhk; (cd /usr/local/ && git remote -v) | |
origin https://github.com/mxcl/homebrew.git (fetch) | |
origin https://github.com/mxcl/homebrew.git (push) | |
: cez@rhk; |