Skip to content

Instantly share code, notes, and snippets.

View thb's full-sized avatar

Thomas Blumenfeld thb

View GitHub Profile
#!/usr/bin/ruby
# frozen_string_literal: true
# prendre les 9 premiers chiffres, exception si plus ou moins que 9 chiffres
SIREN = ARGV[0]
# calculer la clé
key = (12 + 3 * (SIREN.to_i % 97)) % 97
# concaténer et prévixer de "FR" pour la france
tva = "FR#{key}#{SIREN}"
puts tva
kill $(ps aux | grep ruby | awk '{print $2}')
\list or \l - to display databases
\connect or \c database_name - to connect to a database
\dn - list of schemas
SHOW search_path;
SET search_path TO xxxxxx;
\dt - to list tables
pg_dump {database} > {dump_name}.sql -U {dbuser} -h {host}
psql -p {port} -d {database} -U {dbuser} -W -f {dump_name}.sql
@thb
thb / fix_locales_ubuntu_server
Created January 9, 2012 15:31
Getting rid of ennoying "locales" messages on ubuntu server
$ sudo locale-gen fr_FR fr_FR.UTF-8
Generating locales...
fr_FR.ISO-8859-1... done
fr_FR.UTF-8... done
Generation complete.
$ sudo dpkg-reconfigure locales
Generating locales...
fr_FR.ISO-8859-1... up-to-date
fr_FR.UTF-8... up-to-date
@thb
thb / gitolite_install
Created January 9, 2012 14:40
Gitolite Installation
Your working on your workstation, your *nix username is "mat". You want to install gitolite on a server
1) go to your server, and with admin rights, create a git user. On ubuntu:
adduser git
2) on your workstation, copy you local SSH public key to the git home directory. On ubuntu:
ssh-copy-id -i ~/.ssh/id_rsa.pub git@server
@thb
thb / bad unaccent
Created June 23, 2011 13:33
Unaccent method for a Ruby string
class String
UNACCENT_HASH = {
'A' => 'ÀÁÂÃÄÅĀĂǍẠẢẤẦẨẪẬẮẰẲẴẶǺĄ',
'a' => 'àáâãäåāăǎạảấầẩẫậắằẳẵặǻą',
'C' => 'ÇĆĈĊČ',
'c' => 'çćĉċč',
'D' => 'ÐĎĐ',
'd' => 'ďđ',
'E' => 'ÈÉÊËĒĔĖĘĚẸẺẼẾỀỂỄỆ',
'e' => 'èéêëēĕėęěẹẻẽếềểễệ',
@thb
thb / grant language postgresql
Created June 23, 2011 13:08
Postgresql : grant usage of c language for a given user
postgres=# GRANT USAGE ON LANGUAGE c TO rails;
ERREUR: le langage « c » n'est pas de confiance
ASTUCE : Seuls les super-utilisateurs peuvent utiliser des langages qui ne sont pas
de confiance.
postgres=# UPDATE pg_language SET lanpltrusted = true WHERE lanname = 'c';
UPDATE 1
postgres=# GRANT USAGE ON LANGUAGE c TO rails;
GRANT