Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am kdisneur on github.
  • I am kdisneur (https://keybase.io/kdisneur) on keybase.
  • I have a public key whose fingerprint is 6788 1927 15C5 4ABA 18BA 8564 6D50 AEFB 5386 EAB3

To claim this, I am signing this object:

require 'benchmark'
Benchmark.bm do |x|
x.report('String') { 1_000_000.times { "ma_valeur" } }
x.report('String to_sym') { 1_000_000.times { "ma_valeur".to_sym } }
x.report(':String') { 1_000_000.times { :"ma_valeur" } }
x.report('sym') { 1_000_000.times { :ma_valeur } }
end
# user system total real
require 'benchmark'
class A
def double_with_hash_param(h)
h[:value] * 2
end
def double_with_reused_hash_param(h)
h[:value]
h[:value] * 2
@kdisneur
kdisneur / gist:2337544
Created April 8, 2012 14:19
improve ordinal_array speed
require './lib/ordinal_array'
require "benchmark"
number_values = (0...999).sort_by{rand}
number_letters = [
:first, :second, :third, :fourth, :fifth, :sixth, :seventh, :eighth, :ninth,
:tenth, :eleventh, :twelfth, :thirteenth, :fourteenth, :fifteenth, :sixteenth, :seventeenth, :eighteenth, :nineteenth,
:twentieth, :twenty_first, :twenty_second, :twenty_third, :twenty_fourth, :twenty_fifth, :twenty_sixth, :twenty_seventh, :twenty_eighth, :twenty_ninth,
:thirtieth, :thirty_first, :thirty_second, :thirty_third, :thirty_fourth, :thirty_fifth, :thirty_sixth, :thirty_seventh, :thirty_eighth, :thirty_ninth,
:fortieth, :fourty_first, :fourty_second, :fourty_third, :fourty_fourth, :fourty_fifth, :fourty_sixth, :fourty_seventh, :fourty_eighth, :fourty_ninth,
syntax on
filetype plugin indent on
set nowrap
set tabstop=2
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set shiftwidth=2 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch " set show matching parenthesis
@kdisneur
kdisneur / gist:3104921
Created July 13, 2012 13:36
shared class variables in module
module SpecialAttributes
module ClassMethods
def attr_special(*attrs)
class_attribute :special_attributes
self.special_attributes = attrs
end
def special_attributes
self.special_attributes
end
@kdisneur
kdisneur / tmux.conf
Created July 13, 2012 13:37
tmux.conf
set -sg escape-time 1
set -g base-index 1
set-window-option -g pane-base-index 1
set-window-option -g automatic-rename off
# pane configuration
bind | split-window -h
bind - split-window -v
bind h select-pane -L
@kdisneur
kdisneur / recreate_database.sh
Created August 29, 2012 16:02
Recreate database
#! /bin/sh
env=${1:-test}
for action in drop create migrate; do
RAILS_ENV=$env rake db:$action;
done
@kdisneur
kdisneur / gist:4045596
Last active October 12, 2015 15:08
trouve toutes les couleurs définies dans le css
color_pattern='#[a-fA-F0-9]{3,6}';
for color in $(find app/assets/stylesheets -iname '*.scss*' -exec grep -oE "${color_pattern}([^_-]|$)" {} \; | grep -oE $color_pattern | sort | uniq); do
if [ $color != ':' ]; then
echo "couleur: $color, occurences: $(grep -R $color app/assets/stylesheets | wc -l)"
fi
done

UIActivityIndicatorView

@property (readwrite, nonatomic, retain) UIColor *color

UIBarButtonItem

- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics