Skip to content

Instantly share code, notes, and snippets.

View defvol's full-sized avatar

Rodolfo Wilhelmy defvol

View GitHub Profile
@defvol
defvol / hcnl-iniciativas.js
Created February 1, 2013 22:15
Ejemplo de extracción de datos de las iniciativas del Congreso de Nuevo León.
// Probado con el web inspector de Google Chrome en:
// http://www.hcnl.gob.mx/trabajo_legislativo/iniciativas/pri.php
trs = $("#Tabla tr");
trs.map(function(i, tr) {
// Extrae primera columna
var exp = $(tr).find("td")[0];
if (exp != undefined) {
console.log($(exp).text());
}
@defvol
defvol / merit_setup_error
Created February 4, 2013 22:06
Setup error in 'merit' gem
$ rails g merit:install --trace
/Users/rod/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1153:in `async_exec': PG::Error: ERROR: relation "merit_actions" does not exist (ActiveRecord::StatementInvalid)
LINE 5: WHERE a.attrelid = '"merit_actions"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"merit_actions"'::regclass
@defvol
defvol / prime.c
Last active December 12, 2015 07:58
438 bytes to print the biggest prime number (a cleaner version)
// All credits go to Fabrice Bellard http://bellard.org/mersenne.html
#include <stdio.h>
int m=167772161,N=1,t[1<<25]={2},a,*p,i,e=34893349,s,c,U=1;
g(d,h) {
for(i=s;i<1<<24;i*=2)d=d*1LL*d%m;
for(p=t;p<t+N;p+=s)
for(i=s,c=1;i;i--)
@defvol
defvol / Rakefile
Created April 27, 2013 16:48 — forked from juanje/Rakefile
load 'rake/helper.rb'
desc "Set up the VM"
task :up do
vm = VM.new
vm.cli('up')
end
desc "Shutdown the VM"
task :graceful_down do
require 'nokogiri'
require 'open-uri'
require 'CSV'
doc = Nokogiri::HTML(open('http://www.weatherusa.net/tropical/storm.php?year=2013&basin=at&num=10'))
# Do funky things
CSV.open("ingrid.csv", "wb") do |csv|
doc.css('table tr').each do |tr|
# Bulk convert shapefiles to geojson using ogr2ogr
# For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/
# Note: Assumes you're in a folder with one or more shape files at most 2 levels deep the file structure
# and outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere)
# GeoJSON conversion
function shp2geojson() {
ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
}
@defvol
defvol / catalogo-de-datos-abiertos.json
Last active December 27, 2015 15:49
Plantilla de ejemplo para un catálogo de datos abiertos. Inspirado en http://project-open-data.github.io.
[
{
"identifier": "pef2013_1",
"title": "presupuestoDeEgresos2013",
"description": "Presupuesto de Egresos de la Federación para el 2013",
"keyword": [
"presupuesto",
"egreso"
],
"modified": "20130222T10:00:00Z",
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev lib64readline-gplv2-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@defvol
defvol / geopolitical-polygons.markdown
Last active August 29, 2015 13:57
A demo to retrieve geospatial and geopolitical info by drawing overlays on top of Google Maps (v3).

Geopolitical polygons

A demo to retrieve geospatial and geopolitical info by drawing overlays on top of Google Maps (v3).

screenshot

A Pen by Rod Wilhelmy on CodePen.

License.

@defvol
defvol / postgis_wizardry.md
Last active August 29, 2015 13:58
Brujería en PostGIS

¿Cuál es la distancia en KM entre el centroide de un municipio y otro?

Distancia entre los municipios 'Mexicali' y 'Ensenada':

SELECT ST_Distance(ST_Centroid(a.the_geom_webmercator), ST_Centroid(b.the_geom_webmercator)) / 1000
FROM los_municipios a, los_municipios b
WHERE a.nombre='Mexicali' AND b.nombre='Ensenada'