Skip to content

Instantly share code, notes, and snippets.

View Ugarz's full-sized avatar

Ugo Ugarz

View GitHub Profile
@Ugarz
Ugarz / index.md
Last active July 6, 2017 13:12
Async / Await

Thoughts on javascript Async / Await

Some thoughts and playing around Async / Await with Javascript.

// Basic function setting name to this object
function _setName(name){
    this.name = name
}
@Ugarz
Ugarz / index.md
Last active July 24, 2017 14:34
Templating a file with Lodash

Discover the advanced templating function with lodash

Moar informations here at the Lodash documentation

Create a file index.js and copy paste it. Do not forget to

npm init -y &&
npm i lodash fs nodemon -D

Paste this into the index.js

@Ugarz
Ugarz / resizr.md
Last active July 31, 2017 10:46
Resize an image with the gm library, quick'n'easy

Simple image resizer with node

For more api, see here

const fs = require('fs');
const gm = require('gm');

gm('id.jpg')
.toBuffer('JPG', function (err, buffer) {
 if (err) return console.error(err);
@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 '';
@Ugarz
Ugarz / slugify.md
Last active August 2, 2017 09:31 — forked from mathewbyrne/slugify.js
Javascript Slugify

Simple Slugy for strings

function slugify(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
 .replace(/-+$/, ''); // Trim - from end of text
@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 / 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 / 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 / mobileAndTabletcheck.txt
Created December 10, 2015 13:06
Check if your device if mobile or tablet in Javascript
window.mobileAndTabletcheck = function() {
var check = false;
(function(a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) ||
if (window.mobileAndTabletcheck == true)
@Ugarz
Ugarz / prototypal_pattern.md
Last active February 6, 2018 13:00
Reflexion around Prototype pattern in Javascript

Prototypal pattern

Let's say I want a provider to request a file

// Create the Provider
const Provider = function(datas) {
    if(!datas || !datas.provider) console.warn('Nope, need a provider')
    const { provider } = datas;
    this.provider = provider;
}