Skip to content

Instantly share code, notes, and snippets.

View Ugarz's full-sized avatar

Ugo Ugarz

View GitHub Profile
@Ugarz
Ugarz / recursion.md
Last active March 20, 2018 13:15
Recursion with node to process on each item from an array

Recursion on array with Promises

Sometime you just want to do operations on a bunch of datas. Oh wait, there is Promises to resolve before.. Here is a simple proposal to solve it.

// Act like it is a database
const users = [
    { name: "ugo", age: 28 },
    { name: "camille", age: 25 }
]
@Ugarz
Ugarz / set.md
Created March 13, 2018 14:28
Use Sets in Javascript

Sets in Javascript

const storePersons = new Set();

const personn1 = {
    "user": 4321,
    "type": "female"
}
const personn2 = {
@Ugarz
Ugarz / index.md
Last active September 7, 2018 13:10
Simple observable on html ready

Use Observable in html

A simple attempt to use Observable in html.

Instructions

  • Download this html
  • Launch it in your browser
  • Type anything on this page
  • Hit Enter to see what you typed
@Ugarz
Ugarz / index.md
Created February 6, 2018 13:27
Class Pattern

Simple reminder class with Javascript

Have fun with Class

// Mother Class
class Provider {
    constructor(data) {
        this.provider = data.provider;
        this.maxTry = data.maxTry || 3;
    }
@Ugarz
Ugarz / camelCase.md
Created January 24, 2018 14:17
Javascript tricks

Force an object to have camelCase keys

const camelCase = require('lodash/camelCase');

/**
 * Force object key to camelCase
 * @param  {object} obj
 * @return {object} newObj
 */
@Ugarz
Ugarz / cipher.md
Last active March 13, 2018 14:39
Using Crypto, the Node js module to encrypt passwords

How to use the Crypto module from Node js

This is a simple example, please consider using createHash instead for passwords in production

const crypto = require('crypto');
const passwordToEncrypt = "AP34IOUR+&"
const salt = "My Awesome Salt"

function encryptData(salt, passwordToEncrypt){
@Ugarz
Ugarz / index.md
Last active January 19, 2018 14:07
I'm fed up of all wordpress magic ! So let's list some Wordpress tips and tricks to level up ! C'mon !
@Ugarz
Ugarz / dockerpress.md
Last active October 9, 2019 10:13
Create a wordpress site with docker-compose

Create a wordpress site with docker-compose

#!/bin/bash

mkdir wordpress-site && cd wordpress-site

touch docker-compose.yml

cat > docker-compose.yml <<EOL
version: "2"
@Ugarz
Ugarz / removeTracked.md
Last active August 2, 2017 20:41 — forked from Zyber17/gist:8233445
Remove tracked node_modules

Remove tracked files in git

Works with any files / folder, it's delete in remote the target.

git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@Ugarz
Ugarz / getFileExtension.md
Last active August 2, 2017 09:30
Get a file extension with javascript (no regex)

Get a file extension simply, no regex

Full credits to this thread

const getFileExtension = (filename) => {
  const splitedName = filename.split('.');
  console.log(splitedName) // [ 'fileblabla', 'pdf' ]
  if (splitedName.length === 1 || (splitedName[0] === '' && splitedName.length === 2)) {
 return '';