This file contains 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
{ | |
"scripts": { | |
"build:js": "microbundle -i test.js -o js_out/ -f modern", | |
"build:ts": "microbundle -i test.ts -o ts_out/ -f modern" | |
}, | |
"dependencies": { | |
"microbundle": "^0.12.4" | |
} | |
} |
This file contains 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
from contextlib import contextmanager | |
import threading | |
def use_context(context): | |
with context.consumer() as value: | |
return value | |
class Context(threading.local): | |
def __init__(self, default = None): | |
self.value = default |
This file contains 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* cartesianProduct(...iterables) { | |
const pools = iterables.map(function(iterable) { | |
const pool = Array.from(iterable); | |
return {pool, length: pool.length, counter: 0}; | |
}); | |
let iterations = pools.reduce( | |
(total, {length}) => total * length, | |
1 | |
); |
This file contains 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
let up = (msg) => new Error(msg); | |
function zip(...args) { | |
args = args.filter(arg => 'length' in args); | |
let result = []; | |
let minLength = Math.min(...args.map(arg => arg.length)); | |
if(args.length === 0) return result; | |
for(let i = 0; i < minLength; i++) { |
This file contains 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
export function serialize(element) { | |
// I could probably use form.elements here | |
// But I want this to work if elements are just in a div | |
const controls = Array.from(element.querySelectorAll("input, textarea, select, button")); | |
const withoutName = (control) => !!control.name; | |
const disabled = (control) => !control.disabled; | |
const removeFiles = (control) => !control.matches('input[type="file"]'); | |
const checkboxes = (control) => control.matches('input[type="checkbox"], input[type="radio"]')?control.checked:true; | |
This file contains 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 range(start, stop, step=1) { | |
let length = 0; | |
if(arguments.length == 1) { | |
[start, stop, step] = [0, start, 1]; | |
} | |
[start, stop, step] = [start, stop, step].map(Math.floor); | |
if(step === 0) | |
throw new TypeError("step cannot be zero"); |
This file contains 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
<?php | |
// Data like one might recieve from a form | |
$data = [ | |
'id' => [ | |
10, | |
20, | |
100, | |
], | |
'first_name' => [ | |
"Nick", |
This file contains 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
#!/usr/bin/env python | |
from __future__ import division | |
from OpenGL.GL import * | |
import numpy as np | |
import math | |
import pygame | |
import textwrap | |
from PIL import Image | |
vertex_shader_source = textwrap.dedent("""\ |
This file contains 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
import numpy | |
import math | |
def perspective(fovy, aspect, z_near, z_far): | |
f = 1 / math.tan(math.radians(fovy) / 2) | |
return numpy.array([[f / aspect, 0, 0, 0], | |
[ 0, f, 0, 0], | |
[ 0, 0, (z_far + z_near) / (z_near - z_far), -1], | |
[ 0, 0, (2*z_far*z_near) / (z_near - z_far), 0]]) |
This file contains 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
"""I'm using ctypes to interact with cairo instead of pycairo | |
because pycairo hasn't been updated in 4 years and has features missing | |
in python3. | |
""" | |
import ctypes | |
import ctypes.util | |
from ctypes import c_void_p, c_double | |
# Enumerate pixel formats | |
FORMAT_INVALID = -1 |
NewerOlder