Skip to content

Instantly share code, notes, and snippets.

@neilvallon
neilvallon / rdp.go
Last active August 27, 2020 15:15
In-place Ramer–Douglas–Peucker for Go & TypeScript
package rdp
import "math"
type point [2]float64 // [x, y]
// RDPSimplify is an in-place implementation of Ramer–Douglas–Peucker.
func RDPSimplify(points []point, epsilon float64) []point {
return points[:rdpCompress(points, epsilon)]
}
@neilvallon
neilvallon / staticserve.go
Last active August 29, 2015 14:16
dead simple file server that will host the current dir on port 8000
package main
import (
"net/http"
"github.com/zenazn/goji"
)
func init() {
goji.Get("/*", http.FileServer(http.Dir("./")))
@neilvallon
neilvallon / stream.php
Created February 18, 2015 23:03
PHP Streams
<?php
// Now I remember why I don't use PHP anymore.
function repeat($n) {
return function() use ($n) {
return [$n, repeat($n)];
};
}
function countFrom($n) {
@neilvallon
neilvallon / codelog.rb
Created July 27, 2014 07:45
Count total line changes in a git repository.
#!/usr/bin/env ruby
log = `git log --oneline --shortstat`
puts log
i = 0
d = 0
log.each_line { |l|
ii = /([0-9]+) insertion/.match(l)
@neilvallon
neilvallon / piglatin.scpt
Created May 13, 2014 19:44
Applescript mail action to translate texts to piglatin and send them back - Jul 24 2009
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
repeat with theMessage in theMessages
set theText to content of theMessage
set theSender to sender of theMessage
set TempTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set theText to text items of theText
@neilvallon
neilvallon / randHex.php
Last active August 29, 2015 14:01
ranHexColor - May 15 2009
<?php
function ranHex(){
$i = rand(0, 15);
switch ($i) {
case 0: $a = "0"; break;
case 1: $a = "1"; break;
case 2: $a = "2"; break;
case 3: $a = "3"; break;