Skip to content

Instantly share code, notes, and snippets.

View sylvainSUPINTERNET's full-sized avatar
🗑️
:(){ :|: & };:

sylvainSUPINTERNET

🗑️
:(){ :|: & };:
View GitHub Profile
@sylvainSUPINTERNET
sylvainSUPINTERNET / recursive.php
Last active July 10, 2018 14:43
Basic recursive usage
<?php
function recursiveCount()
{
//static to avoid reset of variable for each itterations
static $countMax = 5;
//On affiche
echo $countMax;
//On décrémente
@sylvainSUPINTERNET
sylvainSUPINTERNET / recursive.js
Created July 10, 2018 15:16
Basic recursive script for JS
'use strict';
function recursive(x){
console.log(x);
if(x === 0){ //end condition
//end
return 1;
} else {
//reset process until 0
'use strict';
function recursive(x){
console.log(x);
if(Math.sign(x) === 1){
//positiv given
if(x === 0){
//end
return 1;
@sylvainSUPINTERNET
sylvainSUPINTERNET / make_uuid.js
Created November 7, 2018 15:07
Generate uuid with Node.js with only crypto
'use strict';
const crypto = require("crypto");
module.exports = {
generateUuid: function(){
let randomVal1 = crypto.randomBytes(16).toString('hex');
let randomVal2 = crypto.randomBytes(16).toString('hex');
let currentDate = new Date().getTime();
@sylvainSUPINTERNET
sylvainSUPINTERNET / decompose-string.js
Created December 19, 2018 13:39
JS decompose string
'use strict';
let str = "salut";
for(let x=0; x < [...str].length; x++){
console.log([...str][x]);
}
@sylvainSUPINTERNET
sylvainSUPINTERNET / gist:364a2e2659f5d0f3ff94be380a586cd1
Created January 3, 2019 12:51
composer "Allowed memory size of XXX bytes exhausted"
$ php -d memory_limit=-1 /usr/local/bin/composer require your-package-name
@sylvainSUPINTERNET
sylvainSUPINTERNET / test_async.js
Created January 9, 2019 10:19
async exemple with loader + timer
'use strict';
async function print(value) {
return new Promise((resolve, reject) => {
if(typeof value === 'string'){
setTimeout(() => resolve(value), 1000)
} else {
setTimeout(() => reject("string value param only."), 500)
}
@sylvainSUPINTERNET
sylvainSUPINTERNET / db_import.sh
Created March 19, 2019 10:44
Import database from mongoDB dump
#!/bin/sh
path=/Users/christopher/Development/backups/dumps/[Dump_folder]/[Dump_folder/db_name]
for i in $(ls $path/*.bson)
do
echo mongorestore --drop $i --db mpec
mongorestore --drop $i --db mpec
done
@sylvainSUPINTERNET
sylvainSUPINTERNET / main.js
Created April 9, 2019 07:55
Async / await example
function display(){
console.log("display called ...")
return new Promise( (resolve, reject) => {
setTimeout(function(){
console.log("display resolved !");
resolve("aurevoir");
}, 2000)
})
@sylvainSUPINTERNET
sylvainSUPINTERNET / promises_ex.js
Created May 16, 2019 09:57
Promises e.g with async await + Promise.all
async run (modelsToSync){
console.log(";;;;;;;;; RUN STARTED ;;;;;;;;; ");
console.log(` > ${modelsToSync}`);
let dataToSync = [];
for (let model in modelsToSync){
let promise = this.sync(model);
dataToSync.push(promise);
}
try {