Skip to content

Instantly share code, notes, and snippets.

@jbdesbas
jbdesbas / Vector.js
Created January 1, 2018 08:37 — forked from jjgrainger/Vector.js
A simple Vector class in javascript
var Vector = function(x, y) {
this.x = x || 0;
this.y = y || 0;
};
// return the angle of the vector in radians
Vector.prototype.getDirection = function() {
return Math.atan2(this.y, this.x);
};
@jbdesbas
jbdesbas / my_taxref.sql
Created July 29, 2019 12:55
GeoNature. Petit trick pour modifier les noms français et cd_ref (attention, le trigger modifie la table taxonomie.taxref)
CREATE TABLE taxonomie.taxref_mytaxref (
cd_nom integer UNIQUE,
cd_ref integer,
nom_vern varchar(1000)
)
COMMENT ON TABLE taxonomie.taxref_mytaxref IS 'Attention, les modifications de cd_ref ou nom_vern intégrées dans cette table écraserons les valeurs de la table taxref.';
CREATE OR REPLACE FUNCTION taxonomie.fct_trg_refresh_taxons_forautocomplete()
RETURNS trigger
LANGUAGE plpgsql
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
# name = value
#
# (The "=" is optional.) Whitespace may be used. Comments are introduced with
# "#" anywhere on a line. The complete list of parameter names and allowed
@jbdesbas
jbdesbas / matomo.js
Created November 15, 2019 14:40
Geonature citizen, tracking matomo (piwiki)
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//MY_MATOMO_URL/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 'MY_MATOMO_ID_SITE']);
@jbdesbas
jbdesbas / geonature_status.sql
Last active December 27, 2019 08:32
projet pour gérer les statuts de taxon dans taxhub/geonature. Permet de gérer les statuts localiser (LR régionnal, sous-population, arrêtés municipaux, etc..)
/*
--Fonction pas encore dans taxhub
CREATE OR REPLACE FUNCTION taxonomie.find_all_taxons_parents(id integer)
RETURNS TABLE(cd_nom integer, id_rang character varying)
LANGUAGE plpgsql
IMMUTABLE
AS $function$
--Param : cd_nom d'un taxon quelque soit son rang
--Retourne une table avec le cd_nom de tout les taxons parents et leur id_rang.
--Retourne le cd_nom de tous les taxons parents sous forme d'un jeu de données utilisable comme une table. Les cd_nom sont ordonnées du plus bas vers le plus haut (Dumm)
from utils_flask_sqla import response
from datetime import date, time, datetime
import uuid
test_dict=dict(
my_datetime=datetime.now(),
my_uuid=uuid.uuid4(),
my_time=time(12,54),
@jbdesbas
jbdesbas / observation.json
Created October 9, 2020 11:26
gn monitoring config observation
{
"specific": {
"cd_nom": {
"type_widget": "taxonomy",
"attribut_label": "Taxon",
"type_util": "taxonomy",
"required": true,
"idComponent": "100"
},
"id_nomenclature_nature_observation": {
@jbdesbas
jbdesbas / exemple_taxref_tree_parents.sql
Last active October 29, 2020 11:05
Exemple taxref_tree_parents
--Selection des occurences d'Odonates [185356] et taxons inférieurs
--A utiliser également pour sélectionner des espèces, afin d'inclure les éventuelles sous-espèces
SELECT s.*
FROM gn_synthese.synthese s
JOIN taxonomie.taxref t USING (cd_nom)
JOIN taxonomie.taxref_tree_parents ttp ON ttp.cd_nom_parent = t.cd_ref
WHERE ttp.cd_nom_parent = 185356
--Exemple 2 : Liste des parents sous format JSON
@jbdesbas
jbdesbas / upload_media_to_s3.py
Created November 5, 2020 08:49
Taxhub : upload media to S3 cloud
"""A lancer à la racine du dossier Taxhub, après avoir renseigner les accès du S3
dans le fichier de config et activé l'environnement virtuel"""
import config
import os
import boto3
import mimetypes
s3 = boto3.client('s3',
aws_access_key_id=config.S3_KEY,
@jbdesbas
jbdesbas / geoserver2pg.sql
Last active March 24, 2022 14:48
Insert geonetwork mtd into PG
CREATE TABLE xml_mtd ("xml" xml);
/*COPY distant XML file (with removing line feed) */
COPY xml_mtd FROM PROGRAM 'curl "https://www.geo2france.fr/geonetwork/srv/api/records/6ea5c1bd-b10b-4f7e-9139-2f878c63fc74/formatters/xml?attachment=true&approved=true" | tr -d "\n" ';
/*Extract relevant data*/
WITH ns AS (
SELECT ARRAY[
ARRAY['gmd', 'http://www.isotc211.org/2005/gmd'],
ARRAY['gco', 'http://www.isotc211.org/2005/gco'],