Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Working

Ugo Ugarz

💻
Working
View GitHub Profile
View bluebird.md

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 Nov 13, 2018
Scripts to run wsl
View dev-setup-wsl.md

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 Oct 25, 2018
Javscript Functions and privacy
View privacy.md

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 Oct 22, 2018
Set data in key of value in object with javascript
View index.md

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 Sep 10, 2018
Piping functions in javacript
View pipe.md

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 Jun 14, 2018
WP tricks database migration
View index.md

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
Workflow to process a bunch of users
View process_users.md

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 Oct 9, 2019
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)
View lesson-01.md

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 Oct 9, 2019
Playing with Reduce
View index.md

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 Oct 9, 2019
Manage folder and file rights
View index.md

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;