Skip to content

Instantly share code, notes, and snippets.

View xarg's full-sized avatar

Alex Plugaru xarg

View GitHub Profile
@xarg
xarg / dp.py
Created June 28, 2011 14:31
Douglas-Peucker
# pure-Python Douglas-Peucker line simplification/generalization
#
# this code was written by Schuyler Erle <schuyler@nocat.net> and is
# made available in the public domain.
#
# the code was ported from a freely-licensed example at
# http://www.3dsoftware.com/Cartography/Programming/PolyLineReduction/
#
# the original page is no longer available, but is mirrored at
# http://www.mappinghacks.com/code/PolyLineReduction/
@xarg
xarg / count_words.go
Created June 28, 2011 07:01
Boyer-Moore-Horspool (Go)
package main
import (
"fmt"
)
func count_words(word, text string) int {
var skip [255]int
m := len(word)
#!/usr/bin/python
#
# Original version by Rory McCann (http://blog.technomancy.org/)
# Modifications by Christoph Lupprich (http://www.stopbeingcarbon.com)
#
import xml.sax
import logging
from xml.sax.saxutils import XMLGenerator
log = logging.getLogger("pyosm")
#!/usr/bin/env python
from imposm.parser import OSMParser
from pyosm import OSMXMLFile, Node, Way
border_ways = {}
border_nodes = {}
node_ids = set()
got_nodes = 0
@xarg
xarg / Linkigy
Created September 15, 2010 09:45
function Linkify(inputText) {
//URLs starting with http://, https://, or ftp://
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
var replacedText = inputText.replace(replacePattern1, '<a href="$1">$1</a>');
//URLs starting with www. (without // before it, or it'd re-link the ones done above)
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
var replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2">$2</a>');
//Change email addresses to mailto:: links
/**
* This is an example to create persistent forms using
* HTML5 localStorage + jQuery serialization and
* url.decode from http://www.webtoolkit.info/
*
*
* The example bellow is seriously unoptimized.
* It listens to changing events in the form and
* serializes the data of the form in localStorage
*/
find . -name "*.pattern" -exec bash -c "mv \"\$1\" \"\`echo \$1 | sed s/.pattern//\`\"" -- {} \;
#!/usr/bin/env python
""" Make a Git checkout from an SVN repository """
import os
from optparse import OptionParser
from subprocess import Popen, PIPE
def run(cmd):
return Popen(cmd, stdout=PIPE).communicate()[0]