Skip to content

Instantly share code, notes, and snippets.

Matthew Wells mdespuits

Block or report user

Report or block mdespuits

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mdespuits / account_decorator.rb
Last active Dec 12, 2015
Example of a basic decorator that uses `method_missing` rather than Delegation
View account_decorator.rb
class AccountDecorator
attr_accessor :account
def initialize(account)
@account = account
def method_missing(method_name, *args, &blk)
if account.respond_to?(method_name)
account_method_result(method_name, *args, &blk)
mdespuits / some_object_tap_uses.rb
Last active Dec 10, 2015
Example uses of Object#tap that I really like
View some_object_tap_uses.rb
# Logging some action in the console or log file
# Prevents lots of references to a variable
# Maybe not the best example, but potentially cleaner than the alternative
class ApplicationController
after_filter :log_action_without_tap
after_filter :log_action_with_tap
def log_action_with_tap
"[ACTION LOG]: #{} tried to #{action_name} #{controller_path}".tap{|l|
l <<{|k,v| "#{k}: #{v}"}.join(',') if flash.any?
mdespuits / bench_str_building.rb
Created Aug 31, 2012 — forked from alno/bench_str_building.rb
Benchmark: interpolation vs concatenation in Ruby
View bench_str_building.rb
require 'benchmark'
count = 1_000_000
Benchmark.benchmark do |bm|"concat") { count.times { 11.to_s + '/' + 12.to_s } }"interp") { count.times { "#{11}/#{12}" } }
mdespuits /
Last active Oct 9, 2015 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 - Useful Shortcuts (Mac OS X)


Command Action
⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
mdespuits / backtrace.txt
Created Aug 15, 2012
Cancan block ability error in v1.6.8
View backtrace.txt
activerecord (3.2.6) lib/active_record/sanitization.rb:121:in `sanitize_sql_array'
activerecord (3.2.6) lib/active_record/sanitization.rb:28:in `sanitize_sql_for_conditions'
activerecord (3.2.6) lib/active_record/relation/query_methods.rb:324:in `build_where'
activerecord (3.2.6) lib/active_record/relation/query_methods.rb:136:in `where'
activerecord (3.2.6) lib/active_record/querying.rb:9:in `where'
cancan (1.6.8) lib/cancan/model_adapters/active_record_adapter.rb:96:in `database_records'
cancan (1.6.8) lib/cancan/model_additions.rb:23:in `accessible_by'
activerecord (3.2.6) lib/active_record/relation/delegation.rb:37:in `block in method_missing'
activerecord (3.2.6) lib/active_record/relation.rb:241:in `block in scoping'
activerecord (3.2.6) lib/active_record/scoping.rb:98:in `with_scope'
mdespuits / brew-config
Created Aug 3, 2012
Node.js installation issues
View brew-config
HEAD: 3113434e7107c928dcfd411160bf44b921dd564d
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit sandybridge
OS X: 10.7.4-x86_64
Xcode: 4.4
GCC-4.0: N/A
GCC-4.2: build 5666
mdespuits / chef-solo-ubuntu-12-04
Created Jun 29, 2012
Chef Solo Setup for Ubuntu 12.04
View chef-solo-ubuntu-12-04
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
cd /tmp
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local
make install
mdespuits /
Created May 15, 2012
mac os x postgres install (homebrew option)
# Access tty to ask for confirmation even if we're in a pipe (thanks Pow)
TTY="/dev/$( ps -p$$ -o tty | tail -1 | awk '{print$1}' )"
read -p "*** Do you want to reinstall the 'pg' gem [y/n]?" REINSTALL_PG < $TTY
if [[ $REINSTALL_PG == "y" ]]; then
gem uninstall pg
gem install pg
# Ask if the user wants to setup the db with a 'root' superuser?
mdespuits /
Created May 3, 2012
Add to Mac OS X hosts file
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo ' is already specified in your hosts file'
echo ' was added to your hosts file!'
mdespuits / gist:2492087
Created Apr 25, 2012 — forked from thommahoney/gist:2491946
RailsConf 2012 Lightning Talks
View gist:2492087
1 min:
~Painless Javascript
koting hatduklgg
with wind tunnel
~tenderlove.dup jremsikjr
(collecting resources for learning ruby)
You can’t perform that action at this time.