Skip to content

Instantly share code, notes, and snippets.

View annoyingmouse's full-sized avatar

Dominic Myers annoyingmouse

View GitHub Profile
diff --git a/js/sketch.js b/js/sketch.js
index 1f5c62f..7048e55 100644
--- a/js/sketch.js
+++ b/js/sketch.js
@@ -96,7 +96,7 @@ var __slice = Array.prototype.slice;
return this.redraw();
};
Sketch.prototype.onEvent = function(e) {
- if (e.originalEvent && e.originalEvent.targetTouches) {
+ if (e.originalEvent && e.originalEvent.targetTouches && e.originalEvent.targetTouches[0]) {
@mlocati
mlocati / color-scale.js
Last active September 13, 2025 12:00
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
// License: MIT - https://opensource.org/licenses/MIT
// Author: Michele Locati <michele@locati.it>
// Source: https://gist.github.com/mlocati/7210513
function perc2color(perc) {
var r, g, b = 0;
if(perc < 50) {
r = 255;
g = Math.round(5.1 * perc);
}
else {
@fernandojsg
fernandojsg / JS: JSON pretty
Created May 14, 2013 15:52
JS: JSON pretty
var obj = {a:1, 'b':'foo', c:[false,null, {d:{e:1.3e5}}]};
var str = JSON.stringify(obj, undefined, 2); // indentation level = 2
See the MDN Docs for further details (e.g. on the second argument);
If you need syntax highlighting, you might use some regex magic like so:
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
@tylerhall
tylerhall / strong-passwords.php
Created August 12, 2010 21:38
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by