Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / _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));
};
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;
}
function BrownNoise(audioContext) {
this.node = audioContext.createBufferSource();
var bufferSize = 2 * audioContext.sampleRate,
buffer = audioContext.createBuffer(1, bufferSize, audioContext.sampleRate),
data = buffer.getChannelData(0);
lastOutput = 0;
for (var i = 0, len = data.length; i < len; i++) {
var white = Math.random() * 2 - 1;
function randomRGB() {
const c = 0xffffff * Math.random();
return [c >> 16, c >> 8 & 255, c & 255];
}
@toruta39
toruta39 / sortPoints.js
Created October 16, 2015 09:51
Solve z-buffer problem of transparent Points by sorting depth of vertices on each draw
// https://github.com/mrdoob/three.js/commit/8406cd7c6ecbdaca8e9d985158e5403492da48b5
import THREE from 'three';
export default function sortPoints(points, camera) {
var vector = new THREE.Vector3();
// Model View Projection matrix
var matrix = new THREE.Matrix4();
matrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
let rules = [];
function appendRule(path, callback) {
rules.push([path, callback]);
}
function matchPath(path, currentPath) {
let params = {};
// If there's a '/' in the end of path, trim it.
@mixin e($element) {
@at-root {
#{&}__#{$element} {
@content;
}
}
}
@mixin m($modifier) {
@at-root {
@toruta39
toruta39 / co-test.js
Created February 23, 2016 01:43
Learning co
var co = require('co');
co(function* () {
var result = 0;
result = yield Promise.resolve(1);
console.log(result); // 1
result = yield Promise.resolve(result + 1);
console.log(result); // 2
return 3;
}).then(function(res) {