Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / proxy.php
Created September 20, 2012 15:40
play with proxy function with invoke php
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
function node_load($param) {
echo $param;
}
@francescoagati
francescoagati / main.rb
Created August 12, 2012 09:08
celluloid-io and faraday
require 'celluloid/io'
require 'faraday'
require 'benchmark'
class HttpClient
include Celluloid::IO
attr_accessor :conn
@francescoagati
francescoagati / sexp.ripper
Created August 1, 2012 18:51
who is pippo? ruby runtime variable, methods and closure
[:program,
[[:class,
[:const_ref, [:@const, "Context", [4, 8]]],
nil,
[:bodystmt,
[[:def,
[:@ident, "pippo", [6, 8]],
[:params, nil, nil, nil, nil, nil],
[:bodystmt,
[[:string_literal,
@francescoagati
francescoagati / directive.js
Created July 8, 2012 20:05
angular.js directive for loading json in view and associate to property scope
var directives;
directives = angular.module("myApp.directives", ['ngResource']);
(function(){
this.directive("jsonresource", function($resource){
return function(scope, element, attrs){
console.log(attrs.variable);
return scope[attrs.variable] = $resource(attrs.path).get();
};
});
}.call(directives));
@francescoagati
francescoagati / ecample.opal.rb
Created June 19, 2012 13:43
module Observable ported to Opal
#hacking Kernel module for add loop_every
module Kernel
def loop_every(n,&blk)
blk.call
n=n*1000
`setInterval(function() {`
blk.call
`},n);`
end
end
@francescoagati
francescoagati / jquery.rb
Created June 18, 2012 17:42
Opal: wrap jquery native methods at runtime with metaprogramming
module Jquery
module WrapMethods
def WrapMethods.included(base)
# i can't use extend on opal. why?
class << base
def wrap_method(meth)
@francescoagati
francescoagati / include.php
Created April 11, 2012 13:54
simple dependency load in php with require and extract
<?
return array("a" => $title);
@francescoagati
francescoagati / Main.hx
Created January 14, 2012 15:53
haxe dependency injection style syringe pimple
class Main {
public static function getInjector() {
var inject=new Injector();
inject.service("logger",function(context) {
trace(context);
return 9999;
});
@francescoagati
francescoagati / chainable.coffee
Created January 5, 2012 09:54
coffeescript: chainable methods
chained_method= (obj,method,fn) -> obj::[method]= ()-> fn.apply(@,arguments);@
class Base
constructor: -> @n=0
chained_method @,'sum', (x) -> @n=@n+x
chained_method @,'minus', (x) -> @n=@n-x
chained_method @,'pp', (x) -> console.log @n
(new Base).sum(3).minus(10).pp()
@francescoagati
francescoagati / fibonacci.lua
Created July 31, 2011 20:51
fibonacci lua vs luajit
-- Code thaked from http://en.literateprograms.org/Fibonacci_numbers_(Lua)?
-- for benchmarking lua and luajit
-- at bottom of files the result of benchmark
-- Copyright (c) 2011 the authors listed at the following URL, and/or
-- the authors of referenced articles or incorporated external code:
-- http://en.literateprograms.org/Fibonacci_numbers_(Lua)?action=history&offset=20081019232035
--
-- Permission is hereby granted, free of charge, to any person obtaining