Skip to content

Instantly share code, notes, and snippets.

@monjudoh
monjudoh / supports.js
Created April 4, 2013 11:55
現在の環境でstructured cloneで渡せるもの渡せないものを調べる
(function (global) {
var supports = Object.create(null);
(function __BlobUrls() {
// URLにベンダプレフィクスが付いているのはwebkitだけ!!
var URL = global.URL || global.webkitURL;
supports.BlobUrls = URL !== undefined && URL.createObjectURL;
})();
(function __MessageChannel() {
supports.MessageChannel = !!global['MessageChannel'];
})();
@monjudoh
monjudoh / gist:3909563
Created October 18, 2012 02:37
Transferablesサポートチェック
// 参考
// http://updates.html5rocks.com/2011/12/Transferable-Objects-Lightning-Fast
// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string
var isSupportTransferables = (function () {
var global = window;
// URLにベンダプレフィクスが付いているのはwebkitだけ!!
var URL = global.URL || global.webkitURL;
var supportsBlobUrls = URL !== undefined && URL.createObjectURL;
// Transferablesの方がBlobURLよりサポートが遅いし、BlobURLsを使わないと外部JSなしでworkerを作れないのでこうしている
if (!supportsBlobUrls) {
@monjudoh
monjudoh / classbox.js
Created September 11, 2012 05:18
classboxよく分かってないんだけどJavaScriptでやるとこんな感じ?__proto__のsetを使っているので標準準拠で実装できません。
var classbox = (function () {
var proto = Array.prototype;
var proto2 = Object.create(Object.getPrototypeOf(proto));
Object.getOwnPropertyNames(proto).forEach(function(propName){
var desc = Object.getOwnPropertyDescriptor(proto,propName);
Object.defineProperty(proto2,propName,desc);
});
proto2.first = function first() {
return this[0];
@monjudoh
monjudoh / gist:3303195
Created August 9, 2012 10:44
JSでFizzBuzz。剰余と一切の条件分岐を無くしたよ。さらに、元々ループと再帰はなかったけど、反復メソッドも(見かけ上)なくしたよ。
fizzArray = [];
buzzArray = [];
new Array(101).join('a').replace(/a/g,function(n,i){
fizzArray = fizzArray.concat(['','','Fizz']);
buzzArray = buzzArray.concat(['','','','','Buzz']);
var result = (fizzArray[i]+buzzArray[i]).replace(/^$/,i + 1);
return result + '\n';
});
@monjudoh
monjudoh / fizzbuzz.js
Created August 7, 2012 05:28
FizzBuzzを久々に素直に書いたら長くなった
Array.apply(null,new Array(101))
.map(function(n,i){ return '';})
.map(function(n,i){ return n+(i % 3 ? '' : 'Fizz');})
.map(function(n,i){ return n+(i % 5 ? '' : 'Buzz');})
.map(function(n,i){ return n ? n : i;})
.slice(1,101)
@monjudoh
monjudoh / canvas.html
Created December 12, 2011 07:38 — forked from moriyoshi/canvas.html
canvas
<html>
<body>
<canvas id="test" width="320" height="320"></canvas>
<script type="text/javascript">
(function() {
var proto = document.createElement('canvas').getContext('2d').constructor.prototype;
var x = proto.fillText;
proto.fillText = function fillText(text) {
if (proto.fillText !== fillText) {
proto.fillText = fillText;
@monjudoh
monjudoh / gist:909813
Created April 8, 2011 13:20
JavaScriptのobject・arrayからObjective-CのNSDictionary,NSArrayのコード生成
function stringToNSString(str) {
return ['@"',str,'"'].join('');
}
function numberToNSNumber(num) {
return ['[NSNumber numberWithLong:',num,']'].join('');
}
function booleanToNSNumber(bool) {
return ['[NSNumber numberWithBool:',(bool ? 'YES' : 'NO'),']'].join('');
}
@monjudoh
monjudoh / underscore.interval-iterator.js
Created February 7, 2011 07:54
長時間かかる反復メソッド(each,map,reduce等)の実行をtimerで飛ばしながら休み休み行うUnderscore.js用mixin
/*
* Underscore.js plugin
* http://documentcloud.github.com/underscore/
*/
(function(){
var root = this;
var console = root.console;
var optionsTable = {};
var setResultTable = {};
var lib = {};
@monjudoh
monjudoh / gist:765881
Created January 5, 2011 03:17
IE(主に6,7)で「操作は中断されました」エラーが出るヶ所でstackTraceをalertで出す。これに依存→ https://github.com/emwendelin/javascript-stacktrace
(function(){
var domManip = jQuery.fn.domManip;
jQuery.fn.domManip = function(){
if(!jQuery.isReady && !!this.closest('body').size() ) {
var msg = printStackTrace().join('\n');
alert(msg);
throw new Error();
}
return domManip.apply(this,arguments);
}
use JSTAPd::Suite;
sub tests { 11 }
sub include {
(
# /Users/monjudoh/Sites/callendar-demo/js/config-require.js
'/js/config-require.js',
'/js/allplugins-require.js',
);
}