Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / commandline
Created March 10, 2011 17:15
rainbows.conf
rainbows -c rainbows.conf
@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 / Proc.to_php
Created September 13, 2010 19:16
an example of sourcify + php for generate php from a block
require 'rubygems'
require 'active_support'
require 'php'
require 'sourcify'
class Proc
def to_php
code=self.to_source.gsub("proc {","")[0..-2]
PHP.generate(code).to_php.gsub("<?php","")
@francescoagati
francescoagati / select_if for underscore.js
Created August 30, 2010 10:03
a select_if for underscore.js
_.mixin({
select_if:function(data,options) {
if (options.cond()==true) {
return _(data).chain().filter(options.exec).value();
} else {
return data;
}
}
});
@francescoagati
francescoagati / core.clj
Created August 16, 2010 19:08
n example of with-diret-linking for overloading symbols in a local scope in clojure
(comment
"an example of with-diret-linking for overloading symbols in a local scope"
)
(ns prova.core)
(use 'clojure.contrib.macro-utils)
(require '[prova.over :as over])
(require '[clojure.contrib.macros :as macros])