Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / async.js
Created November 10, 2012 02:41
async map and filter using livescript and continuation.js
/* Generated by Continuation.js v0.0.5 */
(function () {
var async, slice$, result;
slice$ = [].slice;
async = function () {
var delay, sum, amap, afilter;
delay = function (fn) {
var i$, args, cb, wrapper;
args = 1 < (i$ = arguments.length - 1) ? slice$.call(arguments, 1, i$) : (i$ = 1, []), cb = arguments[i$];
wrapper = function () {
@francescoagati
francescoagati / continuation.js
Created November 9, 2012 20:19
complex continuation with livescript and continuation.js
/* Generated by Continuation.js v0.0.5 */
(function () {
var identity, sum, transform_array, ranges, i$, len$, range;
identity = function (el, callback) {
var delayed;
delayed = function () {
return callback(el);
};
return setTimeout(delayed, 100);
};
@francescoagati
francescoagati / router.rb
Created November 5, 2012 16:31
wrapping routie with opal
# library wrapped https://github.com/jgallen23/routie
class Router
attr_accessor :params
def initialize
@routes={}
@params={}
end
@francescoagati
francescoagati / stream.rb
Created November 4, 2012 16:53
celluloid streaming content and write to mysql db
class Writer
include Celluloid
include Celluloid::Logger
def write_tweet(tweet)
DB[:links].insert(tweet)
end
@francescoagati
francescoagati / Container.js
Created October 31, 2012 16:38
simple Dependency injection in livescript
var Container, cnt;
Container = (function(){
Container.displayName = 'Container';
var prototype = Container.prototype, constructor = Container;
function Container(){
var ref$;
ref$ = [{}, {}], this.registry = ref$[0], this.shared = ref$[1];
}
prototype.set = function(name, opt, fn){
var registry;
@francescoagati
francescoagati / actor.rb
Created October 29, 2012 03:07
an example of actor model in opal client side
class Timer
def initialize(delay=100)
@delay=delay
end
def run
end
@francescoagati
francescoagati / behnchmark
Created October 23, 2012 10:08
simple benchmarking jruby
rvm use 1.9.3
ruby bn.rb
Rehearsal --------------------------------------------
Hash:set 7.970000 0.030000 8.000000 ( 8.049540)
----------------------------------- total: 8.000000sec
user system total real
Hash:set 7.910000 0.030000 7.940000 ( 7.998218)
@francescoagati
francescoagati / actor_cell.rb
Created September 28, 2012 15:29
rendering cell inside celluloid actor
class ActorCell
include Celluloid
def render_cell(class_cell,state,args={})
class_cell.new.render_state(state,args)
end
end
@francescoagati
francescoagati / define_method.php
Created September 26, 2012 15:55
metaprogramming php: using define_method with traits, closure and rebind
<?php
trait MethodsRuntime {
public static function defineMethod($name,$fn) {
self::$methods[$name]=$fn;
}
@francescoagati
francescoagati / extensions.php
Created September 24, 2012 14:46
simple extension method with reflection and __call in php
<?php
class St {
public static function pippa($obj) {
print_r($obj);
}
}