Skip to content

Instantly share code, notes, and snippets.

View Ugarz's full-sized avatar

Ugo Ugarz

View GitHub Profile

Bluebird

Use bluebird with another library

You can override another Promise from a library like node-fetch with bluebird.

var fetch = require("node-fetch");
var Bluebird = require("bluebird");

fetch.Promise = Bluebird;
@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 / index.md
Last active June 14, 2018 08:26
WP tricks database migration

Move your wordpress to localhost

Move your website parameters to new url

UPDATE wp_options
SET option_value = replace(option_value, 'http://mywebsite.fr', 'http://localhost/mywebsite')
WHERE option_name = 'home'
@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 / lesson-01.md
Last active October 9, 2019 10:09
Safer Javascript, create a validation parameters for your Javascript functions with Maybe | Just | Nothing (cf: https://egghead.io/lessons/javascript-unwrap-values-from-a-maybe)

Egghead - Validation algorythm - Lesson 01

const { inc } = require('../utils')
const Maybe = require('crocks/Maybe')

// Maybe = Just x | Nothing

const safeNum = val =>
    typeof val === 'number' ? Maybe.Just(val) : Maybe.Nothing()
@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;