Skip to content

Instantly share code, notes, and snippets.

Max Nordlund maxnordlund

Block or report user

Report or block maxnordlund

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

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:

View _disable_stealthy_require.js
// 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 Sep 27, 2018
Quick micro benchmark regarding passing of arguments
View benchmark.js
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 Apr 20, 2017
Get the defining class for a unbound method in Python
View method_reflection.py
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 Mar 30, 2017
Pure CSS for `hr` element with caption
View horizontal-ruler-with-caption.scss
$size: 1rem;
$background: white;
hr[title] {
line-height: 0;
&::after {
background: $background;
content: attr(title);
@maxnordlund
maxnordlund / default_list.py
Created Mar 14, 2017
Default list in python, á la defaultdict.
View default_list.py
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 Dec 18, 2016
Multiple inheritance in JavaScript
View multiple-inheritance.js
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 Oct 5, 2016
Pillow 3.4.1 test logs
View python2.log
......................................................................................................SSSSSSSSSSSSSSSSSSSSSSSSSS..........................................SS........................SS......................................................................................................................................SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS.............................................................................................S..S.....................................................................................................................................................................................................................F...................................................................................................................................S..................S....SSSSSS...SSSSSS.........................................................SSSSSSSSSSSSSSSSSSSS....................................................................................S....S..
@maxnordlund
maxnordlund / syncron.js
Last active Aug 22, 2016
A nano framework for synchronized DOM updates
View syncron.js
(function() {
var consoleError,
renderLoop,
queue = [],
rAF = window.requestAnimationFrame || function(fn) {
setTimeout(fn, 0)
}
if (typeof console === "object" &&
typeof console.error === "function") {
View asdq-2016-hack.js
$$("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])"
))
You can’t perform that action at this time.