Skip to content

Instantly share code, notes, and snippets.

View jlecour's full-sized avatar

Jérémy Lecour jlecour

View GitHub Profile
@jlecour
jlecour / deploy.rb
Created April 6, 2012 10:39
A common (little) effort with @madx to reduce the pain when building a string with a subset of an ENV. Usage example ; giving Capistrano some environment variables to pass to a rake task on remote servers.
# put this in your Capistrano recipe
def subenv_string(env, *keys)
(env.keys & keys).map {|k| "#{k}=#{env[k].inspect}" }.join(' ')
end
# Capistrano task
namespace :deploy
task :my_cap_task do
task_env = subenv_string(ENV, *%w(FOO BAR))
run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} #{task_env} my_rake_task"
@jlecour
jlecour / gist:2477311
Created April 24, 2012 07:04
A bash/zsh alias to open a "Textmate project" file, named after the current working directory, if present, or falling back to simply open the current directory. Put this with your aliases, like `~/.bashrc` for example.
function tmproj(){
file=${PWD##*/}.tmproj
if [ -f $file ]; then
command open ./$file
else
command mate .
fi
}
@jlecour
jlecour / kill_passenger_orphans.sh
Created May 21, 2012 08:22
A script to kill Passenger processes that are not known anymore by the watchdog
#!/bin/bash
set -e
# overridable defaults
GEM_HOME=${GEM_HOME:-/usr/local/passenger}
PASSENGER_BIN_PATH=${PASSENGER_BIN_PATH:-$GEM_HOME/bin}
PASSENGER_TMPDIR=${PASSENGER_TMPDIR:-/var/tmp}
PATH=$PATH:$PASSENGER_BIN_PATH
@jlecour
jlecour / save_apache_status.sh
Created June 8, 2012 23:58
Save Apache status to a file and files older than 1 day. Run this from a crontab to do it automatically
#!/bin/bash
set -e
DIR=/var/log/apache-status
URL=http://example.com/server-status/
TS=`date +%Y%m%d%H%M%S`
FILE="$DIR/$TS.html"
mkdir -p $DIR
@jlecour
jlecour / init_unicorn.sh
Created June 25, 2012 13:39
Unicorn configuration
#!/bin/bash
set -e
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@jlecour
jlecour / gist:3045970
Created July 4, 2012 07:52
Multiple Redis instances on Mac OS X with Homebrew
@jlecour
jlecour / gist:3515210
Created August 29, 2012 16:25
Textmate variable extraction from source code

In a situation like this (pseudo code)

assert a_method(with, many, arguments)

I'd like to select the a_method(...) part, launch a macro/command/whatever and get that :

variable = a_method(with, many, arguments)
@jlecour
jlecour / var-from-selection.tmCommand
Created August 31, 2012 08:13 — forked from sellmerfud/var-from-selection.tmCommand
Textmate bundle command to create a variable declaration with the contents of the selection.
#!/usr/bin/env ruby -wKU
# Save: Nothing
# Input: Document
# Output: Replace Input
# Caret Placement: Line Interpolation
COCOA_DIALOG_COMMAND = "#{ENV["TM_SUPPORT_PATH"]}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog"
@jlecour
jlecour / test_signal.rake
Created May 3, 2013 15:25
A strange issue with signals and ActiveRecord connections
task :test_signal => :environment do
last_record = nil
puts $$
Signal.trap('USR1') do
puts last_record.id
end
Model.find_in_batches do |batch|
batch.each do |item|
→ dig www.destroyallsoftware.com
; <<>> DiG 9.8.3-P1 <<>> www.destroyallsoftware.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32151
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.destroyallsoftware.com. IN A