Instantly share code, notes, and snippets.

# Claudel Sylvainrivsc

• Sort options
Created Oct 25, 2019
Calcul clé rib javascript
View calcul_cle_rib.js
 // 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);
Last active Oct 25, 2019
Méthode de calcul de la clé RIB (relevé d'identité bancaire)
View calcul_cle_rib.rb
 # 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
Created Jun 14, 2017
Hash syntaxe
View hash
 # 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']
Last active Sep 13, 2018
Raspberrypi with custom flash light
View photoflash.rb
 #!/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
Last active Aug 10, 2016
View gist:d25aa3bec65ec9166cb7543f56182a1f
 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
Created Mar 30, 2015
View gist:71481becaeb7ff2a5b95
 class Test < ActiveRecord::Base belongs_to :bidule has_many :truc end
Created Nov 14, 2011
Prawn #rollback method is broken
View prawn_rollback_test.rb
 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
You can’t perform that action at this time.