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 / euler_method.ipynb
Last active April 13, 2022 06:43
euler method
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lykkin
lykkin / some_kinda_parser.py
Last active April 7, 2021 08:25
idk my bff xml
import re
namespace_pattern = re.compile('{(?P<ns>[^}]*}')
def process_node(node, cb):
url = None
ns = namespace_pattern.match(node.tag)
if ns is not None:
url = ns.groupdict()['ns']
@lykkin
lykkin / wrapper.js
Created February 10, 2021 05:01
ez wrapping
'use strict'
const Emitter = require('events')
const oldEmitter = Emitter.prototype.emit
Emitter.prototype.emit = function wrappedEmit(ev) {
const start = Date.now()
const res = oldEmitter.apply(this, arguments)
console.log(`emitting ${ev} on ${this.constructor} took ${Date.now() - start} ms`)
return res
}
@lykkin
lykkin / qs.cpp
Created July 22, 2018 19:53
in place quicksort
#include <iostream>
#include <vector>
using namespace std;
void print(vector<int> a) {
for (int el : a) {
cout << el << " ";
}
cout << endl;
@lykkin
lykkin / iterative.js
Created April 27, 2018 05:32
i will never fibb
var min = this._data.findMinimum()
var data = []
var iterationNodes = [min]
var iterationHeads = [min]
var depth = 0
if (min) {
var current
while (depth >= 0) {
current = iterationNodes[depth]
@lykkin
lykkin / a.js
Created October 14, 2017 18:38
no defineProp for nonenum
function a(x) { this.x = 1 }
a.prototype.toJSON = function () {return}
x = {test: new a(1)}
JSON.stringify(x)
@lykkin
lykkin / stack.js
Created June 26, 2017 23:21
long stacks
var oldNextTick = process.nextTick
process.nextTick = function(cb) {
var stack = (new Error()).stack
return oldNextTick.call(process, function() {
try {
return cb.apply(this, arguments)
} catch (e) {
e.stack = stack + e.stack
throw e
}
new Promise(function(res, rej) {
return Promise.all([
1,
10,
100,
1000
].map(function createPromises(time) {
return new Promise(function(res, rej) {
setTimeout(function() {
console.log('waited ' + time + ' ms!')
@lykkin
lykkin / winner.js
Created May 21, 2017 09:49
odds of getting a chicken dinner
var factArr = [1]
function fact(n) {
if (n > factArr.length) {
for (var i = factArr.length; i <= n; ++i) {
factArr[i] = factArr[i - 1] * i
}
}
return factArr[n]
}
function collatz(n) {
var chain = [n]
while (n !== 1) {
if (n % 2 === 0) {
n /= 2
} else {
n = n * 3 + 1
}
chain.push(n)
}