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
const EventEmitter = require('events') | |
class UserEmitter extends EventEmitter {} | |
const e = new UserEmitter() | |
e.on('incomingData', (data) => { | |
data.forEach((user) => e.emit(user.id, user)) | |
}) | |
userId = 0 | |
class User { |
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
var heap = { | |
heap: [], | |
add(n) { | |
this.heap.push(n) | |
this.siftUp() | |
}, | |
pop() { | |
let res = this.heap[0] | |
this.heap[0] = this.heap[this.heap.length - 1] | |
this.heap.pop() |
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
var hash = { | |
trie: {}, | |
store(k, v) { | |
let current = this.trie | |
k.split('').forEach((letter) => { | |
if (!this.trie[letter]) { | |
this.trie[letter] = {} | |
} | |
current = this.trie[letter] | |
}) |
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
var http = require('http') | |
//Create sample server to send requests to | |
var server = http.createServer(function(request, response) { | |
//Grab the last bit of the url and call it the name | |
var name = request.url.split('/').slice(-1) | |
//Wait a second to respond | |
setTimeout(function (){ | |
//Tell the person hello! | |
response.write('hello ' + 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
function fact(n) { | |
var res = 1 | |
for (var i = 1; i <= n; i++) { | |
res *= i | |
} | |
return res | |
} | |
function choose(n, k) { |
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
#include <iostream> | |
using namespace std; | |
template<typename T, T... values> | |
struct value_tuple { | |
static const size_t size = sizeof...(values); | |
typedef T value_type; | |
}; |
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
def log(f): | |
def logging_wrap(*args, **kwargs): | |
print 'init', args, kwargs | |
return f(*args, **kwargs) | |
return logging_wrap | |
@log | |
def test(*args): | |
return reduce(lambda a, b: a + b, args, 0) |
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
#include <iostream> | |
using namespace std; | |
template <int x, int y> | |
struct gcd { | |
enum { value = gcd<y, x%y>::value }; | |
}; | |
template <int x> |
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 div(n,m){for(var l=m;l>0;l--){for(var k=0;k<m-1;k++){n--}}return n} | |
function rem(n,m){for(var l=0;n>=m;l++){for(var k=0;k<m;k++){n--}}return n} | |
function mul(n,m){for(var l=n;m>1;m--){for(var i=0;i<l;i++){n++}}return n} | |
function sub(n,m){for(var i=0;i<m;i++){n--}return n} | |
function add(n,m){for(var i=0;i<m;i++){n++}return n} |
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
> arguments.callee.arguments | |
{ '0': [Function], | |
length: 1, | |
callee: 'function callTest(callme) {\n debugger\n callme()\n}', | |
undefined: [Function] } | |
> arguments.callee.arguments.undefined | |
> arguments.callee.arguments.undefined() | |
TypeError: arguments.callee.arguments.undefined is not a function |