Skip to content

Instantly share code, notes, and snippets.

View rinaldifonseca's full-sized avatar

Rinaldi Fonseca rinaldifonseca

View GitHub Profile
# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
# Disable the “Are you sure you want to open this application?” dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2
# Disable press-and-hold for keys in favor of key repeat
@rinaldifonseca
rinaldifonseca / mt.rb
Created June 7, 2012 20:17 — forked from alanq/mt.rb
DCI in ruby without injection - MoneyTransfer example
# The code can be seen here: gist.github.com/2711153 (it does use a small bit
# from the Rails framework, just for the persisted LedgerEntry and to create
# attribute readers). Some notes about the code:
# - Each Role is a class, having only (public) class methods. To help
# avoid them being called outside of their Context, a Role Method only has
# access to its associated object while the role's context is the
# current/active global context.
# - Following Trygve's approach: "Roles are referenced by name. If I mean
# the Role I write the role name, not 'self'."
# - For referencing the object playing a role, I've overridden the Role's
#model / Data object
class User
attr_reader :name, :approved
def initialize name
@name = name
@approved = false
end
def approved?
# Framework
# ===========================================
module ContextAccessor
def context
Thread.current[:context]
end
end
module Context
include ContextAccessor
@rinaldifonseca
rinaldifonseca / links.textile
Created May 27, 2012 20:45 — forked from lucashungaro/links.textile
Links de referência utilizados em minha palestra
@rinaldifonseca
rinaldifonseca / multi-threaded-http-client-rails.rb
Created April 28, 2012 13:57 — forked from arp/multi-threaded-http-client-rails.rb
Multi-threaded HTTP requests that help utilize multiple CPU cores in Rails by requerying the app itself
# This way we re-query the app itself in order to avoid sequential execution for CPU-intensive tasks
# that can (and should) be executed in parallel.
#
# Pros: decent scalability can be achieved by assigning path=some.load.balancer.com (i.e. Amazon ELB)
# and putting a bunch of multicore machines behind it.
#
# Cons: we lose some fraction of time on JSON encoding/decoding and HTTP traffic.
# Load-balanced fault-tolerant DRb could be a better choice, but would require more work and provide only
# minor performance improvement in situation where JSON/HTTP aren't the main CPU consumers.
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@rinaldifonseca
rinaldifonseca / gist:2360857
Created April 11, 2012 17:45
No Cache Store with Rails
#lib/active_support/cache/no_store.rb
module ActiveSupport
module Cache
class NoStore < Store
def read_entry(name, options)
return nil
end
def write_entry(name, value, options)
end
@rinaldifonseca
rinaldifonseca / s.rb
Created April 11, 2012 02:17 — forked from jacksonwillis/s.rb
Sentences as Ruby code
class S;def initialize *w;@s=w;end;def method_missing *w;@s<<w;self ###########
end;def to_ary;[@s.map{|e|e=~/[\,\.\:\-\(\)\/\'\"]/?[e]:[" ",e]}.join.strip] ##
end;end;def Object.const_missing(c);S.new c;end ####### gist.github.com/2354740
puts This.is.a.sentence.represented.by.a.Ruby.expression(".") #################
@rinaldifonseca
rinaldifonseca / osx_homebrew_rvm_rails_unixodbc_sqlserver.md
Created April 3, 2012 02:06 — forked from sixfeetover/osx_homebrew_rvm_rails_unixodbc_sqlserver.md
Setup OS X 10.6.4 w/ homebrew, rvm, rails, unixodbc, freetds and SQL Server

Setup new mac from scratch

These commands are good as of 2010-11-18.

ruby -e "$(curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb)"

Install xcode (download, or on the OS X install DVD)

http://developer.apple.com/technology/xcode.html