Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@NickBeeuwsaert
NickBeeuwsaert / svg_simplify.py
Created February 17, 2015 21:50
a test script to simplify SVG paths (ALso: Doesn't work for complex SVG paths, its just a proof of concept)
#!/usr/bin/env python
from xml.dom.minidom import parseString
import sys
import re
"""DISCLAIMER: I wrote this in like 30 minutes, its really hacky and a proof of concept"""
get_pairs = lambda i,l=2:map(None, *[iter(i)]*l)
coord_add = lambda l, r: l + r
@NickBeeuwsaert
NickBeeuwsaert / Makefile
Created April 30, 2015 12:45
Here's a crappy little library I wrote to do matrix math in C because why not
main: main.c
gcc -o main main.c
@NickBeeuwsaert
NickBeeuwsaert / zip.js
Created July 13, 2015 03:51
Python like `zip`-ping
var zip = function() {
var result = [];
// Only zip array-like items
var args = Array.prototype.filter.call(arguments, function(el){
//Make sure the argument is array-like
return typeof el.length !== "undefined";
});
//if we have no items to reduce then return an empty array
if(args.length === 0) return result;
@NickBeeuwsaert
NickBeeuwsaert / PrintElement.js
Last active July 3, 2016 07:21
Chrome DevTools snippet to print out a element
/* Attempts to screen-shot a element onto a canvas */
var css = function(el, styles){
for (var style in styles) {
if(!styles.hasOwnProperty(style)) continue;
el.style[style] = styles[style];
}
return el;
};
var selectElement = function(callback){
var selection = document.createElement("div");
@NickBeeuwsaert
NickBeeuwsaert / main.py
Last active August 29, 2015 14:25
Trying to do simple subcommands in python
#!/usr/bin/env python3
import argparse
class Command(object):
name = None
aliases = []
description = None
@classmethod
@NickBeeuwsaert
NickBeeuwsaert / py2js.py
Last active January 18, 2016 03:19
Attempt at converting Python's AST into ES2015
#!/usr/bin/env python3
""" NOTE: This is incomplete!
There are a lot of things that don't work,
like classes, generator functions and async functions!
"""
import ast
import itertools
import json
from io import StringIO
import argparse
@NickBeeuwsaert
NickBeeuwsaert / ccairo.py
Created February 15, 2016 02:47
Using SDL2 and Cairo from python
"""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
@NickBeeuwsaert
NickBeeuwsaert / matrix.py
Last active March 8, 2016 02:38
Crappy MS3D parser
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]])
@NickBeeuwsaert
NickBeeuwsaert / main.py
Last active November 19, 2024 01:58
OpenGL Shader example using python
#!/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("""\
@NickBeeuwsaert
NickBeeuwsaert / example.php
Last active March 19, 2016 03:39
Some functional array utilities in PHP. (TBH I just wanted to see how many times I could not type `for`)
<?php
// Data like one might recieve from a form
$data = [
'id' => [
10,
20,
100,
],
'first_name' => [
"Nick",