Skip to content

Instantly share code, notes, and snippets.

View bravoecho's full-sized avatar

Luca bravoecho

  • UK
  • 08:31 (UTC +01:00)
View GitHub Profile
@bravoecho
bravoecho / dependency_injection_example.rb
Created November 20, 2011 15:57 — forked from mperham/gist:1379464
Flexibility with and without Dependency Injection
require 'minitest/autorun'
class TaxCodeBase
class AbstractMethod < StandardError
end
attr_accessor :user_id
def initialize(user_id=nil)
self.user_id = user_id
@bravoecho
bravoecho / active_model_lint.rb
Created March 6, 2012 11:17 — forked from mikegehard/active_model_lint.rb
RSpec shared examples for ActiveModel::Lint
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
# put this in a file in your spec/support directory, or add the code to the spec_helper.rb
# USAGE:
#
# context "ActiveModel Lint" do
# it_behaves_like "an ActiveModel", YourModel.new
# end
shared_examples "an ActiveModel" do |model|
require 'test/unit/assertions'
@bravoecho
bravoecho / chef_solo_bootstrap.sh
Created April 14, 2012 09:59 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
rm ruby-1.9.3-p125.tar.gz
rm -r ruby-1.9.3-p125
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
@bravoecho
bravoecho / puppet_local_bootstrap.sh
Created May 12, 2012 08:42
Bootstrap Puppet Workstation
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p320.tar.gz
tar -xvzf ruby-1.9.2-p320.tar.gz
cd ruby-1.9.2-p320/
./configure --prefix=/usr/local
make
make install
@bravoecho
bravoecho / global_dependency.rb
Created May 17, 2012 17:13
Global hard-coded dependencies are bad not only for design-related matters.
class MyEvilDependency
def self.do_good
"ok"
end
def self.save_the_world
puts "I could destroy the world if I wanted"
end
end
@bravoecho
bravoecho / selectable_queue.rb
Created June 23, 2012 14:51 — forked from garybernhardt/selectable_queue.rb
A queue that you can pass to IO.select. This is for use in a GUI application. I'm not turning into a Node programmer.
# A queue that you can pass to IO.select.
#
# NOT THREAD SAFE: Only one thread should write; only one thread should read.
#
# Purpose:
# Allow easy integration of data-producing threads into event loops. The
# queue will be readable from select's perspective as long as there are
# objects in the queue.
#
# Implementation:

This document is intended to be a simplified version of the OAuth v2-28 specification. In particular it has been written with implementors in mind, and as such attempts to trim the spec down to just what you need to implement an OAuth provider or client. It is necessarily not complete, but attempts to introduce spec requirements in the same order in which the protocol proceeds in practise, with everything you need to know about each protocol endpoint brought together in one place rather than scattered across a large document.

@bravoecho
bravoecho / gist:3423782
Created August 22, 2012 08:36 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@bravoecho
bravoecho / flattener.rb
Created November 28, 2012 13:16
flatten nested hash - recursive vs non-recursive
require 'pry'
data = {
a: {
alfa: "alfa",
beta: "beta"
},
b: 2,
c: {
alfa: {
module Suggestions
def self.included( base )
base.extend ClassMethods
end
module ClassMethods
# USAGE:
#
# class Doctor
# # this model should have the typical Sunspot.setup clause somewhere else