Skip to content

Instantly share code, notes, and snippets.

@fguillen
fguillen / EvasiveMouse.md
Created February 27, 2012 17:15
Coding Puzzle example

EvasiveMouse

An smart mouse always obtains the cheese without being detected.

Description

You are an office mouse, and you're very lucky because in every office of the building where you live there is always one piece of cheese.

You have worked hard to make one mousehole in every office.

@fguillen
fguillen / config.log
Created January 21, 2012 18:53
brew install ffmpeg ERROR
# ./configure --prefix=/usr/local/Cellar/ffmpeg/0.9.1 --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-libfreetype --cc=/usr/bin/clang --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --disable-ffplay
ACODEC_TESTS='ac3_fixed_test
adpcm_ima_qt_test
adpcm_ima_wav_test
adpcm_ms_test
adpcm_swf_test
adpcm_yam_test
alac_test
aref_test
flac_test
@fguillen
fguillen / hash_with_indifferent_access_extension.rb
Created December 30, 2011 17:05
to_hash recursive for HashWithIndifferentAccess
class HashWithIndifferentAccess < Hash
def to_hash_recursive
result = self.to_hash
result.each do |key, value|
if(value.is_a? HashWithIndifferentAccess)
result[key] = value.to_hash_recursive
end
end
@fguillen
fguillen / compass.rake
Created December 13, 2011 17:58
Compass rake task
namespace :compass do
desc 'Compile SCSS to CSS'
task :compile do
old_argv = ARGV
ARGV = []
load Gem.bin_path('compass', 'compass', ">=0")
ARGV = old_argv
end
@fguillen
fguillen / regex.irb
Created December 12, 2011 09:21
Non Greedy Regex match
# By default ReGex will match the bigest occurrence:
ruby-1.9.2-p180 > "_one_ two _three_".scan(/_(.+)_/)
=> [["one_ two _three"]]
# But we can tell it to match all the smallest ones:
ruby-1.9.2-p180 > "_one_ two _three_".scan(/_(.+?)_/)
=> [["one"], ["three"]]
@fguillen
fguillen / log_processor.rb
Created October 26, 2011 12:05
Rails log processor, show the milliseconds and the request
# use:
# ruby log_processor.rb log/production.log
#
# result:
# [ 168] /folders/xxx1.vitreous.co/fill_it
# [1816] /folders/xxx2.vitreous.co/auth
# [1230] /folders/xxx2.vitreous.co/auth_confirm?uid=1488231&oauth_token=myusjr3gg59ntdi
# [ 763] /folders/xxx2.vitreous.co/create_scaffold_form
# [ -] /folders/xxx2.vitreous.co/create_scaffold
# [ -] /folders/xxx2.vitreous.co/create_scaffold
@fguillen
fguillen / dropbox_entry_recursive_hash.rb
Created August 16, 2011 15:13
Dropbox: calculate a directory hash that includes every recursive subfolder
module Dropbox
class Entry
def recursive_hash
return metadata.hash unless metadata.is_dir
recursive_hashes =
list.select{ |e| e.is_dir }.map do |e|
@session.entry( e.path ).recursive_hash
end
@fguillen
fguillen / crontab
Created August 9, 2011 09:05
Cron & RVM & Bundle & Rails & Rake & log
00 01 * * * /bin/bash --login -c 'cd <your app> && RAILS_ENV=production /usr/bin/env bundle exec rake <your rake>' >> /var/log/<your app>.log 2>&1
@fguillen
fguillen / mustache_filter.rb
Created July 30, 2011 13:48
Mustache filter
# Wanting to use the _filter_ feature of _Liquid_ in _Mustache_?, no problem:
# To MarkDown filter in Mustache
require 'rubygems'
require 'mustache'
require 'rdiscount'
class MyView < Mustache
def to_md( text )
RDiscount.new( text ).to_html
@fguillen
fguillen / my_file.rb
Created July 25, 2011 20:44
not require rubygems
begin
require 's3'
rescue LoadError
require 'rubygems'
require 's3'
end