Skip to content

Instantly share code, notes, and snippets.

View Spaxe's full-sized avatar
🏹

Xavier Ho Spaxe

🏹
View GitHub Profile
Take original image A, blur it to get image B. Then:
(A-B) * effectStrength + A
gives you output with lots more apparent detail.
It boosts contrast against surrounding pixels. A blur kernel with 1 pixel radius is equivalent to standard pixel sharpening, bigger blurs give a better effect but produce haloes around objects. You need a smarter blur that preserves edges to remove them.
@Spaxe
Spaxe / p5js-browserfy-example.js
Created March 13, 2015 00:11
p5js with browserfy
// Thanks to @brysonian
// https://github.com/processing/p5.js/issues/522#issuecomment-78510817
var p5 = require("p5");
var myp5 = new p5(function( sketch ) {
sketch.setup = function() {
var cnv = sketch.createCanvas(500, 500);
sketch.colorMode(sketch.HSB, 360, 100, 100);
sketch.noStroke();
};
@Spaxe
Spaxe / gitter-p5js-email
Last active August 29, 2015 14:17
Adding processing/p5.js to Gitter Chatroom
Hey p5js people,
I recently started using p5.js. After transitioning from Processing to
Prcoessing.py, p5.js seems like a good step to go. Thanks for making this
possible, and I expect to be contributing to the Github page soon.
At the moment there aren't a lot of real-time conversation places for p5.js. I
have found the Education Page, the Forum, and of course the GitHub Issues page.
There are great, searchable resources, but no direct access to human resources.
@Spaxe
Spaxe / loop.js
Created March 16, 2015 00:43
It's 2015 and I still have to write this to iterate through objects in Javascript.
// Util functions
var Util = {
loop: function (obj, callback) {
for (var x in obj) {
if (obj.hasOwnProperty(x)) {
callback(x, obj[x]);
}
}
return obj;
}
@Spaxe
Spaxe / Usage Example
Created March 17, 2015 02:29
Deploy master to GitHub Pages and push both branches
# Step 0: save git-deploy-master somewhere in your $PATH and make sure it has execute permission.
# in master, commit your code
git commit -m "Updated website"
# Deploy to gh-pages
git deploy-master
@Spaxe
Spaxe / split-tsv.py
Created August 7, 2015 00:41
Splits large tab-separated value files into smaller ones.
#!/usr/bin/env python3
'''Breaks large tab-separated value files into smaller files'''
import argparse
def split_tsv(filepath, lines, limit):
header = []
with open(filepath, 'r') as f:
# Assume there is header
header = f.readline().split()
@Spaxe
Spaxe / jquery.promise.js
Created August 31, 2015 23:55
jQuery promise pseudo code
var i = 0;
function makeChartFromList(list) {
function consume ( data ) {
process(data);
i++;
if (i === list.length) {
$.Deferred().resolve();
} else {
PGraphics gStuff;
int w = 400;
int h = 300;
void setup () {
size(w, h);
gStuff = createGraphics(w, h);
}
void draw() {
@Spaxe
Spaxe / mobile-detect.js
Created February 8, 2012 12:16
Detecting Mobile devices with Javascript
function TouchScreenAdapt()
{
if (typeof TouchEvent != "undefined")
{
$('body').removeClass('mouse').addClass('touch');
}
}
@Spaxe
Spaxe / audio.js
Created April 11, 2012 04:44
Quick and dirty way of selectively loading a playable audio file in HTML5
// Because HTML5 Audio support isn't all that consistent, we need to do something.
// With at least both .ogg and .mp3 formats, they will play on all 5 major
// browsers on the desktop.
// XXX If more ancient support is desired, feel free to add <embed> support. Or Flash.
//
// sources should be a list of audio files of the same sound, but in different formats.
// e.g.: ['effect.ogg', 'effect.mp3', 'effect.wav']
// Depending on the browser capability, it will only add one of them that is playable.
// If no compatible format is found for that browser, a warning will be issued.
// List of Audio MIME Types: