Skip to content

Instantly share code, notes, and snippets.

View timyates's full-sized avatar

Tim Yates timyates

  • Manchester, UK
View GitHub Profile
#!/usr/bin/env groovy
// Trying it in Groovy as a shell script (just for fun)
import java.util.regex.Pattern
// All folders on the path which have contents:
path = System.env[ 'PATH' ]
.tokenize( File.pathSeparator )
.collect( { new File( it ) } )
@timyates
timyates / Reshape.md
Last active December 17, 2015 16:59 — forked from anonymous/Reshape.md

From the simple R example of reshape here, given a List of Maps like this:

data = [ [ id: 1, time: 1, x1: 5, x2: 6 ],
         [ id: 1, time: 2, x1: 3, x2: 5 ],
         [ id: 2, time: 1, x1: 6, x2: 1 ],
         [ id: 2, time: 2, x1: 2, x2: 4 ] ]

And the methods melt:

//Project Euler # 10
//http://projecteuler.net/problem=10
@GrabResolver( name='s', root='https://oss.sonatype.org/repositories/snapshots' )
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
@Grab( 'com.bloidonia:groovy-stream:0.7.0-SNAPSHOT' )
import groovy.transform.*
import groovy.stream.Stream
import groovyx.gbench.Benchmark
@timyates
timyates / rdp.coffee
Created June 8, 2012 11:03 — forked from rhyolight/rdp.js
Ramer-Douglas-Peucker line filtering algorithm in JavaScript
findPerpendicularDistance = ( point, line ) ->
[pointX,pointY] = point[0..1]
lineStart = x: line[0][0], y: line[0][1]
lineEnd = x: line[1][0], y: line[1][1]
slope = ( lineEnd.y - lineStart.y ) / ( lineEnd.x - lineStart.x )
intercept = lineStart.y - ( slope * lineStart.x )
Math.abs( slope * pointX - pointY + intercept ) / Math.sqrt( Math.pow( slope, 2) + 1)
douglasPeucker = ( points, epsilon ) ->
maxIndex = maxDistance = 0