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 / anidated.promises.dont.bubble.up.errors.js
Last active December 2, 2016 20:02
Little snippet to show that you must catch anidated promises or return them to be catched by outer `catch()`
'use strict';
const willResolve = (value = true) => Promise.resolve(value);
const willReject = (msg = 'This is fucked up!') => Promise.reject(new Error(msg));
const toBeOrNotToBe = (value = true, msg = 'This may resolve... Or not') => {
(Math.random() > 0.5) ? Promise.resolve(value) : Promise.reject(msg);
};
@fernandocanizo
fernandocanizo / destructuring.js
Created September 9, 2016 12:17 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
@fernandocanizo
fernandocanizo / xyz_vs_tms.md
Created August 26, 2016 20:05 — forked from tmcw/xyz_vs_tms.md
The difference between XYZ and TMS tiles and how to convert between them

The difference between XYZ and TMS tiles and how to convert between them

Lots of tile-based maps use either the XYZ or TMS scheme. These are the maps that have tiles ending in /0/0/0.png or something. Sometimes if it's a script, it'll look like &z=0&y=0&x=0 instead. Anyway, these are usually maps in Spherical Mercator.

Good examples are OpenStreetMap, Google Maps, MapBox, MapQuest, etc. Lots of maps.

Most of those are in XYZ. The best documentation for that is slippy map tilenames on the OSM Wiki, and Klokan's Tiles a la Google.

@fernandocanizo
fernandocanizo / json_postgres.js
Created July 28, 2016 16:14 — forked from gerzhan/json_postgres.js
Example of json document storage in postgresql and querying (with knex.js)
var connectionString = 'postgres://localhost:5432/postgres';
var Promise=require('bluebird');
var knex = require('knex')({
client: 'pg',
connection: {
user: 'postgres',
database: 'postgres',
port: 5432,
@fernandocanizo
fernandocanizo / sleep.js
Last active June 15, 2016 12:16
sleep function for JS
"use strict";
function sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
sleep(1).then(() => console.log('finished'));
@fernandocanizo
fernandocanizo / gist:399f62aa0684ee59c45e89fa532a26ab
Created June 15, 2016 01:30
Using reduce to apply a pipeline of functions
"use strict";
const pipe = functions => data => {
return functions.reduce((value, func) => func(value), data);
};
const pipeline = pipe([
n => n + 1,
n => n * 2,
n => n * n,
@fernandocanizo
fernandocanizo / ways.to.check.properties.on.objects.js
Created June 14, 2016 23:52
Ways to check for an object property
"use strict";
// There are three ways to check if an object has a property:
const obj = {
one: 1
};
const otherObj = Object.create(obj);
@fernandocanizo
fernandocanizo / A bunch of funky CSS3 Toggle Buttons.markdown
Last active March 11, 2016 21:18
A bunch of funky CSS3 Toggle Buttons

A bunch of funky CSS3 Toggle Buttons

A collection of toggle buttons that use CSS3 transitions to animate their state when interacted with. Created using HTML and CSS (no JS). By Ashley Nolan.

Uses the checkbox :checked state to differentiate between state, and therefore is still semantic and accessible.


Twitter: https://twitter.com/AshNolan_

@fernandocanizo
fernandocanizo / gist:86d2430ae9b8d416ab19
Created December 21, 2015 02:29 — forked from mapio/gist:1050635
A test comparing defaultdict and groupby for grouping
from timeit import Timer
from operator import attrgetter
from random import randint
def timeit( stmt, setup ):
t = Timer(stmt=stmt, setup=setup)
print "%.2f usec/pass" % (100000 * t.timeit(number=10000)/10000)
class Person(object):
def __init__(self, age):
@fernandocanizo
fernandocanizo / logger.js
Created October 7, 2015 13:28 — forked from CootCraig/logger.js
PhantomJs logger, logs to file and console.
// logger = require('logger');
// logger.log_to_console(true);
// logger.log_to_folder('log','_app.log');
// logger.set_log_level('DEBUG');
// logger.info('Happy to be here.');
exports.logger = (function() {
var that = {};
that.levels = {
"TRACE": 0,
"DEBUG": 1,