Skip to content

Instantly share code, notes, and snippets.

function WhiteNoise(audioContext) {
this.node = audioContext.createBufferSource();
var bufferSize = 2 * audioContext.sampleRate,
buffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate),
data = buffer.getChannelData(0);
for (var i = 0, len = data.length; i < len; i++) {
data[i] = Math.random() * 2 - 1;
}
@toruta39
toruta39 / _tinyMPA.js
Last active August 29, 2015 13:55
Tiny MPA (Multipage Page Application) Framework
(function(global) {
function App () {
this.controllers = {};
this.modules = {};
this.router = new Router(this);
$(window).on('load', this.init.bind(this));
};
@toruta39
toruta39 / matchIrregularChar.py
Created January 31, 2014 01:54
Match irregular characters (such as greek, asian characters)
str = "ありがとう"
result = re.search(r"[^\x00-\x7F]", str)
if result:
print(result.start()) # 0
@toruta39
toruta39 / createAndDownloadABlob.js
Last active December 31, 2015 14:39
Create and download a blob in JS. Tested on the latest Chrome stable
var output = {someKey: "someValue"};
var blob = new Blob([JSON.stringify(output)], {type: 'application/json'});
var anchor = document.createElement('a');
anchor.setAttribute('href', window.URL.createObjectURL(blob));
anchor.setAttribute('download', 'data' + Date.now() + '.json');
anchor.click();
@toruta39
toruta39 / perlin.coffee
Created October 30, 2013 02:01
Perlin library, arranged on the base of http://jsdo.it/edo_m18/juzx
do (win = window, doc = window.document, exports = window) ->
floor = Math.floor
class Xorshift
vec: [ 1812433254, 3713160357, 3109174145, 64984499 ]
constructor: (seed = +new Date)->
x = 123456789
y = 362436069
z = 521288629
@toruta39
toruta39 / promise.coffee
Created October 24, 2013 01:12
Promise pattern
class Promise
then: (@onResolved, @onRejected) ->
return
resolve: (val) ->
@onResolved val
return
reject: (err) ->
@onRejected err
@toruta39
toruta39 / _mixin.scss
Created October 1, 2013 09:47
SCSS Helpers
/* Mixin */
@mixin media($point) {
@if $point == papa-bear {
@media (max-width: 1600px) { @content; }
}
@else if $point == mama-bear {
@media (max-width: 1250px) { @content; }
}
@else if $point == baby-bear {
bl_info = {
"name": "My Custom Menu",
"category": "3D View",
"author": "Joshua Zhang"
}
import bpy
# Define a custom menu
@toruta39
toruta39 / normalizeRAF.js
Last active December 22, 2015 00:18
Normalize requestAnimationFrame
// Normalize requestAnimationFrame
var fps = 30;
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
return setTimeout(callback, 1000 / fps);
};
var cancelAnimationFrame = window.cancelAnimationFrame ||
@toruta39
toruta39 / getDataURLfromSVG.js
Created May 8, 2013 08:05
Get DataURL from SVG Element, supported on Chrome, Firefox, Opera, IE10+. stringencoders is needed on IE9-.
function getDataURLfromSVG (svg) {
var code = (new XMLSerializer).serializeToString(svg);
var b64 = window.btoa(unescape(encodeURIComponent(code))); // Workaround on UTF-8 char
return "data:image/svg+xml;base64," + b64;
}