Skip to content

Instantly share code, notes, and snippets.

View cfcosta's full-sized avatar

Cainã Costa cfcosta

  • São Paulo, Brazil
View GitHub Profile
//= require_tree ./vendor
//= require_directory .
<!DOCTYPE html>
<html>
<head>
<title>Shmup Game</title>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/assets/application.css">
@cfcosta
cfcosta / gist:3594439
Created September 2, 2012 03:08
Gemfile for embedding
source :rubygems
gem 'sinatra'
gem 'sprockets'
gem 'coffee-script'
@cfcosta
cfcosta / gist:3594414
Created September 2, 2012 03:05
Sinatra application for serving simple Single Page Applications
require 'bundler/setup'
Bundler.require
class Application < Sinatra::Base
get '/assets/:file' do
env['PATH_INFO'].gsub!("/assets","")
asset_handler.call(env)
end
get '/' do
@cfcosta
cfcosta / gist:3418640
Created August 21, 2012 19:39
Monkeypatch to make Devise::Mailer to work with Resque::Mailer
require "devise"
module Devise
module Mailers
module Helpers
include Resque::Mailer
alias_method :old_initialize_from_record, :initialize_from_record
protected
@cfcosta
cfcosta / tree.rb
Created May 11, 2012 21:18
An implementation of Trees for PostgreSQL
module Tree
extend ActiveSupport::Concern
module ClassMethods
def leaves
where("children = ?::integer[]", [].pg)
end
def roots
where("ancestry = ?::integer[]", [].pg)
module Tree
extend ActiveSupport::Concern
module ClassMethods
def leaves
where("children = ?::integer[]", [].pg)
end
def roots
where("ancestry = ?::integer[]", [].pg)
test_tree=# insert into tags (name, ancestry) values ('child', '{1}') returning id;
id
----
4
(1 row)
INSERT 0 1
>> require "minitest/mock"
=> true
>> mock = MiniTest::Mock.new
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={}, @actual_calls={}>
>> mock.respond_to? :abc
=> false
>> mock.expect(:abc, "123")
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={:abc=>{:retval=>"123", :args=>[]}}, @actual_calls={}>
>> mock.respond_to? :abc
=> true
@cfcosta
cfcosta / gist:2124269
Created March 19, 2012 19:05
integration test helper for rails with minitest
ENV['RAILS_ENV'] = "test"
unless defined?(Bundler)
require 'bundler/setup'
end
require 'minitest/autorun'
require 'factory_girl'
MiniTest::Unit::TestCase.send(:include, FactoryGirl::Syntax::Methods)