Skip to content

Instantly share code, notes, and snippets.

View maxnordlund's full-sized avatar

Max Nordlund maxnordlund

View GitHub Profile
@maxnordlund
maxnordlund / keybase.md
Created August 8, 2019 11:03
Keybase proof

Keybase proof

I hereby claim:

  • I am maxnordlund on github.
  • I am maxnordlund (https://keybase.io/maxnordlund) on keybase.
  • I have a public key ASBnMu1IGUACj7EGUL_RjMcu4g856OgXkYI9Yy0o_tFfsQo

To claim this, I am signing this object:

// Disable stealthy-require as it breaks ESM in modernish node
// 1. Load stealthy-require into the require cache. This way all the module
// machinery gets run like normal.
require("stealthy-require")
// 1. Overwrite the real function with a dummy one
require.cache[require.resolve("stealthy-require")].exports = notSoSthealthyRequire
// 3. Dummy implementation that calls the provided callbacks in the right order
@maxnordlund
maxnordlund / benchmark.js
Last active September 27, 2018 12:19
Quick micro benchmark regarding passing of arguments
module.exports = exports = benchmark
function benchmark(size, fn, name) {
console.time("benchmark " + name)
var result = 0
for (var i = 0; i < size; ++i) result = fn(result, i)()
console.timeEnd("benchmark " + name)
console.log(result)
@maxnordlund
maxnordlund / method_reflection.py
Last active April 20, 2017 15:36
Get the defining class for a unbound method in Python
def get_class(method):
"""
Get the class that the defined the provided method.
In Python 3 the concept of unbound method is removed and raw method
references are just plain functions. But it is sometimes useful to get the
class that defined that method. Unfortunately that turns out to be hard.
But there is a sure fire way of doing it, because Python exposes the
variables that a method can access, which by definition includes the
surronding class, so just go through that and find the class.
Of course it's not quite that simple. First off to find the class we check
@maxnordlund
maxnordlund / horizontal-ruler-with-caption.scss
Last active March 30, 2017 14:39
Pure CSS for `hr` element with caption
$size: 1rem;
$background: white;
hr[title] {
line-height: 0;
&::after {
background: $background;
content: attr(title);
@maxnordlund
maxnordlund / default_list.py
Created March 14, 2017 13:36
Default list in python, á la defaultdict.
class DefaultList(list):
"""
List that always returns a value
If you try to access an missing index, it will fill up this list with
empty lists for all missing indices before returning the requested
index. This will be the last element since lists are ordered.
A consequence of this is that `for` loops over this list will never
stop.
@maxnordlund
maxnordlund / multiple-inheritance.js
Last active December 18, 2016 11:10
Multiple inheritance in JavaScript
export default function createMixinFrom(...classes) {
let proto = Object.create(null)
function AnonymousMixinClass(...parameters) {
let proto = Object.getPrototypeOf(this)
// Run all super class constructors in order they were given.
// *This doesn't work without babel, sadly, because classes can't be called
// with an user supplied context*
classes.forEach(klass) => {
@maxnordlund
maxnordlund / python2.log
Created October 5, 2016 20:42
Pillow 3.4.1 test logs
......................................................................................................SSSSSSSSSSSSSSSSSSSSSSSSSS..........................................SS........................SS......................................................................................................................................SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS.............................................................................................S..S.....................................................................................................................................................................................................................F...................................................................................................................................S..................S....SSSSSS...SSSSSS.........................................................SSSSSSSSSSSSSSSSSSSS....................................................................................S....S..
@maxnordlund
maxnordlund / syncron.js
Last active August 22, 2016 21:03
A nano framework for synchronized DOM updates
(function() {
var consoleError,
renderLoop,
queue = [],
rAF = window.requestAnimationFrame || function(fn) {
setTimeout(fn, 0)
}
if (typeof console === "object" &&
typeof console.error === "function") {
$$("tbody td:first-child:not([colspan])").forEach(function use24hclock(td) {
td.textContent = moment(td.textContent, "hh:mm a").format("HH:mm")
})
function markAired() {
var date, i, style, td, tr,
tds = Array.from(document.querySelectorAll(
"tbody td:first-child:not([colspan])"
))