This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fonction de calcul de la clé RIB en javascript | |
function cle_rib(code_banque, code_guichet, numero_compte){ | |
var mapping = ["", "AJ", "BKS", "CLT", "DMU", "ENV", "FOW", "GPX", "HQY", "IRZ"]; | |
var cherche_lettre = new RegExp(/[A-Z]/g); | |
var res = numero_compte.match(cherche_lettre); | |
if(res.length > 0){ | |
res.forEach(function(ch){ | |
mapping.forEach(function(str, i){ | |
if(str.includes(ch)){ | |
numero_compte = numero_compte.replace(new RegExp(ch,"g"), i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Methode de calcul de la clé RIB (relevé d'identité bancaire) | |
# le calcul vient de wikipedia fr | |
def cle_rib(code_banque, code_guichet, numero_compte) | |
mapping = ["", "AJ", "BKS", "CLT", "DMU", "ENV", "FOW", "GPX", "HQY", "IRZ"] | |
numero_compte.scan(/[A-Z]/).each do |ch| | |
mapping.each_with_index do |str, i| | |
if str.include?(ch) | |
numero_compte = numero_compte.gsub(ch, i.to_s) | |
break | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clé integer | |
2.3.3 :054 > { 4 => 'truc' } | |
=> {4=>"truc"} | |
2.3.3 :055 > { 4: 'truc' } | |
SyntaxError: (irb):55: syntax error | |
# Clé string | |
2.3.3 :061 > { 'cle': 'truc' }['cle'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# @rivsc / http://blog.escarworld.com | |
require 'rpi_gpio' | |
PIN_NUM = 12 | |
RPi::GPIO.set_numbering :board | |
RPi::GPIO.setup PIN_NUM, :as => :output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'Benchmark' | |
def inject_method(arr) | |
arr.inject(Hash.new(0)) { |a, e| a[e] += 1 ; a } | |
end | |
def each_wo_method(arr) | |
arr.each_with_object(Hash.new(0)) { |e, a| a[e] += 1 } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test < ActiveRecord::Base | |
belongs_to :bidule | |
has_many :truc | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'prawn' | |
Prawn::Document.generate("make_a_broken.pdf") do |pdf| | |
pdf.font_size 12 | |
pdf.move_down 20 | |
pdf.font "Helvetica" | |
# We use the rollback method so the text in this block should not be displayed | |
pdf.transaction do |