Skip to content

Instantly share code, notes, and snippets.

View defvol's full-sized avatar

Rodolfo Wilhelmy defvol

View GitHub Profile
@defvol
defvol / image_server.js
Created April 10, 2012 22:16
A simple asynchronous image server
// A simple image server
// To run:
// $ node image_server.js
var fs = require('fs')
, http = require('http')
, anImage = '';
// Read an image on disk
try {
@defvol
defvol / covid19mx-to-jsonseries.js
Last active April 3, 2020 04:01
Script que agrupa en una serie de tiempo, los reportes diarios del gobierno sobre COVID-19. De paso deja los estados en formato compatible con el Marco Geoestadístico de INEGI (i.e. listo para mapas). Referencia coronavirus.gob.mx via https://github.com/guzmart/covid19_mex/issues/2.
(async () => {
const assert = require('assert')
const path = require('path')
const aliases = {
'ciudad de mexico': 'ciudad de méxico',
'coahuila': 'coahuila de zaragoza',
'michoacan': 'michoacán de ocampo',
'michoacán': 'michoacán de ocampo',
'queretaro': 'querétaro',
@defvol
defvol / random-wallpaper.py
Last active May 3, 2019 22:15
A cron-ready script for choosing a random wallpaper on a GNOME desktop. Some ideas borrowed from https://github.com/thedevsaddam/ubuntu-live-wallpaper and crontab.guru.
#!/usr/bin/python
# usage: random-wallpaper.py <directory>
from os import environ, listdir, system
from os.path import isfile, join
import random
import sys
environ['GIO_EXTRA_MODULES'] = '/usr/lib/x86_64-linux-gnu/gio/modules/'
@defvol
defvol / csv-to-json.py
Created August 21, 2018 20:38
Simple python script to transform CSV to JSON
# usage: python csv-to-json.py the.csv
# based on https://stackoverflow.com/questions/3428532/how-to-import-a-csv-file-using-python-with-headers-intact-where-first-column-is#3428562
import csv
import json
import sys
csvfile = open(sys.argv[1], 'r')
reader = csv.DictReader(csvfile)
out = json.dumps( [ row for row in reader ] )
sys.stdout.write(out)
@defvol
defvol / commands.sh
Last active January 23, 2018 19:24
List of useful commands
# handy linux commands
# get video card specs
lshw -C video
lspci | grep -i vga
# distro specs
uname -m && cat /etc/*release
# distro name
@defvol
defvol / datos-abiertos-por-bittorrent.md
Last active July 11, 2017 05:36
Distribuye datos abiertos por BitTorrent

Distribuye datos abiertos por BitTorrent

TL;DR para asegurar disponibilidad de los datos abiertos, necesitamos descentralizar su distribución.

¿qué es BitTorrent?

En lugar de que miles de personas intenten bajar grandes conjuntos de datos de un servidor malconfigurado de gobierno, con BitTorrent los datos pueden ser distribuidos y compartidos en pequeños fragmentos y entre diferentes consumidores (y los mismos servidores originales).

La alta disponibilidad se asegura porque los datos tienen múltiples réplicas y la carga de la red se distribuye entre múltiples usuarios.

@defvol
defvol / safeparse.js
Created January 27, 2017 18:07
Wrapper to handle accessing undefined properties on a nested object (catches TypeErrors)
/**
* Add a standard error handling routing when accessing nested keys
* On TypeError (accessing undefined property) it will return empty array
* Will also take care of wrapping single elements in an array
* usage: safeparse(() => parsedXml.status.events.event)
* @param {Function} accessor just returns a nested key
* @returns {Array}
*/
function safeparse (accessor) {
try {
@defvol
defvol / toTable.js
Created January 26, 2017 22:31
Traverse object's properties to build an HTML table
function toTable (obj) {
var td = function (s) { return '<td>' + s + '</td> ' };
var tr = function (s) { return '<tr>' + s + '</tr> ' };
var table = ''
for (var k in obj) table += tr(td(k) + td(obj[k]));
return '<table>' + table + '</table>';
}

Map QA Issues Specs v2.0 [DRAFT]

JSON schema to represent data quality issues on a map. A QA project is a collection of data quality issues generated from a source or queried live from OSM.

Project Metadata

A JSON-compliant schema to describe a project

{
	"project": {
		"uid": "1001",
@defvol
defvol / profeco.js
Last active July 21, 2016 02:52
Builds GeoJSON Feature objects from the profeco.precios dataset: http://datos.gob.mx/busca/dataset/quien-es-quien-en-los-precios
var es = require('event-stream')
var fs = require('fs')
var JSONStream = require('JSONStream')
var request = require('request')
function toGeoJSON(obj) {
var lon = parseFloat(obj.longitud);
var lat = parseFloat(obj.latitud);
if (!lon || !lat) return null;