Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
leandrosilva / gist:167361
Created August 13, 2009 18:26
Script to remove all .svn directory recursively
find -name ".svn" | while read line; do rm -Rf $line; done
@leandrosilva
leandrosilva / ApplicationHelper with render a partial method .rb
Created August 26, 2009 05:05
ApplicationHelper with render a partial method
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
# Helper to render a partial with or without a block.
def render_a_partial(partial_name, options = {}, &block)
if block_given?
options.merge!(:body => capture(&block))
concat(render(:partial => partial_name, :locals => options), block.binding)
else
render(:partial => partial_name, :locals => options)
@leandrosilva
leandrosilva / gist:177293
Created August 28, 2009 22:08
A text replacement script
for i in `find . -type f -name "*" | grep -v "*.jar"`; do echo $i | tee -a log.txt; cat $i | sed s/textoAntigo/textoNovo/g > x; cat x > $i; rm x; done
@leandrosilva
leandrosilva / gist:177294
Created August 28, 2009 22:10
Yet another script to remove all .svn directory recursively
rm -rf `find . -name ".svn"`
@leandrosilva
leandrosilva / sinatra-rack.ru
Created October 27, 2009 14:13
A experience on rack
require 'sinatra-rack_app'
run Sinatra::Application
@leandrosilva
leandrosilva / gist:220766
Created October 28, 2009 20:00
A function to convert "list" to "term"
list_to_term(String) ->
{ok, T, _} = erl_scan:string(String ++ "."),
case erl_parse:parse_term(T) of
{ok, Term} ->
Term;
{error, Error} ->
Error
end.
@leandrosilva
leandrosilva / README
Created October 30, 2009 22:13
My custom OTP behaviour for event management
Do you want to try it?
---
1st. Compile
$ erlc gen_event_manager.erl my_event_manager.erl my_event.erl
2nd. Test
@leandrosilva
leandrosilva / simples_fsm.erl
Created October 30, 2009 22:20
A simple finite state machine implemented with gen_fsm
%% finite state machine
-module(simples_fsm).
-behaviour(gen_fsm).
-export([start_link/1, dispara_evento/1]).
-export([init/1]).
-export([estado_um/2, estado_dois/2, estado_tres/2]).
%% api
@leandrosilva
leandrosilva / gist:230140
Created November 9, 2009 18:05
New method implementation with instance_eval
#
# Some class for example
#
class SomeClass
def a_method
puts '>> a defined method: a_method'
end
end
#
@leandrosilva
leandrosilva / gist:230884
Created November 10, 2009 13:16
Algumas dicas avançadas de jpa + ejb3: persistence unit
/**
* (Código 1)
*
* Anotação @PersistenceUnit sendo usada num Stateful SessionBean para registrar
* um EntityManagerFactory no contexto JNDI sob o nome "persistencia/MaritimoDB",
* tendo como unidade de persistencia "MaritimoDB".
*/
@Stateful
@PersistenceUnit(name="persistencia/MaritimoDB", unitName="MaritimoDB")
public class AgenteDeTurismoBean implements AgenteDeTurismoRemote {