Skip to content

Instantly share code, notes, and snippets.

View changa's full-sized avatar

Dominique Rose-Rosette changa

  • Praditus
  • Paris, France
View GitHub Profile
# Stupid dirty trick to return a HTTP status code 500 when testing a Rails app
class ApplicationController < ActionController::Base
if Rails.env == 'test'
rescue_from 'ActionView::TemplateError' do |exception|
render :text => exception, :status => 500
end
end
@changa
changa / gist:786034
Created January 19, 2011 11:28
Terrible rspec performance with Ruby 1.9.2 & Rails 3.0.3
1.9.2@opera changa:~/webdev/projets/opera/code develop! $ ruby-prof -m 1 /home/drr/.rvm/gems/ruby-1.9.2-p136@opera/bin/rspec spec
No examples were matched by {:focus=>true}, running all
..................................**....
Pending:
Article add some examples to (or delete) /home/drr/webdev/projets/opera/code/spec/models/article_spec.rb
# Not Yet Implemented
# ./spec/models/article_spec.rb:4
ArticlesHelper add some examples to (or delete) /home/drr/webdev/projets/opera/code/spec/helpers/articles_helper_spec.rb
# Not Yet Implemented
@changa
changa / gist:789535
Created January 21, 2011 10:58
Nice autoselection transforms for urxvt & vim
# ~/.Xdefaults
# Shamelessly stolen from https://github.com/tpope/tpope/blob/master/.Xresources
# and http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.7.pod
# This will automatically put "+line_number file_name" in the clipboard when clicking on a Ruby backtrace
URxvt.perl-lib: /usr/lib64/urxvt/perl # YMMV
URxvt.perl-ext-common: default,selection-autotransform,selection-pastebin,remote-clipboard
URxvt.selection-autotransform.0: if(/\\n\\[?\\d\\d(\\d\\d-|:)\\d\\d/) { s{^\\[?[\\d:_-]+\\]? +}{}; s/\\s*\\n\\[?[\\d:_-]{5,}\\]? +/ || /g; s/^\\s+/ /mg; s/( ?) \*\\n( ?)/($1||$2)/eg; s{ $}{}; };
@changa
changa / gist:897915
Created April 1, 2011 09:05
Vim snippet for automatically prepending an encoding line for ruby files
# .vimrc
" Add default utf-8 encoding to ruby files
:autocmd BufNewFile *.rb,*.rake 0r ~/.vim/skeletons/skeleton.rb
$ cat ~/.vim/skeletons/skeleton.rb
# encoding: utf-8
$
@changa
changa / gist:1183434
Created August 31, 2011 12:37
jasmine-headless-webkit backtrace
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:553:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension ext/jasmine-webkit-specrunner/extconf.rb. (#<ArgumentError: invalid byte sequence in UTF-8>) (Gem::Installer::ExtensionBuildError)
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:20:in `gsub'
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:20:in `make'
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:18:in `build'
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:532:in `block (2 levels) in build_extensions'
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:531:in `chdir'
/home/drr/.rvm/rubies/ruby-1.9.2-p180-patched/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:531:in `block in build_extensions'
/
@changa
changa / gist:1234795
Created September 22, 2011 13:41
ldd jasmine-webkit-specrunner
1.9.2@global|drr@drr-x201:~/.rvm/gems/ruby-1.9.2-p180-patched@ftv/gems/jasmine-headless-webkit-0.7.1 $ ldd ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner
linux-vdso.so.1 => (0x00007ffff97ff000)
libQtWebKit.so.4 => /usr/lib/libQtWebKit.so.4 (0x00007fcf562f5000)
libQtGui.so.4 => /usr/lib/libQtGui.so.4 (0x00007fcf55615000)
libQtNetwork.so.4 => /usr/lib/libQtNetwork.so.4 (0x00007fcf552d4000)
libQtCore.so.4 => /usr/lib/libQtCore.so.4 (0x00007fcf54e2f000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcf54c13000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcf54908000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcf54686000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcf54470000)
@changa
changa / .pryrc
Created June 15, 2012 14:19
Pryrc stuff
# vim: se ft=ruby :
# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953
if defined?(::Bundler) || File.exists?('Gemfile')
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first
if global_gemset
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*")
all_global_gem_paths.each do |p|
gem_path = "#{p}/lib"
$LOAD_PATH << gem_path
@changa
changa / .gitconfig
Last active October 11, 2015 07:58
$HOME/.gitconfig
# vim: se ft=gitconfig :
[diff]
color = true
[alias]
; shortcuts
st = status
a = add
ap = add -p
@changa
changa / gist:4761918
Created February 12, 2013 12:11
${HOME}/.pryrc
# vim: se ft=ruby :
# ${HOME}/.pryrc
# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953
if defined?(::Bundler) || File.exists?('Gemfile')
global_gemset = ENV['GEM_PATH'].split(':').grep(%r{ruby.*@global|gemsets/global}).first
if global_gemset
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*")
all_global_gem_paths.each do |p|
@changa
changa / locks.sql
Created April 10, 2014 14:20
Show current locks (for PosgreSQL < 9.2)
-- Taken from http://wiki.postgresql.org/wiki/Lock_Monitoring
-- (PostgreSQL < 9.2 version)
SELECT bl.pid AS blocked_pid,
a.usename AS blocked_user,
ka.current_query AS blocking_statement,
now() - ka.query_start AS blocking_duration,
kl.pid AS blocking_pid,
ka.usename AS blocking_user,
a.current_query AS blocked_statement,
now() - a.query_start AS blocked_duration