Skip to content

Instantly share code, notes, and snippets.

@monjudoh
monjudoh / supports.js
Created Apr 4, 2013
現在の環境でstructured cloneで渡せるもの渡せないものを調べる
View supports.js
(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 Oct 18, 2012
Transferablesサポートチェック
View gist:3909563
// 参考
// 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 Sep 11, 2012
classboxよく分かってないんだけどJavaScriptでやるとこんな感じ?__proto__のsetを使っているので標準準拠で実装できません。
View classbox.js
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 Aug 9, 2012
JSでFizzBuzz。剰余と一切の条件分岐を無くしたよ。さらに、元々ループと再帰はなかったけど、反復メソッドも(見かけ上)なくしたよ。
View gist:3303195
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 Aug 7, 2012
FizzBuzzを久々に素直に書いたら長くなった
View fizzbuzz.js
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)
View canvas.html
<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 Apr 8, 2011
JavaScriptのobject・arrayからObjective-CのNSDictionary,NSArrayのコード生成
View gist:909813
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 Feb 7, 2011
長時間かかる反復メソッド(each,map,reduce等)の実行をtimerで飛ばしながら休み休み行うUnderscore.js用mixin
View underscore.interval-iterator.js
/*
* 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 Jan 5, 2011
IE(主に6,7)で「操作は中断されました」エラーが出るヶ所でstackTraceをalertで出す。これに依存→ https://github.com/emwendelin/javascript-stacktrace
View gist:765881
(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);
}
View 01_base.t
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',
);
}
You can’t perform that action at this time.