Skip to content

Instantly share code, notes, and snippets.

def a
'a'
end
if true
a = 'b'
end
puts a
# => 'b'
@pcreux
pcreux / memoize.rb
Created December 17, 2010 19:17
operator priorities
def a
puts 'a'
'a'
end
def null
puts 'null'
nil
end
# /etc/init.d/* scripts always have to be run as 'root'. These scripts take care of
# launching processes with the right user (www-data, aptproxy, nagios ...)
define :monit_process, :pid_file => nil, :executable => nil, :user => 'root', :group => nil do
execute "monit_reload" do
command "/usr/sbin/monit reload"
end
template "/etc/monit/conf.d/#{params[:name]}.monitrc" do
source "monit_process.monitrc.erb"
@pcreux
pcreux / awesomer.rb
Created June 2, 2011 00:12
Convert markdown inline links to link definitions
# For https://github.com/guard/guard/blob/master/CHANGELOG.md
str = File.read('CHANGELOG.md')
people = []
str.each_line do |l|
found = l.match(/\[@(\w+)\]\(([\w:\/.]+)\)/)
if found
user = found[1]
@pcreux
pcreux / play_remote.zsh
Created June 15, 2011 15:57
Zsh autocompletion is easy. That's how we play sounds on a remote computer with autocompletion.
aplay () { ssh applemini "afplay Music/$1" }
alist () { ssh applemini "ls Music" }
compctl -k "(`alist`)" aplay
@pcreux
pcreux / order.rb
Created July 29, 2011 16:34
active_admin custom collection action with filtering and sorting
ActiveAdmin.register Order do
# Export the current collection of items with filtering and sorting
# List the current collection ids
collection_action :export_txt do
render :text => collection.map { |order| order.id }.join(', ')
end
# Add a button to index page to export current collection as txt
@pcreux
pcreux / gist:1186998
Created September 1, 2011 19:15
Speed up nginx ssl proxy
# SSL Session Cache + Browser Leverage Caching
server {
ssl_session_cache shared:SSL:10m; # Reuse session => less handshakes => better perfs
# Proxy config ==============================================================
location / {
# Cache assets (Do NOT cache html pages as they contain AuthenticityTokens)
if ($request_uri ~* ^.+\.(svg|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2)$) {
add_header Cache-Control public;
expires max;
@pcreux
pcreux / .zshrc
Created September 14, 2011 10:03
Zsh function - set upstream to origin so that you can pull / push from the current branch without specifying the remote one
git-set-upstream () {
local branch=`git branch | grep '*' | sed 's/* //'`
git branch --set-upstream $branch origin/$branch
}
@pcreux
pcreux / .zshrc
Created September 16, 2011 14:39
This makes cucumber features twice as fast. (25 min => 11min)
# Speed up REE
export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=1000000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_HEAP_FREE_MIN=500000
@pcreux
pcreux / .vimrc
Created September 16, 2011 15:15
Vim command to delete trailing spaces
" Press F5 to delete trailing spaces
map <silent> <F5> :let _s=@/<Bar>:%s/\(\S\)\s\+$/\1/e<Bar>:let @/=_s<Bar>:nohl<CR>