Skip to content

Instantly share code, notes, and snippets.

View Porta's full-sized avatar

Julián Porta Porta

View GitHub Profile
10.times {puts "ALQUILER!"}
class PeopleController < ApplicationController
respond_to :html, :xml, :json
expose(:person)
def create
person.save
respond_with(person)
end
// Hello World in Java
class HelloWorld {
static public void main( String args[] ) {
System.out.println( "Hello World!" );
}
}
#############################################################################################
//Hello World in C#
class HelloWorld
class Event < Ohm::Model
KINDS = %w[creation approval disapproval reception delivery]
reference :user, lambda { |id| User.find(id)}
reference :item, lambda { |id| id.nil? ? nil : Item.find(id)}
reference :transaction, lambda { |id| id.nil? ? nil : Transaction.find(id)}
attribute :kind
attribute :text
class Event < Ohm::Model
reference :user, lambda { |id| User.find(id)}
reference :item, lambda { |id| Item.find(id)}
reference :transaction, lambda { |id|Transaction.find(id)}
attribute :kind
attribute :text
attribute :created_at
ruby-1.9.2-p136 > e = Event[1]
=> #<Event:1 user_id="1" item_id="3" transaction_id="2" kind="reception" text=nil created_at="2011-04-20 14:32:19 -0300">
ruby-1.9.2-p136 > e.item
NoMethodError: You tried to call Item#find, but Item is not defined on /home/porta/Dropbox/Code/rails3/barter/app/models/event.rb:4:in `block in <class:Event>'
from /home/porta/.rvm/gems/ruby-1.9.2-p136@barter/gems/ohm-0.1.3/lib/ohm.rb:215:in `method_missing'
from /home/porta/Dropbox/Code/rails3/barter/app/models/event.rb:4:in `block in <class:Event>'
from /home/porta/.rvm/gems/ruby-1.9.2-p136@barter/gems/ohm-0.1.3/lib/ohm.rb:1192:in `[]'
from /home/porta/.rvm/gems/ruby-1.9.2-p136@barter/gems/ohm-0.1.3/lib/ohm.rb:1192:in `block in reference'
from /home/porta/.rvm/gems/ruby-1.9.2-p136@barter/gems/ohm-0.1.3/lib/ohm.rb:1275:in `instance_eval'
from /home/porta/.rvm/gems/ruby-1.9.2-p136@barter/gems/ohm-0.1.3/lib/ohm.rb:1275:in `block in define_memoized_method'
@Porta
Porta / gist:966443
Created May 11, 2011 13:25
enviar.php
<?
$nombre=$_REQUEST["nombre"];
$email=$_REQUEST["email"];
$filename=$_FILES["strresume"]["name"];
$filetype=$_FILES["strresume"]["type"];
$filesize=$_FILES["strresume"]["size"];
@Porta
Porta / products_controller.rb
Created May 16, 2011 13:55
ProductsController
class ProductsController < ApplicationController
#OJO ACA, esto limita los responses a SOLO json. podes agregar mas
respond_to :json
  def index
    resultado = Array.new
    Product.find_each do |p|
      resultado.push(p_para_json(p))
    end
@Porta
Porta / task_spec.rb
Created January 23, 2012 18:40
Test
it "should reject a new task" do
task = Factory(:task)
task.reject
task.rejected.should be_true
end
@Porta
Porta / task.rb
Created January 24, 2012 17:38
states
state_machine :status, :initial => :new do
event :accept do
transition :new => :accepted
end
event :reject do
transition :new => :rejected
end