This file contains hidden or 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) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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'], |
OlderNewer