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 / promises-iterations.js
Last active June 7, 2023 05:39
Promises iteration with for of
const promise = (number) => new Promise(resolve => {
setTimeout(() => resolve(number), Math.random() * Math.floor(1000))
})
const sequentialIteration = async () => {
for (const number of Array(10).keys()) console.log(await promise(number))
}
sequentialIteration()
@decentraliser
decentraliser / git-aliases
Last active December 1, 2023 01:54
Git aliases
[alias]
b = branch -vv
bb = branch
ba = branch -a -vv
cb = checkout -b
cm = checkout master
cma = checkout main
cnv = commit -m --no-verify
co = checkout
d = branch -D
@decentraliser
decentraliser / enum-extraction.ts
Last active March 11, 2020 10:07
Extract strings and numbers from enums
// A simple way to extract strings and numbers from an enum
enum actions {
Link = 1,
Unlink = 0
}
const strings = Object.keys(actions)
.filter((key) => Number.isNaN(parseFloat(key)))
@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
@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 / 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 / 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 / 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/

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 / 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