Skip to content

Instantly share code, notes, and snippets.

@dvj
dvj / simplify.py
Created September 11, 2015 04:05
simplify points in geojson file using opencv implementation of Douglas–Peucker : https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
import cv2, numpy as np, json, sys
def simplify(data):
d = np.array(data).astype(np.float32)
if d.size > 3:
simple = cv2.approxPolyDP(d, thresh, False).tolist()
data = [[round(n, 6), round(p, 6)] for n,p in np.reshape(simple, [-1, 2]).tolist()]
else:
print "not reducing {}".format(d)
@dvj
dvj / cfg_parse.sh
Created July 29, 2014 18:37
Simple config parser
cfg_parser ()
{
ini="$(<$1)" # read the file
ini="${ini//[/\[}" # escape [
ini="${ini//]/\]}" # escape ]
IFS=$'\n' && ini=( ${ini} ) # convert to line-array
ini=( ${ini[*]//;*/} ) # remove comments with ;
ini=( ${ini[*]/\ =/=} ) # remove tabs before =
ini=( ${ini[*]/=\ /=} ) # remove tabs be =
ini=( ${ini[*]/\ =\ /=} ) # remove anything with a space around =
@dvj
dvj / html2text.py
Created January 28, 2011 04:37
Aaron Swartz's HTML->Markdown parser (http://www.aaronsw.com/2002/html2text/) updated from sgmllib to HTMLParser so that valid XHTML doesn't fail
#!/usr/bin/env python
"""html2text: Turn HTML into equivalent Markdown-structured text."""
__version__ = "2.40"
__author__ = "Aaron Swartz ([email protected])"
__copyright__ = "(C) 2004-2008 Aaron Swartz. GNU GPL 3."
__contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"]
# TODO:
# Support decoded entities with unifiable.
#!/usr/bin/python
# Downloads Google Web History
import sys, optparse, datetime, tempfile, os, string, urllib
import getpass, uu
import httplib2,re
import time
from Cookie import SimpleCookie
import atom
#import gdata.service