Skip to content

Instantly share code, notes, and snippets.

View thiagomoretto's full-sized avatar

Thiago Moretto thiagomoretto

View GitHub Profile
@thiagomoretto
thiagomoretto / gist:1288667
Created October 14, 2011 23:23
IA Search (W.I.P.)
class State
attr_accessor :value, :parent, :cost, :distance
def initialize(value, distance, parent)
@value, @distance, @parent, @cost = value, distance, parent, 0
end
def to_s; value; end
end
def search(strategy, current, final)
return false if current.nil?
@thiagomoretto
thiagomoretto / ts.rb
Created October 14, 2011 17:15
BFS/DFS/BestFS/A* in Ruby
class Node
attr_accessor :value, :left, :right, :cost
def to_s; value; end
def cost; @cost == nil ? 0 : @cost; end
end
def ts(strategy, current, final, total_cost=0.0)
return false if current.nil?
return true if current.value == final
@thiagomoretto
thiagomoretto / remote_session.rb
Created October 11, 2011 21:03
Rack-Test MockSession that enables to call remote/external URL using HTTParty
# Usage
# @browser ||= Rack::Test::Session.new(Rack::RemoteSession.new(Sinatra::Application, "twitter.com"))
require 'httparty'
module Rack
class RemoteSession < MockSession # :nodoc:
def request(uri, env)
env["HTTP_COOKIE"] ||= cookie_jar.for(uri)
@thiagomoretto
thiagomoretto / neurotic_builder.rb
Created February 8, 2011 20:18
Neurotic Builder!
class NeuroticException < Exception; end
module NeuroticBuilder
@@_required_on_create = []
def build(*args)
instance = self.send(:new, *args)
yield(instance) if block_given?
@thiagomoretto
thiagomoretto / chop.erl
Created December 8, 2010 06:14
Binary chop in Erlang
-module(chop).
-export([chop/2]).
chop(_Value, []) ->
-1;
chop(Value, List) ->
case (length(List) + 1) div 2 of
0 ->
-1;
Instalacao do ambiente Ruby/Rails no RedHat 5.5
===============================================
Observacao: Na instalacao em outro S.O. (Linux) o processo eh muito parecido
Toda a instalacao foi feita como root. Se feita com algum usuario o RVM sera
instalado na pasta do usuario, e nao para todo o sistema. Atente-se a isso e
na duvida veja na documentacao do RVM.
0. Requisitos
#!/bin/sh
USER=ruby
case "$1" in
start)
echo "Starting CruiseControl.rb..."
su - $USER -c 'rvm use 1.8.7@ci && /home/ruby/ci/cruisecontrol/cruise start -d'
;;
stop)
@thiagomoretto
thiagomoretto / attr.rb
Created June 24, 2010 14:55 — forked from jm/attr.rb
class ClassWithAttr
def self.my_attr_accessor(attr_name)
define_method("#{attr_name}=") do |arg|
instance_variable_set("@#{attr_name}", arg)
end
define_method(attr_name) do
instance_variable_get("@#{attr_name}")
end
end