Skip to content

Instantly share code, notes, and snippets.

View aaronsnoswell's full-sized avatar

Aaron Snoswell aaronsnoswell

  • Australia
View GitHub Profile
@aaronsnoswell
aaronsnoswell / LICENSE.txt
Created September 4, 2011 15:27 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Aaron Snoswell http://elucidatedbinary.com
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@aaronsnoswell
aaronsnoswell / addtopath.sh
Created December 6, 2011 06:08
Add to path
#!/bin/sh
# Adds the given parameter to the path
export PATH=$PATH:$1 && echo "export PATH=\$PATH:$1" >> ~/.bashrc
@aaronsnoswell
aaronsnoswell / ls.js
Created December 6, 2011 07:31
Easy localStorage caching
/**
* Stores the given key, value pair in localStorage, if it is available
*/
function setLocalStorageValue(key, value) {
if (window.localStorage) {
try {
localStorage.setItem(key, value);
} catch (e) {
// For some reason we couldn't save the value :(
console.log("ERROR | Unable to save to localStorage!", key, value, e);
@aaronsnoswell
aaronsnoswell / isdef.js
Created December 13, 2011 04:51
Easy js definition checking
/**
* Checks if the given object is defined
*/
function isdef(o) {
if(typeof(o)=="undefined") return false;
return true;
}
@aaronsnoswell
aaronsnoswell / gist:1873849
Created February 21, 2012 04:58
Canvas Perlin Noise Generator
// l33t codes go here
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
var randcache = [];
function noise(x, y) {
/*
var n = (x) + (y*57);
@aaronsnoswell
aaronsnoswell / gist:1876320
Created February 21, 2012 12:42
Better Canvas Perlin Noise
// l33t codes go here
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
/**
* The general idea with perlin noise is to generate
* noise at several resolutions and overlay them
* with varying amplitudes and opacities.
*
@aaronsnoswell
aaronsnoswell / screen_record.sh
Created July 9, 2012 07:19
Easy Linux Screen Capture
#!/bin/bash
while :
do
import -window root "png:/home/aaron/Pictures/screen_capture/`date +%Y_%m_%d-%H:%M:%S`.png"
echo "Saved `date +%Y_%m_%d-%H:%M:%S`.png";
sleep 30
done
@aaronsnoswell
aaronsnoswell / gist:3786176
Created September 26, 2012 05:00
Android Webkit <input type="number" /> shim.
// jQuery version
$("input[type='number']").each(function(i, el) {
el.type = "text";
el.onfocus = function(){this.type="number";};
el.onblur = function(){this.type="text";};
});
// Stand-alone version
(function(){ var elms = document.querySelectorAll("input"), i=elms.length;
/* Formats a human-, or machine-friendly string to be suitable for use as a
* CSS class name.
*/
var classify = function(text) {
text = (text != undefined) ? text : "";
return text.toLowerCase().replace(/\s/g, "_").replace(/[^a-zA-Z0-9_]/g, "");
}
@aaronsnoswell
aaronsnoswell / gist:3921992
Created October 20, 2012 04:17
Fast Unit Vector Normalisation for Discrete Spaces
// Really (really) fast unit vector normalisation
var c = 0.7071067812;
if(v[X] != 0 && v[Y] != 0) {
v[X] *= c, v[Y] *= c;
}