Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / fox.cow
Last active December 28, 2015 07:09
a fox cowsay cow WHAT DOES THE FOX SAY? Sorry I am not a ascii artist :(
$the_cow = <<"EOC";
$thoughts
$thoughts
$thoughts
$thoughts _
|\\ _/ \\
| \\------/ , )
| \\ | | |
\\ / /
___,--------____ / \\
@NickBeeuwsaert
NickBeeuwsaert / why.py
Created November 2, 2013 03:59
Some stupid programmer humor
#!/usr/bin/env python
if __name__ == "__main__":
print("Why do programmers confuse Halloween and Christmas?");
print("Because oct %o == dec %d!"%(25, 031));
all: main.c
gcc -o main main.c -I/opt/X11/include/cairo -I/opt/X11/include/pixman-1 -I/opt/X11/include -I/opt/X11/include/freetype2 -I/opt/X11/include -I/opt/X11/include/libpng15 -I/opt/X11/include -I/usr/include/libxml2 -I/usr/local/Cellar/libsvg-cairo/0.1.6/include -I/usr/local/Cellar/libsvg/0.1.4/include -L/opt/X11/lib -L/usr/local/Cellar/libsvg-cairo/0.1.6/lib -L/usr/local/Cellar/libsvg/0.1.4/lib -lsvg-cairo -lsvg -lpng -ljpeg -lz -lxml2 -lcairo
@NickBeeuwsaert
NickBeeuwsaert / SVG_Load.c
Created September 3, 2013 20:36
Loads a SVG file into a SDL_Texture
/* Reads a SVG file into a SDL_Texture
inputs:
SDL_Renderer *r: the SDL_Renderer to use,
const char *filename: the file to load
returns:
SDL_Texture*: the loaded texture, or NULL if something went wrong
*/
SDL_Texture *SDL_TextureFromSVG(SDL_Renderer *r, const char *filename){
SDL_Texture *texture = NULL;
SDL_Surface *tmpSurface = NULL;