Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / drupal_connect.rb
Created March 27, 2010 14:36
drupal client with xmlrpc
require 'rubygems'
require 'xmlrpc/client'
# an example of client for drupal made with xmlrpc
class Drupal
def initialize(opt={},&blk)
@client = XMLRPC::Client.new( opt[:host] , "/?q=services/xmlrpc")
@sess=@client.call("system.connect", 1)
require 'Tempfile'
class Test
def `(s)
output=""
(eval Ruby2Ruby.new.process("Proc.new {|z| z+1}".to_sexp)).call 3
require 'rubygems'
require 'liquid'
tpl=%{
{%for player in players%}
{{player.name}}
{{player.surname}}
{%endfor%}
require 'rubygems'
require 'yaml'
class Player
attr_accessor :name,:surname
def initialize(opt={})
@name=opt[:name]
@surname=opt[:surname]
run_in_context: (fn,context) ->
if fn.length>0
fn.apply null,[context]
else
fn.apply context
process: (n,fn) ->
run_in_context fn,n
require 'rubygems'
require 'v8'
require 'johnson'
require 'ruby_parser'
sexp=Johnson::Parser.parse %{
var sum=function sum (x,y) {
return x+y
};
@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])
@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 / 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","")