This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://phrogz.net/SVG/convert_path_to_polygon.xhtml | |
function pathToPolygon(path,samples){ | |
if (!samples) samples = 0; | |
var doc = path.ownerDocument; | |
var poly = doc.createElementNS('http://www.w3.org/2000/svg','polygon'); | |
// Put all path segments in a queue | |
for (var segs=[],s=path.pathSegList,i=s.numberOfItems-1;i>=0;--i) segs[i] = s.getItem(i); | |
var segments = segs.concat(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Benchmarking answers to http://stackoverflow.com/questions/9333952/in-ruby-how-to-make-the-string-include-method-ignore-case/9334066 | |
# http://www.gutenberg.org/cache/epub/1661/pg1661.txt | |
strings = IO.read('sherlock.txt').scan(/\w+/) # 109,222 words | |
known = 500.times.map do | |
strings.sample.downcase.chars.map{ |c| rand<0.5 ? c.upcase : c }.join | |
end | |
words = known.flat_map{ |s| [s, s+"-"] } # \w does not include - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = [ | |
[1,'1'], | |
[6,'6'], | |
[9,'9'], | |
[10,'10'], | |
[11,'11'], | |
[19,'19'], | |
[90,'90'], | |
[99,'99'], | |
[100,'100'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Storing response objects for delayed responses | |
const responseByMessage = {} | |
// A forked process that does some necessary heavy lifting | |
const worker = require('child_process').fork( | |
require('path').resolve('worker.js'), [], | |
{stdio:['inherit', 'inherit', 'inherit', 'ipc']} | |
) | |
require('http').createServer(function (req, res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /etc/init.d/minecraft | |
# version 0.3.4 2011-06-12 (YYYY-MM-DD) | |
### BEGIN INIT INFO | |
# Provides: minecraft | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Should-Start: $network | |
# Should-Stop: $network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc = (new DOMParser).parseFromString('<r xmlns="uri1" xmlns:xx="uri2"><b/></r>', 'text/xml'); | |
doc.querySelector('b').setAttributeNS('uri2', 'foo', 'bar'); | |
(new XMLSerializer).serializeToString(doc); | |
// "<r xmlns="uri1" xmlns:xx="uri2"><b xmlns:ns14641696="uri2" ns14641696:foo="bar"/></r>" | |
doc = (new DOMParser).parseFromString('<r xmlns="uri1" xmlns:xx="uri2"><b/></r>', 'text/xml'); | |
doc.querySelector('b').setAttributeNS('uri2', 'xx:foo', 'bar'); | |
(new XMLSerializer).serializeToString(doc); | |
// "<r xmlns="uri1" xmlns:xx="uri2"><b xx:foo="bar"/></r>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ƒ(name){ | |
let v,params=Array.prototype.slice.call(arguments,1); | |
return o=>(typeof (v=o[name])==='function' ? v.apply(o,params) : v); | |
} | |
a = ["foo", "barmitzvah"] | |
a.map(ƒ('length')) // [3, 10] | |
a.map(ƒ('toUpperCase')) // ["FOO", "BARMITZVAH"] | |
a.map(ƒ('slice',1)) // ["oo", "armitzvah"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xml = | |
`<r a="42" xmlns:blah="MYURI"> | |
<e> <!-- my house --> </e> | |
<f>9<42</f> | |
<blah:dumb>go away</blah:dumb> | |
<g><![CDATA[5<7]]></g> | |
</r>`; | |
let doc = (new DOMParser).parseFromString(xml, 'application/xml'); | |
console.log(NeatSerializer(doc)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let p = console.log; | |
let Interceptor = { hi:_=>"I am "+this.name } | |
function Person(name) { | |
this.name = name; | |
} | |
Person.prototype.hi = function() { | |
return "Hello, I'm "+this.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- An expression to evaluate | |
local expr = 'a + (b or 0)' | |
-- Set up two different environments we want our expression to be evaluated against | |
local env1,env2 = {a=17}, {a=1,b=25} | |
-- Create a wrapper environment with a metatable | |
local envmeta = {} | |
local envwrap = setmetatable({},envmeta) |
NewerOlder