Skip to content

Instantly share code, notes, and snippets.

View maumchaves's full-sized avatar

Mau Muñoz maumchaves

  • Vienna
View GitHub Profile
@maumchaves
maumchaves / README.md
Created March 28, 2020 16:52 — forked from rochoa/README.md
CARTO Node.js code test

CARTO Node.js code test

Introduction

At CARTO, among other things, we render maps, just check this example of Map with countries and USA states.

In order to limit the scope of the challenge, we are gonna use Mapnik and Node.js. Within this repository, we are providing all the pieces you need to reproduce that map. Well, all pieces except the map tile server.

An example of how to create an image with Mapnik:

@maumchaves
maumchaves / custom-implementation-array-push.js
Last active March 24, 2019 17:43
Custom implementation of Array.push() as described by Douglas Crockford in his book "JavaScript: The Good Parts". The breakdown / analysis is my own.
/* TL;DR:
* The method replicates the functionality of Array.push
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
* Array.method("myFunction", function() {}) is just an imaginary pre-implemented function that
* is equivalent to Array.prototype.myFunction = function() {}
*/
Array.method('push', function() {
// array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
/*
* By Dan Abramov, @dan_abramov
* https://mobile.twitter.com/dan_abramov/status/1018945865745084416
*/
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
@maumchaves
maumchaves / settings.json
Created October 6, 2018 13:33
LumProtest VS Code Settings
{
"prettier.bracketSpacing": true,
"prettier.singleQuote": true,
}
@maumchaves
maumchaves / functional-constructor-pattern.js
Last active April 19, 2018 04:54
Functional Constructor Pattern: an inheritance pattern described by Douglas Crockford in his book "JavaScript: The Good Parts" (Ch.5).
"use strict";
/**
* var myConstructor = function(spec, shared) { ... };
*
* ~ The 'spec' object contains all of the information that the constructor
* needs to make an instance (it can also be a single value). Destructuring
* assignment can be used for more clarity about the excpected values.
*
* ~ The 'shared' object is a container of secrets that are shared by the
@maumchaves
maumchaves / move-fixed-content-with-toast.ts
Last active April 9, 2018 17:55
Angular / Ionic 3 directive to allow Ionic toasts to animate the fab buttons and other elements in the fixed-content div of a page accordingly.
/*
* USAGE
*
* Add the following element in your app component template:
*
* <ng-container move-fixed-content-with-toast></ng-container>
*
* IMPLEMENTATION NOTES
*
* - It works with only one toast at the time.
@maumchaves
maumchaves / javascript-anomalies.js
Last active November 6, 2017 03:20
JavaScript Anomalies.
// #1 - Context. The `this` variable case:
var Person = function(firstname) {
this.firstname = firstname;
this.print = function() {
setTimeout(function () {
console.log("My name is " + this.firstname);
});
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My App</title>
<!-- Uncomment if Angular -->
<!-- <base href="/"> -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
@maumchaves
maumchaves / read-overwrite-json.js
Created October 13, 2017 02:22
Read and overwrite a json file in node.js.
const fs = require('fs');
const filePath = 'file/path.json';
const fileObject = JSON.parse(fs.readFileSync(filePath, 'utf8'));
// Do something with file
try {
fs.writeFileSync(filePath, JSON.stringify(fileObject, null, 2), 'utf8');
console.log("The file was saved!");