Skip to content

Instantly share code, notes, and snippets.

@alexisljn
alexisljn / b64ToBlob.js
Created August 29, 2019 14:46
Convert base64 into blob
b64toBlob(b64Data, contentType, sliceSize = 512) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
let byteCharacters = atob(b64Data);
let byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
let slice = byteCharacters.slice(offset, offset + sliceSize);
@alexisljn
alexisljn / resolvingPromisesSequentially.js
Last active September 11, 2019 10:07
Resolving javascript's promises sequentially
// COMMENTAIRE TECHNIQUE
// Si on ne donne pas un Promise.resolve() en valeur initiale, le "accPromise.then()" ne peut
// pas fonctionner car then n'est pas une fonction sur le tableau sur lequel on applique reduce()
// Retourner buildPromise permet de lui faire prendre la place de AccPromise.
// Pour autant cette ligne execute aussi la promesse et c'est parce que AccPromise est
// devenu la promesse qu'on attends sa résolution pour rentrer dans le then.
buildPromise(data, tableAbbreviation)
@alexisljn
alexisljn / gitkeep-all-empty-folders
Created March 2, 2020 08:16
Create .gitkeep file in empty folders
find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \;
@alexisljn
alexisljn / timeleft.js
Last active March 27, 2021 14:21
timeleft from SetTimeout in NodeJS
const timeout = setTimeout(() => {
console.log("executé après 5 sec")
},5000)
setTimeout(() => {
console.log(Math.ceil((timeout._idleStart + timeout._idleTimeout)/1000 - process.uptime()));
}, 3000)
package {
'apache2':
ensure => present,
#name => 'apache2',
#provider => apt
}
package {
'php7.3':
ensure => present
@alexisljn
alexisljn / binary-mask.php
Last active December 21, 2022 08:28
Use of binary mask to create basis of a permissions system
<?php
$permA = 1;
$permB = 2;
$permC = 4;
$permD = 8;
$permE = 16;
$permF = 32;
// Malgré le '|' c'est un set de permissions
@alexisljn
alexisljn / ebauche-permission.php
Created August 30, 2021 12:46
Ebauche permissions
<?php
// Il faut ET la permission 1 (OU la permission 2 ET la permission 4)
// ET la permission 3
$permissions = [
'and' => [
'permission' => [
'name' => $permission1,
'or' => [
- PHP
- Symfony var-dumper : le var-dumper de Symfony, utile pour debug
- https://github.com/symfony/var-dumper
- https://packagist.org/packages/symfony/var-dumper
- Javascript
- Turbolinks : Accélère le chargement des pages en chargeant les pages en ajax
- https://github.com/turbolinks/turbolinks
- Vidéo Grafikart : https://www.youtube.com/watch?v=CjZnG_X85ww
- Tui Editor : Editeur WYSIWYG Markdown
@alexisljn
alexisljn / d-app-docker-compose.yml
Created June 13, 2022 14:04
Starter docker compose for Ethereum Dapp
version: "3.8"
services:
hardhat:
image: node:16
container_name: hardhat
working_dir: /home/node/app
volumes:
- ./:/home/node/app
ports:
@alexisljn
alexisljn / hex-to-uint-uint-to-hex-string.sol
Created June 22, 2022 08:54
This gist shows how to convert bytes input into an uint output. Then we can retrieve the bytes input by converting the uint value into an hexadecimal string
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
import "@openzeppelin/contracts/utils/Strings.sol";
contract Test {
uint256 public value;