Skip to content

Instantly share code, notes, and snippets.

View nicordev's full-sized avatar

Nicolas Renvoisé nicordev

View GitHub Profile
@nicordev
nicordev / create_or_get_element_by_id
Last active December 24, 2018 17:05
Create a DOM element if it does not exist already
/**
* Create a DOM element if it does not exist already
*
* @param {String} id the id of the element
* @param {String} eltTag HTML tag of the element
* @param {String} txtContent = '' the content of the element
* @return {DOM element} the DOM element
*/
function createOrGetElementById(id, eltTag, txtContent = '') {
@nicordev
nicordev / calculateDistanceLatLng
Created December 24, 2018 17:04
Calculate the distance between 2 points knowing their longitude and latitude
/**
* Retourne la distance entre 2 points avec des coordonnées géographiques en mètres ou kilomètres
* @param lat1 la latitude du point 1
* @param lng1 la longitude du point 1
* @param lat2 la latitude du point 2
* @param lng2 la longitude du point 2
* @param [unit] 'k' pour un résultat en kilomètre
* @return la distance en mètres ou kilomètres
*/
function calculateDistanceLatLng(lat1, lng1, lat2, lng2, unit = 'm') {
@nicordev
nicordev / calculateAzimuth
Created December 24, 2018 17:05
Calculate heading between 2 points knowing their longitude and latitude
/**
* Calcul l'azimut entre 2 points de coordonnées géographiques connues
* @param lat1 la latitude du point 1
* @param lng1 la longitude du point 1
* @param lat2 la latitude du point 2
* @param lng2 la longitude du point 2
* @return l'azimut en degrés (en anglais azimuth)
*/
function calculateAzimuth(lat1, lng1, lat2, lng2) {
@nicordev
nicordev / basic_animator.js
Created May 17, 2019 13:16
Basic javascript object to animate DOM elements
/**
* Object containing methods to animate DOM elements
*
* @type {{rotate: animator.rotate, moveY: animator.moveY, moveX: animator.moveX}}
*/
var animator = {
/**
* Rotate a DOM element using CSS property transform and the deg unit
*
@nicordev
nicordev / domKiller.js
Last active May 20, 2019 06:31
Hide or remove DOM elements of a page by clicking on it (left click: hide, middle + left button: remove)
var domKiller = {
hiddenElements: [],
activated: false,
/**
* Initialize and activate the remove action when clicking simultaneously on left and middle mouse button and the hide action when clicking on the left mouse button
*/
init: function () {
@nicordev
nicordev / intro.html
Last active September 16, 2019 20:23
Quick start guide for leaflet from leafletjs.com
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
@nicordev
nicordev / password_hash.php
Created September 27, 2019 16:44
Hash a password using php in the command line
<?php
echo "Password: ";
fscanf(STDIN, "%s\n", $password);
echo "$password\nHash using password_hash() and PASSWORD_DEFAULT: ";
echo password_hash($password, PASSWORD_DEFAULT);
@nicordev
nicordev / AppFixtures.php
Last active July 23, 2020 13:48
ApiPlatform & React formation - Fixtures refactoring for myself
<?php
namespace App\DataFixtures;
use App\Entity\Customer;
use App\Entity\Invoice;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Faker\Factory;
@nicordev
nicordev / labyrinthe.js
Created December 18, 2019 20:45
blockly-games labyrinthe
while (notDone()) {
if (isPathLeft()) {
turnLeft();
moveForward();
} else {
if (isPathForward()) {
moveForward();
} else {
if (isPathRight()) {
turnRight();
@nicordev
nicordev / display.css
Created February 15, 2020 21:37
Display an element if you hover or tap on another element.
.switch-display
{
display: none;
}
.switch-display-trigger:hover .switch-display, .switch-display-trigger:focus .switch-display
{
display: inline;
}