Skip to content

Instantly share code, notes, and snippets.

function clearLocalStorage() {
var len = window.localStorage.length;
while (len >= 0) {
window.localStorage.removeItem(window.localStorage.key(len--));
}
}
@toruta39
toruta39 / StepAction.coffee
Last active December 16, 2015 00:59
StepAction helps to get rid of nesting setTimeout
# StepAction helps to get rid of nesting setTimeout
#
# Function.prototype.bind feature is used.
# Only support IE9+ for now
class StepAction
constructor: (@steps, @initDelay) ->
@_timer = null
@_onStep = 0
@toruta39
toruta39 / base64.html
Created May 7, 2013 08:25
Conditional comment for supporting `window.btoa` and `window.atob` on *lte IE 9*
<!--[if lte IE 9]>
<script src="https://stringencoders.googlecode.com/svn/trunk/javascript/base64.js"></script>
<script>
if (!window.btoa) window.btoa = base64.encode;
if (!window.atob) window.atob = base64.decode;
</script>
<![endif]-->
-- Switch to English (Run in CLI)
-- defaults write NSGlobalDomain AppleLanguages "(en, ja, \"zh-Hans\", \"zh-Hant\", fr, de, es, it, pt, \"pt-PT\", nl, sv, nb, da, fi, ru, pl, ko, ar, cs, hu, tr, th, ca, hr, el, he, ro, sk, uk)"
-- Switch to Japanese (Run in CLI)
-- defaults write NSGlobalDomain AppleLanguages "(ja, en, \"zh-Hans\", \"zh-Hant\", fr, de, es, it, pt, \"pt-PT\", nl, sv, nb, da, fi, ru, pl, ko, ar, cs, hu, tr, th, ca, hr, el, he, ro, sk, uk)"
@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;
}
@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 ||
bl_info = {
"name": "My Custom Menu",
"category": "3D View",
"author": "Joshua Zhang"
}
import bpy
# Define a custom menu
@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 {
@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 / 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