Skip to content

Instantly share code, notes, and snippets.

View mdespuits's full-sized avatar

Matthew Wells mdespuits

View GitHub Profile
@mdespuits
mdespuits / handlebars-1.0.0.beta.6.js
Created April 20, 2012 14:56
mattdbridges favorite javascript resources
// lib/handlebars/base.js
var Handlebars = {};
Handlebars.VERSION = "1.0.beta.6";
Handlebars.helpers = {};
Handlebars.partials = {};
Handlebars.registerHelper = function(name, fn, inverse) {
if(inverse) { fn.not = inverse; }
@mdespuits
mdespuits / gist:2492087
Created April 25, 2012 18:41 — forked from thommahoney/gist:2491946
RailsConf 2012 Lightning Talks
1 min:
~Painless Javascript
koting hatduklgg
with wind tunnel
~tenderlove.dup jremsikjr
~iwanttolearnruby.com
(collecting resources for learning ruby)
@mdespuits
mdespuits / add_lvhme.sh
Created May 3, 2012 15:34
Add lvh.me to Mac OS X hosts file
#!/bin/bash
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo 'lvh.me is already specified in your hosts file'
else
add_lvh_me
echo 'lvh.me was added to your hosts file!'
fi
flush_dns_cache
@mdespuits
mdespuits / basic_postgres_setup.sh
Created May 15, 2012 16:50
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
fi
# Ask if the user wants to setup the db with a 'root' superuser?
@mdespuits
mdespuits / chef-solo-ubuntu-12-04
Created June 29, 2012 05:52
Chef Solo Setup for 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
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local
make
make install
@mdespuits
mdespuits / brew-config
Created August 3, 2012 15:15
Node.js installation issues
HOMEBREW_VERSION: 0.9.2
HEAD: 3113434e7107c928dcfd411160bf44b921dd564d
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit sandybridge
OS X: 10.7.4-x86_64
Xcode: 4.4
CLT: 1.0.0.9000000000.1.1249367152
GCC-4.0: N/A
GCC-4.2: build 5666
@mdespuits
mdespuits / backtrace.txt
Created August 15, 2012 21:40
Cancan block ability error in v1.6.8
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
mdespuits / sublime_shortcuts.md
Last active October 9, 2015 15:28 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 - Useful Shortcuts (Mac OS X)

General

Command Action
⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
@mdespuits
mdespuits / bench_str_building.rb
Created August 31, 2012 15:31 — forked from alno/bench_str_building.rb
Benchmark: interpolation vs concatenation in Ruby
require 'benchmark'
count = 1_000_000
Benchmark.benchmark do |bm|
bm.report("concat") { count.times { 11.to_s + '/' + 12.to_s } }
bm.report("interp") { count.times { "#{11}/#{12}" } }
end
@mdespuits
mdespuits / some_object_tap_uses.rb
Last active December 10, 2015 18:58
Example uses of Object#tap that I really like
# 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
private
def log_action_with_tap
"[ACTION LOG]: #{current_account.name} tried to #{action_name} #{controller_path}".tap{|l|
l << flash.map{|k,v| "#{k}: #{v}"}.join(',') if flash.any?