Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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
/**
* Compile with `gcc -o anagram main.c -std=c99`
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char *human_readable;
@NickBeeuwsaert
NickBeeuwsaert / Pack.c
Last active August 29, 2015 14:11
C functions for reading data out of a binary function, similar to pythons struct module
//
// Pack.cpp
//
// Created by Nick Beeuwsaert on 5/17/14.
// Copyright (c) 2014 Nick Beeuwsaert.
// MIT Licensed.
//
#include "Pack.h"
#include <stdarg.h>
@NickBeeuwsaert
NickBeeuwsaert / Makefile
Last active August 29, 2015 14:07
Drawing scalable images in SDL2
LIBS=`sdl2-config --libs` `pkg-config SDL2_image --libs`
CFLAGS=`sdl2-config --cflags` `pkg-config SDL2_image --cflags`
all: main.o
gcc -o main main.o $(LIBS) -Wall
main.o: main.c
gcc -o main.o -c main.c $(CFLAGS) -Wall
clean:
rm main.o main
@NickBeeuwsaert
NickBeeuwsaert / printElement.js
Last active March 22, 2017 06:38
This is a chrome snippet to take a screenshot of a element
/**
* NOTE: Because Chrome doesn't elevate the permissions
* of snippets, we can't push the image out to the browser
* using canvas.toDataURL(), we have to add it to the page
* and have the user right-click and save-as
*/
var css = function(el, styles){
for (var style in styles) {
if(!styles.hasOwnProperty(style)) continue;
el.style[style] = styles[style];