Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / macro.phn
Created January 20, 2011 19:42
pharen php evalutation
class PhpNode extends SpecialForm{
public $body_index = 2;
public function compile_statement(){
$body = $this->compile_body();
eval("\$body=$body");
echo $body;
return $this->format_line($body);
@francescoagati
francescoagati / commandline
Created March 10, 2011 17:15
rainbows.conf
rainbows -c rainbows.conf
@francescoagati
francescoagati / main.phn
Created June 12, 2011 14:29
usin pharen lisp compiling in php with slim
(require "Slim/Slim.php")
(:: Slim (init))
(fn hello (name) (echo (. "Hello, " name)) "")
(:: Slim (get "/hello/:name" "hello"))
(:: Slim (run))
@francescoagati
francescoagati / idiorm.phn
Created June 12, 2011 15:18
phare with idiorm -> sql and lisp and php
(:: ORM (configure "mysql:host=localhost;dbname=my_database"))
(:: ORM (configure #username #database_user))
(:: ORM (configure #password #top_secret ))
(def people
(-> (:: ORM (for_table #person))
(where #name "Fred")
(where_raw "(`age` = ? OR `age` = ?)" [20,25])
(order_by_asc #name)
@francescoagati
francescoagati / transition.phn
Created June 12, 2011 15:53
transition with idiorm php pharen and lambda function
(fn transiction (callback)
(-> (:: ORM get_db) (beginTransaction))
($callback ORM)
(-> (:: ORM get_db) (commit))
)
(transition (lambda (orm) (print_r orm)))
@francescoagati
francescoagati / drupal.phn
Created June 13, 2011 11:56
using drupal with pharen lisp
(def result
(-> (db_select #users #u)
(condition "u.uid" 0 "<>")
(fields #u [#uid #name #created #access])
(range 0 100)
(execute)))
@francescoagati
francescoagati / deferred.coffee
Created June 18, 2011 22:39
jasmine jquery and deferred various examples
checkDeferred=(df,fn) ->
callback = jasmine.createSpy()
df.then(callback)
waitsFor -> callback.callCount > 0
runs ->
#expect(callback).toHaveBeenCalled()
fn.apply @,callback.mostRecentCall.args if fn
checkJson = (path,fn) ->
@francescoagati
francescoagati / async_map.coffee
Created July 1, 2011 15:37
test async.js map with jasmine
describe "async", ->
it "async not null", ->
expect(async).not.toBeNull()
it "respond to map", ->
expect(async.map).not.toBeNull()
it "[1,2,3] map (x) -> x + 1 eq [2,3,4]", ->
callback = jasmine.createSpy()
summer= (el,callback) -> callback null, el + 1
async.map([1,2,3],summer,callback)
@francescoagati
francescoagati / attr_accessor.coffee
Created July 3, 2011 21:05
a simple getter and setter in coffeescript mimic attr_accessor of ruby (monkey patching version)
Object::attr_accessor= (prop) ->
self=@
self["_#{prop}"]=null
self[prop]=(value) ->
@["_#{prop}"]=value if value?
@["_#{prop}"]
Player={}
@francescoagati
francescoagati / attr_accessor_with_closure.coffee
Created July 3, 2011 21:18
getter and setter with closure in coffeescript style attr_accessor of ruby
#this version don't work with prototype chain for generation variable prop_value with closure
Object::attr_accessor= (prop) ->
self=@
do ->
prop_value=null
self[prop]=(value) ->
prop_value=value if value?
prop_value