Skip to content

Instantly share code, notes, and snippets.

View Tom-Alexander's full-sized avatar

Tom Alexander Tom-Alexander

View GitHub Profile
@Tom-Alexander
Tom-Alexander / pathFromPolygon.js
Created April 28, 2016 19:57
Converts an SVG polygon to a path
function pathFromPolygon(points) {
var p = points.split(/\s+/);
var path = '';
for( var i = 0, len = p.length; i < len; i++ ) {
path += (i && 'L' || 'M') + p[i]
}
return path;
}
@Tom-Alexander
Tom-Alexander / parser.rb
Last active February 25, 2019 08:12
Recursive descent parser
# Recursive descent parser
# http://adayinthepit.com/2011/07/19/hanging-in-the-treetops/
def exp(stack)
token = stack.shift
return stack if token =~ /[0-9]/ || token =~ /X/ && exp(stack) || token =~ /Y|Z/ && exp(stack) && exp(stack)
false
end
def parse(source)
stack = exp(source.split(''))