Skip to content

Instantly share code, notes, and snippets.

View Ugarz's full-sized avatar

Nimbly Ugarz

  • Toulouse
View GitHub Profile
@Ugarz
Ugarz / dev-setup-wsl.md
Last active March 22, 2023 22:20
Scripts to run wsl

Setup development environment with WSL (Windows Subsystem Linux)

I always used a unix environment to work and like it. I'm also a creative guy, sometimes I do graphism, design and don't like to switch OS to enjoy doing both. I heard of WSL and saw this as the forgotten messiah, so here a guide to install everything you will have to set up to enjoy both like me.

Process

Powershell

First we will need to activate the Windows Subsystem Linux (WSL).

  1. Run powershell as admin type in terminal
@Ugarz
Ugarz / privacy.md
Last active October 25, 2018 08:54
Javscript Functions and privacy

Javascript Functions and privacy

Using Closures

Douglas Crockford’s code conventions for JavaScript recommend this pattern when privacy is important discouraging naming properties with the underscore prefix to indicate privacy.

var Person = (function() {
    function Person(name) {
        this.getName = function() {
            return name;
@Ugarz
Ugarz / index.md
Created October 22, 2018 14:56
Set data in key of value in object with javascript

Set data in key of value in object with javascript

Consider an simple object like so

// Build object
const obj = {}
// Add data to it
obj.data = { $: { 'myAwesomeKey': 'toto' }, _: 'myAwesomeValue' }

// Convert it to xml
const xml = xml2js(objet)
@Ugarz
Ugarz / pipe.md
Created September 10, 2018 14:09
Piping functions in javacript

How to pipe functions in Javacript

const add = (a, b) => a + b
const dbl = (num) => num * 2
const pipe = (f, g) => (...args) => g(f(...args))
const sumThenDbl = pipe(add, dbl)
const result = sumThenDbl(2, 1) // 6
@Ugarz
Ugarz / process_users.md
Created May 29, 2018 11:23
Workflow to process a bunch of users

Workflow to process a bunch of users

How to process users recovered from a database going down the array of users until there is no more of them.

// Act like it is a database
const users = [
    { name: "ugo", age: 28 },
    { name: "camille", age: 25 }
]
@Ugarz
Ugarz / index.md
Last active October 9, 2019 10:10
Playing with Reduce

Reduce Practicing

const basket = [
  { "chanvre" : { "price": 23.39, "nb": 1 }},
  { "flapjack": { "price": 19.99, "nb": 2 }},
  { "farine"  : { "price": 19.99, "nb": 3 }}
];

const basket2 = [{
@Ugarz
Ugarz / index.md
Last active October 9, 2019 10:07
Manage folder and file rights

Manage folder and file rights with Node.js

var fs = require('fs'),
    path = require('path'),
    assert = require('assert'),
    dir = 'tmp_'+Date.now(),
    file = dir+'/file.txt';

var existsSync = fs.existsSync || path.existsSync;
@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 / 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 / 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){