Skip to content

Instantly share code, notes, and snippets.

View Ugarz's full-sized avatar

Ugo Ugarz

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 / index.md
Last active June 1, 2020 23:53
Encoding and Decoding images in base64 with Nodejs

Encoding and Decoding images in base64 with Node

Take a trump.jpg and launch this gist.

trump.jpg

var fs = require('fs');

function base64_encode(file) {
@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 / 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 / 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: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;

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 / remove_node_modules.md
Last active November 19, 2018 09:56 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo

Add 'node_modules' to .gitignore file and remove versionned ones

git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@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)