Skip to content

Instantly share code, notes, and snippets.

@jbdesbas
jbdesbas / rebase.md
Created April 11, 2024 07:20
rebase
git checkout feature
git rebase dev
git push --force # car l'historique a changé, OK si personne ne travail sur _feature_
@jbdesbas
jbdesbas / dataGroupBy.ts
Last active January 17, 2024 20:03
Javascript groupby
const dataGroupBy = (data:[], group_fields:string[], metric_field:string, method:string) => {
const agg_function:(arr:[], field:string) => number = ((arr, field) => {
switch(method){
case 'sum':
return _.sumBy(arr, field)
case 'min':
return _.minBy(arr, field)[field]
case 'max':
return _.maxBy(arr, field)[field]
@jbdesbas
jbdesbas / udp_listen.py
Created December 17, 2023 20:42
pocsag log
import socket
import threading
import sys
import logging
import locale
import re
from datetime import datetime
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
@jbdesbas
jbdesbas / montyhall.py
Last active November 11, 2023 13:32
Monty Hall Game
import random
class Door:
def __init__(self, name):
self.is_winner = False
self.is_open = False
self.name = name
self.is_chosen = False
def __repr__(self):
@jbdesbas
jbdesbas / standardize_csv.py
Last active October 10, 2023 13:43
Standardize csv
import io
from sys import stdout, stdin, stderr
import clevercsv
import chardet
"""
Script permettant de lire un csv sur l'entrée standard, et de retourner sur la sortie un CSV RFC-4180 en UTF-8.
Le script detecte l'encoding (chardet) et le dialect (clevercsv).
@jbdesbas
jbdesbas / copy_json.sql
Created September 15, 2023 10:20
psql copy json
\copy mytable from 'fichier.json' WITH csv quote e'\x01' delimiter e'\x02'
@jbdesbas
jbdesbas / col_description.sql
Created March 1, 2023 10:50
Get columns description
select table_name, column_name, col_description((table_schema||'.'||table_name)::text::regclass, ordinal_position)
from information_schema.COLUMNS
where table_schema = 'sinoe' and table_name LIKE 'ind_reg%';
-- https://stackoverflow.com/a/44493548/10995624
@jbdesbas
jbdesbas / v_dataset_as_inspire.sql
Last active March 15, 2023 11:29
pgMetadata INSPIRE
CREATE VIEW pgmetadata.v_dataset_as_inspire AS
WITH "MaintenanceFrequencyCode"(code, inspire_code) AS (
VALUES
('NEC','asNeeded'),
('YEA','annually'),
('MON','monthly'),
('WEE', 'weekly'),
('DAY','daily'),
('TRI', 'quarterly'),
('BIA', 'biannually'),
@jbdesbas
jbdesbas / iinst.sql
Last active May 20, 2022 07:45
Puissance instantannée teleinfo
/*
Indication de la puissance "instantanné" a partir de l'index EDF (en Wh).
Il s'agit en fait l'évolution de l'index sur la plus petite unité de temps possible (dépend de la fréquence de remonté
de l'info, en général 1 min ou 30 sec)
divisée par l'interval entre les deux mesures --> puissance en W.
Sur des intervals de temps plus longz, selon correspond à la puissance moyenne utilisée.
*/
SELECT
*,
@jbdesbas
jbdesbas / onf_parcelle_pub.vrt.xml
Last active May 16, 2022 13:19
onf_parcelle_pub.vrt.xml
<!-- Parcelles forestières de l'Office National des Forêts en Hauts-de-France (buffer km) -->
<OGRVRTDataSource>
<OGRVRTLayer name="parcelle_forestiere">
<SrcDataSource>WFS:http://ws.carmencarto.fr/WFS/105/ONF_Forets?</SrcDataSource>
<SrcLayer>PARC_PUBL_FR</SrcLayer>
<OpenOptions>
<OOI key="EXPOSE_GML_ID">NO</OOI>
</OpenOptions>
<SrcRegion clip="FALSE">POLYGON ((579103 6997695, 580761 7001558, 584837 7004703, 587571 7012556, 591593 7017267, 590762 7022295, 594586 7051079, 593335 7071052, 596473 7076232, 594661 7085073, 595662 7089514, 601773 7092190, 608651 7098986, 618354 7103072, 635982 7106966, 640941 7110703, 645076 7109880, 653102 7112036, 656746 7111226, 669828 7115154, 672622 7112574, 675038 7103420, 678738 7096492, 677637 7085125, 684331 7082539, 689115 7074279, 691164 7074164, 694702 7077503, 706352 7082297, 713130 7081417, 723351 7068188, 722741 7061611, 725127 7050924, 727759 7049711, 732990 7053527, 738247 7052558, 741178 7049682, 746729