Skip to content

Instantly share code, notes, and snippets.

View decentraliser's full-sized avatar
🦈
In a sharking mood

Decentraliser decentraliser

🦈
In a sharking mood
View GitHub Profile
@decentraliser
decentraliser / jsdocs-type-casting.js
Created January 14, 2022 10:01
jsdocs type casting
const subUser = /** @type {SubUserType} */ (/** @type {unknown} */ (user))
@decentraliser
decentraliser / async-javascript-basics.js
Last active June 7, 2023 05:35
Async JavaScript basics: Promises and async/await
// Asynchronous JavaScript basics
// Asynchronous programming is a way to execute code
// without blocking the execution of the rest of the program.
// We commonly use the asynchronous syntax when we need to
// => Get data from another website or API
// => Retrieving / storing data in a database
// => Write / Read files from file system
@decentraliser
decentraliser / functional-programming.js
Last active June 7, 2023 05:41
Functional programming examples in JavaScript
// COMMON OPERATIONS ON ARRAYS:
// CREATE A NEW VARIABLE
// Array.map => create a new array from an existing array. Each return is a new element of the new array
// Array.filter => create a new array: keeps elements when return true, removes elements when return false
// Array.reduce => create something new (number, string, object, array...) from an existing array. return adds things to the accumulator (acc)
// EXECUTE SIDE EFFECTS
// Array.foreach => Do stuff with each array item (it does not return anything)
@decentraliser
decentraliser / contribution-guidelines.md
Last active September 3, 2021 13:10
Contributions guidelines

When starting a new session

// update your local git repository
git remote update

// update your master branch
git checkout master
git pull

A simple Docker and Docker Compose install script for Ubuntu

Usage

  1. sh install-docker.sh
  2. log out
  3. log back in

Links

@decentraliser
decentraliser / global-gitignore-file.md
Last active November 16, 2020 08:23
Global gitignore file

code ~/.gitconfig

[core]
    excludesfile = ~/.gitignore_global

code ~/.gitignore_global

.idea/
.vscode/
@decentraliser
decentraliser / VAT-from-SIREN.php
Last active September 18, 2020 08:19
Calculer un numéro de TVA à partir d'un numéro SIREN
function getVatNumberFromSiren($siren)
{
$prefix = ((($siren%97)*3)+12)%97;
if ($prefix < 10) {
$prefix = "0{$prefix}";
}
return "FR{$prefix}{$siren}";
}
@decentraliser
decentraliser / ubuntu-ssh-setup.sh
Last active August 12, 2021 23:04
One-time setup for git SSH credentials
# Start ssh-agent at each session if necessary
# Source: https://askubuntu.com/questions/878944/cant-store-passphrase-in-same-session-with-eval-ssh-agent-ssh-add
sudo vim ~/.bashrc
#
# setup ssh-agent
#
#start running ssh-agent if it is not already.
if [ ! 'root' = "${USER}" ]; then
@decentraliser
decentraliser / rebase-branch
Last active April 18, 2021 16:54
Git: rebasing a (broken) branch
/**
* Rebase, having non-committed changes
*/
git remote update origin
git stash
git checkout master
git pull
git checkout MY_BRANCH
git rebase master
git stash pop
@decentraliser
decentraliser / array-some.js
Last active August 11, 2020 08:07
Test for arrays intersections with array.some
// array some helps keeping code succinct when looking for occurences in arrays
const firstArray = ['shark', 'fish', 'dinosaur']
const secondArray = ['whale', 'shark', 'bird']
const thirdArray = ['raptor', 'tuna']
// determine wether 2 arrays have a similar entry
const bool1 = firstArray.some(animal => secondArray.some(otherAnimal => otherAnimal === animal))
console.log("bool1", bool1) // true, "shark" is in both arrays