Skip to content

Instantly share code, notes, and snippets.

@nmeylan
nmeylan / my_prompt.sh
Created February 2, 2015 08:08
My prompt
PS1='\[\e[35m\]\u\[\e[m\]@\[\e[36m\]\h\[\e[m\]:\[\e[93m\]\w\[\e[m\]$(__git_ps1 \("%s"\)) \[\e[92m\]\t\[\e[m\] \$'
@nmeylan
nmeylan / fast_rails_test_env.md
Last active August 29, 2015 14:14
Set up a fast rails test environment

Use sqlite in memory db :

config/database.yml

  test:
    adapter: sqlite3
    database: ":memory:"

Setup Spring configuration to run with in memory db :

config/spring.rb

@nmeylan
nmeylan / spring_test.sh
Last active August 29, 2015 14:14
Command line : Run rake test for the given file and/or given method
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Please provide arguments at least 1 argument. You use the command as following"
echo "sptest test_file"
echo "sptest test_file test_case"
else
if [ $# -eq 2 ]; then
test_case=$2
test_case=${test_case// /_}
@nmeylan
nmeylan / list_X_packages_inline.sh
Last active August 29, 2015 14:12
List all audio package (sample)
dpkg-query -l | grep -i audio | grep -oP '[rci]{2}\s{2}\K(\w*[\:\-\.]*\w*)*' | perl -e 's/\n/\s/g' -pi
RAILS_VERSION = '4.2.0' # switch '4.1.8' '4.2'
# Remember to rm Gemfile when switch version.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '#{RAILS_VERSION}'
gem 'sqlite3'
gem 'pg'
gem 'byebug'
@nmeylan
nmeylan / issue_benchmark_script.rb
Last active August 29, 2015 14:11
issue_benchmark_script
ENV['RAILS_ENV'] = 'development'
require File.expand_path('../../config/environment', __FILE__)
RAILS_VERSION = Rails.version
ITERATIONS = 5
# Database contains :
# 10_000 issues
# 30 categories
# 3 trackers

Here the result of the benchmark :

                                                  user     system      total        real
    
    Iteration n: 1
    Rails 4.1.8 : 1 relation                   0.490000   0.020000   0.510000 (  0.531127)
    Rails 4.1.8 : 2 relations                  0.530000   0.020000   0.550000 (  0.554869)
    Rails 4.1.8 : 1 nested relation            0.570000   0.020000   0.590000 (  0.607984)

Iteration n: 2

logger.formatter = ->(severity, datetime, progname, msg) do
"#{datetime.strftime('%Y-%m-%d %H:%M:%S')} - #{sprintf('%-5s',severity)} - #{msg}\n"
end
@nmeylan
nmeylan / sample_benchmark_template
Created December 18, 2014 20:04
Ruby benchmark template
require 'Benchmark'
ITERATION = 100_000
Benchmark.bm(27) do |bm|
bm.report('TEST 1') do
ITERATION.times do
# test 1 content
end
@nmeylan
nmeylan / git_conf_aliases
Created December 4, 2014 17:00
Git config aliases
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%C(yellow)%h %C(cyan)%ad %C(white)| %s%C(green bold)%d %Creset%C(magenta)[%an]\" --graph --date=rfc
type = cat-file -t
dump = cat-file -p