Skip to content

Instantly share code, notes, and snippets.

View lucashungaro's full-sized avatar

Lucas Húngaro lucashungaro

View GitHub Profile
@lucashungaro
lucashungaro / gist:1924747
Created February 27, 2012 15:38
Some ideas on a small framework. Yet another web framework.
class Lists < App
authenticate { AuthenticationService.authenticate(session) } # just an example, it checks for true or false only
authorize { current_user.role? :admin }, :for => :create, :update # same here
all { List.all } # :get /lists
# the param name should always be class.name.singularize
one { List.find(params[:list]) } # :get /lists/:id
instance { List.new(params[:list]) }
@lucashungaro
lucashungaro / gist:2690982
Created May 14, 2012 00:51
SRP snippet 2
class Game < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :category_id, :description,
:price, :platform, :year
end
class GamePriceService
attr_accessor :game
# we could use a config file
@lucashungaro
lucashungaro / gist:2690968
Created May 14, 2012 00:49
SRP snippet 1
class Game < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :category_id, :description,
:price, :platform, :year
def get_official_price
open("http://thegamedatabase.com/api/game/#{name}/price?api_key=ek2o1je")
end
def print
@lucashungaro
lucashungaro / gist:2946258
Last active October 6, 2015 05:48
Installing ruby 1.9.3 from source on OS X Lion
Install XCode *and* Command Line Tools (just CLT won't be enough, readline won't work =[)
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2
brew install wget openssl readline libyaml curl libxslt
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz
tar xzvf ruby-1.9.3-p392.tar.gz
cd ruby-1.9.3-p392
@lucashungaro
lucashungaro / gist:3001503
Created June 27, 2012 04:40
DIP snippet 1
class Game < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :category_id, :description,
:price, :platform, :year
end
 
class GamePriceService
attr_accessor :game
 
# we could use a config file
@lucashungaro
lucashungaro / gist:3001505
Created June 27, 2012 04:42
DIP snippet 2
class Game < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :category_id, :description,
:price, :platform, :year
end
 
class GamePriceService
attr_accessor :game, :json_parser
 
# we could use a config file
@lucashungaro
lucashungaro / gist:3001511
Created June 27, 2012 04:44
DIP snippet 3
class Game < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :category_id, :description,
:price, :platform, :year
end
 
class GamePriceService
attr_accessor :game
 
# we could use a config file
@lucashungaro
lucashungaro / gist:3001641
Created June 27, 2012 05:16
DIP snippet 4
# WARNING: pseudo code
class Authenticator
def initialize(user_repository = User)
@user_repository = user_repository
end
def authenticate(identifier, hashed_password)
@user_repository.find(:username => identifier, :password => hashed_password).present?
end
@lucashungaro
lucashungaro / gist:3784008
Created September 25, 2012 19:46
removing conditional and working with provided callbacks
class UserController < ApplicationController
def create
@user_creation = UserCreation.new(self)
@user_creation.on_success { redirect_to users_path }
@user_creation.on_failure { render :new }
@user_creation.please_create_an_user_as_admin(params[:user])
end
end
@lucashungaro
lucashungaro / gist:742790
Created December 15, 2010 23:43
Split MKV files
To install mkvtoolnix:
$ brew install mkvtoolnix
To split a file:
$ mkvmerge --split size:4050m /path/to/file.mkv -o /path/to/output_file.mkv