View flatten.js
/**
* Returns a new array that is a one-dimensional flattening of this array (recursively).
*
* @param {array} arr
*/
function flatten (arr = []) {
return arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
}
View asyncawait_calculator.js
/**
* Async/Await Calculator example
*
* Tested on Node v6
*/
const _async = require('asyncawait/async')
const _await = require('asyncawait/await')
const DELAY = 1000
View random.md

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

View Debugging.md

NodeJS debugging in VS Code with Nodemon

A simple NodeJS App debugging example in VS Code using Nodemon.

Note: Feel free to customize .vscode/launch.json and ./nodemon.json files.

Install

yarn add nodemon --dev
View README.md

Papirus-Dark with Arch Linux Icon

How to change Gnome 3+ application grid icon with a custom Arch Linux icon

Before:

Papirus-Dark

After:

View README.md

Install PHP 7 Xdebug in Arch Linux

"Normally", these instructions should be also valid (in similar way) for other Linux distros.

1.- Install Xdebug using pacman:

sudo pacman -Sy xdebug
View date_helper.js
const time = require('time')(Date)
const dateFormat = require('dateformat')
/**
* Date utility functions
*
* @returns {object}
*/
function dateHelper (defaultTimezone = 'UTC') {
return {
View db.sh
# MySQL query execution using Bash
# Include this file in your bash scripts. Check out 'usage.sh' file example
# Note: Only used for 'development' process
# Settings
HOST='localhost'
USER='usr'
PASSWD='pwd'
DB_NAME='mydb'
View helpers.js
const isEmpty = require('lodash.isempty')
const isObject = require('lodash.isobject')
/**
* Prevent empty object value
*
* @param {object} value
* @returns {object|null}
*/
function notEmpty (value) {
View request.service.ts
import { Injectable } from '@angular/core'
import { Http, Headers, RequestOptions, Response } from '@angular/http'
import { Observable } from 'rxjs'
import 'rxjs/add/operator/map'
/**
* Usage:
*
* export class MyAuthService {
* constructor (private request: RequestService) {