Skip to content

Instantly share code, notes, and snippets.

View fernandocanizo's full-sized avatar
🎃
Working from home

Fernando Lucio Canizo fernandocanizo

🎃
Working from home
View GitHub Profile
@fernandocanizo
fernandocanizo / test2.geojson
Last active September 28, 2017 15:43
Testing geojson gist 2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fernandocanizo
fernandocanizo / test.geojson
Created September 28, 2017 15:30
Testing geojson gists
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
'use strict';
// Comment `process` usage to see the cryptic message
const process = require('process');
process.on('unhandledRejection', reason => console.error(reason));
const foo = () => {
return new Promise((undefined, reject) => {
reject(new Error('RECHAZÁU!'));
});
@fernandocanizo
fernandocanizo / gist:732523e50d819559365dffe686dec881
Created July 21, 2017 15:44
A proper sleep function for Javascript ES2017
// Taken from
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep/39914235#39914235
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
console.log('Taking a break...');
await sleep(2000);
@fernandocanizo
fernandocanizo / gist:045ddc31a03fd80947287f178742c798
Created June 22, 2017 22:39
Console logging with style (browser only)
const success = [
'background: green',
'color: white',
'display: block',
'text-align: center'
].join(';');
const failure = [
'background: red',
'color: white',
'display: block',
const mandatoryParameter = (parameterName) => {
throw Error(`Parameter '${parameterName}' is mandatory`);
};
const foo = (fluffyDragon = mandatoryParameter('fluffyDragon')) => console.log(fluffyDragon);
foo('Spooky');
foo();
@fernandocanizo
fernandocanizo / index.js
Created March 7, 2017 13:34 — forked from mpmckenna8/index.js
Super simple webpage with budo
// try to do some stuff here
var d3 = require('d3');
d3.select('body').append('text')
.text('hey now thats somethin a webpage without any writing any htmml')
console.log('yoyo')
@fernandocanizo
fernandocanizo / adaptive.rounds.calculator.for.bcryptjs.js
Last active June 27, 2018 21:07
Calculate proper number of required rounds for bcryptjs hashing on current hardware
'use strict';
const bcrypt = require('bcryptjs');
const getCost = async () => {
// This code will benchmark your server to determine how high of a cost
// you can afford. You want to set the highest cost that you can
// without slowing down you server too much. 8-10 is a good baseline,
// and more is good if your servers are fast enough. The code below
// aims for ≤ 50 milliseconds stretching time, which is a good baseline
@fernandocanizo
fernandocanizo / Password.php
Created February 17, 2017 11:50
Façade class to handle password hashing on different versions of PHP
<?php
// Creation Date: 2015.03.14
// Author: Fernando L. Canizo - http://flc.muriandre.com/
abstract class Password {
// Façade class to handle password hashing on different versions of PHP
// Uses password_hash() on PHP >= 5.5.0
// Uses crypt() on PHP < 5.5.0 and >= 5.0.0
@fernandocanizo
fernandocanizo / Not so cool refactor attempt (functional programming)
Last active February 15, 2017 15:29
Attempt at refactoring a procedural code into a more functional form. Resulting code looks more bloated than procedural version.
// Possible result as it comes from DB
let dbResults = [
{ username: 'crmeco', status: 'synchronized', count: '19' },
{ username: 'pamela', status: 'synchronized', count: '16' },
{ username: 'pamela', status: 'todo', count: '26' }
];
// Expected result:
// [
// { username: 'crmeco',