Skip to content

Instantly share code, notes, and snippets.

@hughsk
hughsk / lessmark.js
Created October 28, 2011 07:36
Pick up compiled LESS code using a bookmarklet!
//Bookmarklet Code
$('head style').each(function() {if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {var lesscode = $(document.createElement('div'));lesscode.html($(this).text().replace(/\/\*.*?\*\//g,' ').replace(/[ ]{2,100}/g,' '));lesscode.css('padding','20px').css('font-size','10px').css('background-color','#ddd').css('font-family','monospace');$('body:last-child').append(lesscode);} });
//Legible version
$('head style').each(function() {
if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {
var lesscode = $(document.createElement('div'));
//Clean up a lot of comments and white space...
lesscode.html($(this).text().
@hughsk
hughsk / grid.jsx
Created December 15, 2011 11:57
Generating Large Image Grids in Photoshop using Javascript
var shuffleAndValidateFiles = function(files) {
var F = new Array();
while (files.length > 0) {
var N = Math.floor(Math.random()*files.length);
if ((files[N] instanceof File) && !files[N].hidden) {
F.push(files[N]);
}
files.splice(N,1);
@hughsk
hughsk / Boide.pde
Created December 27, 2011 08:40
Simple Boids example in Processing
class Boid {
PVector pos;
PVector spd;
PVector acc;
Boid() { this(random(0, width), random(0, height)); }
Boid(float x, float y) { this(x, y, random(0,1), random(0,1)); }
Boid(float x, float y, float xspd, float yspd) {
pos = new PVector(x, y);
@hughsk
hughsk / rmdirSyncForce.js
Created February 1, 2012 07:47
Synchronous `rmdir --recursive` for NodeJS.
// Thanks to [liangzan's gist](https://gist.github.com/807712)
rmdirSyncForce = function(path) {
var files, file, fileStats, i, filesLength;
if (path[path.length - 1] !== '/') {
path = path + '/';
}
files = fs.readdirSync(path);
filesLength = files.length;
@hughsk
hughsk / post-receive.sh
Created April 3, 2012 09:45
Node + Git push-to-deploy hook
# GITBAREDIR e.g. "/home/web/present-company.git"
GITBAREDIR=`pwd`;
# GITPROJECTDIR e.g. "present-company"
GITPROJECTDIR=`basename $PWD | sed 's/.git//g'`;
# Stop the application, move up on directory
npm stop;
cd ..;
@hughsk
hughsk / .gitignore
Created September 18, 2012 01:19
Trickle
node_modules
<style type='text/css'> html, body { margin: 0; padding: 0; border: 0; } </style>
var perlin = require('perlin').noise.perlin3
var fill = require('ndarray-fill')
var zeros = require('zeros')
var scale = 0.075
var threshold = 0.125
// Untested in 3D, but "theoretically" this should
// work. Using the equivalent 2d getter with the
// continuous-box2d demo works well.
@hughsk
hughsk / index.js
Created September 1, 2013 11:21
requirebin sketch
// Load up the `raf` module.
var raf = require('raf')
// Create the canvas, and add it
// to the page.
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
var width = 500
var height = 300
@hughsk
hughsk / index.js
Created September 1, 2013 14:13
requirebin sketch
// Load up the `raf` module.
var raf = require('raf')
var controls = require('kb-controls-iframed')({
'W': 'up',
'A': 'left',
'S': 'down',
'D': 'right',
'<up>': 'up',
'<left>': 'left',
'<down>': 'down',