Skip to content

Instantly share code, notes, and snippets.

View lykkin's full-sized avatar
🐄
Moo

Bryan Clement lykkin

🐄
Moo
View GitHub Profile
@lykkin
lykkin / eg.js
Created March 22, 2017 00:05
emitter garbage
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 {
@lykkin
lykkin / heaps.js
Created February 7, 2017 07:11
heapin it on
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()
@lykkin
lykkin / trieHashKids.js
Created February 7, 2017 06:59
trie me
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]
})
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)
@lykkin
lykkin / choosin.js
Last active December 1, 2016 03:28
function fact(n) {
var res = 1
for (var i = 1; i <= n; i++) {
res *= i
}
return res
}
function choose(n, k) {
#include <iostream>
using namespace std;
template<typename T, T... values>
struct value_tuple {
static const size_t size = sizeof...(values);
typedef T value_type;
};
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)
#include <iostream>
using namespace std;
template <int x, int y>
struct gcd {
enum { value = gcd<y, x%y>::value };
};
template <int x>
@lykkin
lykkin / gist:65dd6329d454f3161181
Created March 5, 2016 05:36
arithmetic using loops/inc/dec
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}
> 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