Skip to content

Instantly share code, notes, and snippets.

View fellix's full-sized avatar

Rafael Felix fellix

View GitHub Profile
@fellix
fellix / spec.js.coffee
Created February 27, 2012 00:49
JasmineRice spec_helper
#=require_tree ./
#= require application
@fellix
fellix / payment.rb
Created January 3, 2012 21:10
Cielo Config Sample
class Payment
def initialize cliente
@cliente = cliente
end
def checkout order
Cielo.numero_afiliacao = @cliente.numero_afiliacao
Cielo.chave_acesso = @cliente.chave_acesso
transaction = Cielo::Transaction.new
transcation.create! order.attributes
end
@fellix
fellix / money_field.rb
Created December 6, 2011 13:32
Mongoid Money Field
module Mongoid
class MoneyField
include Mongoid::Fields::Serializable
def deserialize(object)
return nil unless object
Money.new(object)
end
def serialize(object)
@fellix
fellix / order.rb
Created November 9, 2011 19:20
order
class Order
attr_accessor :id, :client, :products, :total, :status
def pay!(adapter)
response = adapter.pay(self)
status = response
end
def paid?
status == :paid
@fellix
fellix / pog.js
Created October 28, 2011 17:30
POG pra um container Java reconhecer o caminho relativo numa requisião ajax
local = document.location.href;
urlMappings = local.split("/");
context = urlMappings[3];
$.ajax({
url: '/'+context+'/alertas',
});
@fellix
fellix / connection.rb
Created October 19, 2011 12:33
Ruby on Rails Multiple Connections
ActiveRecord::Base.class_eval do
def self.connection(key)
establish_connection(key)
self
end
end
Model.connection(:development).all
Model.connection(:production).all
@fellix
fellix / gist:1183404
Created August 31, 2011 12:14
Procfile
mongod: sudo mongod
spork: spork
guard: guard
@fellix
fellix / user.rb
Created August 29, 2011 15:08
Has Secure Password
# Schema: User(name:string, password_digest:string, password_salt:string)
class User < ActiveRecord::Base
has_secure_password
end
user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
user.save # => false, password required
user.password = "mUc3m00RsqyRe"
user.save # => false, confirmation doesn't match
user.password_confirmation = "mUc3m00RsqyRe"
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Home</title>
</head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<div>
Hi, I'm a page that contains the time:
@fellix
fellix / router.js
Created July 19, 2011 13:24
backbone sample
var AlbumController = Backbone.Router.extend({
routes: {
"collection/:album_collection_id/album/:id" : "show",
},
initialize: function(options) {
},
show: function(album_collection_id, id){
var albums = new SingleAlbumCollection(album_collection_id, id);