Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@NickBeeuwsaert
NickBeeuwsaert / gist:7490404
Created November 15, 2013 19:42
Pruning my homebrew installation
$ #remove all packages, except the ones I absolutely cannot live without
$ brew uninstall $(comm -13 <((for package in $(echo sdl2 sdl2_{image,mixer,ttf} tmux pianobar pypy python python3 mongodb webkit2png cowsay git figlet); do echo $package; brew deps $package; done;) | sort -u -) <(brew list))
@NickBeeuwsaert
NickBeeuwsaert / json_pretty_encode.php
Last active October 27, 2021 14:08
PHP versions prior to 5.4 didn't have JSON_PRETTY_PRINT for json_encode, so here, I guess...
<?php
//PHP got the JSON_PRETTY_PRINT option for json_encode in 5.4, and I had to use a older version of PHP,
// So I made this
function json_pretty_encode($arr, $indent=" ", $characters=array(", ", ": "), $depth=0, $eol=PHP_EOL){
//You'd think that with the plethora of functions PHP has for array operations, they'd have one to check
// if an array is associative or not
// Now, I know what your saying "Oh, but, ALL arrays in PHP are associative!" Suck it, you know what I mean
$is_assoc = (array_keys($arr) !== range(0,count($arr)-1));
end($arr);
@NickBeeuwsaert
NickBeeuwsaert / os.php
Last active December 31, 2015 16:29
Trying to get all include'd files in a PHP project (mostly so I can know in advance the horrors that await me)
<?php
namespace os;
define("DS", DIRECTORY_SEPARATOR);
function walk($top){
$traverse = array($top);
#foreach($traverse as &$dir){
for($i = 0; $i < count($traverse); $i++){
$dir = $traverse[$i];
$tuple = array($dir, array(), array());
//ignore this directory(we are iterating over it) and the parent directory
@NickBeeuwsaert
NickBeeuwsaert / select.js
Created December 31, 2013 23:18
Select! a element
function selectElement(callback){
var selectorDiv = document.createElement("div");
var css = function(e, styles){
for(style in styles){
if(styles.hasOwnProperty(style))
e.style[style.replace(/-(.)/g, function(a,b){return b.toUpperCase();})] = styles[style];
}
};
var pos = function(e){
var pos = {"left": e.offsetLeft, "top": e.offsetTop};
@NickBeeuwsaert
NickBeeuwsaert / bookmarklet.js
Last active January 1, 2016 22:29
Converts HTML comments into multiline comments for fun and yeah
javascript:(function(){var d=function(a,c){for(style in c)c.hasOwnProperty(style)&&(a.style[style.replace(/-(.)/g,function(a,c){return c.toUpperCase()})]=c[style])};(function(a){var c=document.createElement("div");d(c,{border:"1px solid hsl(240, 80%, 70%)",background:"hsla(240, 50%, 90%,0.5)",top:"0",left:"0",width:"0",height:"0",display:"none","pointer-events":"none",position:"absolute","z-index":"1000",transition:"width 0.5s, height 0.5s, top 0.5s, left 0.5s"});document.body.appendChild(c);var b=function(a){a= a.target;if(a!=c){for(var b=a,e=b.offsetLeft,f=b.offsetTop;b=b.offsetParent;)e+=b.offsetLeft,f+=b.offsetTop;d(c,{top:f+"px",left:e+"px",display:"block",width:a.offsetWidth-2+"px",height:a.offsetHeight-2+"px"})}},g=function(d){d.preventDefault();d.stopPropagation();a(d.target);document.removeEventListener("mouseover",b);document.removeEventListener("mousedown",g);c.parentNode.removeChild(c);return!1};document.addEventListener("mouseover",b);document.addEventListener("mousedown",g)})(function(a){var c=
@NickBeeuwsaert
NickBeeuwsaert / fun.py
Last active August 29, 2015 14:04
I was messing around with writing directly to a terminal
#!/usr/bin/env python
import time
import subprocess
import sys
import random
import fcntl, termios, struct
import re
message = "Mess with the best. Die like the rest"
with open(sys.argv[1], "wb", 0) as tty:
height, width = struct.unpack('hh', fcntl.ioctl(tty.fileno(), termios.TIOCGWINSZ, '1234'))
@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];
@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 / 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>
/**
* 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;