Skip to content

Instantly share code, notes, and snippets.

View teramako's full-sized avatar

teramako teramako

View GitHub Profile
@teramako
teramako / chperm_maker.pl
Last active December 16, 2015 12:08
やっつけコード。与えられたファイルリストから chmod, chown をするコードを吐き出す。
#!/usr/bin/perl
=head1 chperm_maker.pl
与えられたファイルリストのパーミッションを
変更するスクリプトを生成する
=head1 例
$ find . -exec ls -d {} + | perl <this script path>
@teramako
teramako / promise.js
Last active December 16, 2015 11:18
テキトウに Promise 実装。WeakMap とか for-of とか、その他 ECMAScript 6th 機能を使っているので、一般には使えないけど。
/*
* @example 1
* Promise.when(
* asyncFunc1(),
* asyncFunc2()
* ).then(
* function done (p1, p2){ console.log("resolved: ", p1.isResolved, p2.isResolved); },
* function reject(p1, p2){ console.log("rejected: ", p2.isRejected, p2.isRejected); }
* );
* function asycFunc1 () {
@teramako
teramako / setPrototypeOf.js
Created March 19, 2013 05:06
Object.setPrototypeOf の作成。Object.prototype.__proto__ が getter/setter として定義されていないと不可。
/**
* @see https://mail.mozilla.org/pipermail/es-discuss/2013-March/029259.html
*
* @name Object.setPrototypeOf
* @function
* @param {Object} aTarget
* @param {Object} aPrototype
*/
(function() {
var protoDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
@teramako
teramako / WeakSet.js
Last active December 15, 2015 02:28
WeakReference な Set オブジェクトを無理やり作ってみた。Firefox のSystem権限(Components.utils.getWeakReferenceを使用)が必要だけど。
(function(global) {
function mixin (aTarget, aSource) {
for (var key of Object.getOwnPropertyNames(aSource)) {
var desc = Object.getOwnPropertyDescriptor(aSource, key);
desc.enumerable = false;
Object.defineProperty(aTarget, key, desc);
}
return aTarget;
}
@teramako
teramako / flowjs_test.html
Created March 13, 2013 09:04
Flow.js のテスト
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>flow.js Test</title>
<script src="flow.js"></script>
<style>
#outSection {
width: 40%;
float: left;
@teramako
teramako / webcomponents.md
Last active December 14, 2015 21:09
WebComponents の CustomElements の要素名は "x-" で始まるべきか。

#WebComponents

Mozillaが先日WebComponents系のdocument.registerを[Bug783129]で実装した。 使用するには、about:config 等から dom.webcomponents.enabledtrue にする必要がある。

##カスタム要素は "x-" から始まっているべきか

テストコードを書いていて気付いたのだが、Mozillaの実装では document.registerの第一引数のタグ名が x- から始まっていないと InvalidCharacterError の例外が発生する。実際にコードもそのものずばりで書かれてある。

しかし、[CustomElements]、custom element nameの項を見ると、以下のように書かれており、-(ハイフン)は必要だと書いているが x- である必要性は説いていない。

@teramako
teramako / fx_cookie.md
Last active December 14, 2015 09:09
Firefox の Cookie 周りの設定について
@teramako
teramako / httpstatus.js
Last active December 14, 2015 00:59
[Vimperator]httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! 一般的な Web Programmer ならば、HTTP Status code はすべて暗記していると聞きました。 しかし、僕はWeb Programmerではないので、なかなか覚えきれていないので、HTTPのステータスコードをさがすのに便利なツールを用意しました。
/**
* @see http://blog.64p.org/entry/2013/02/21/121830
* @see http://mattn.kaoriya.net/software/vim/20130221123856.htm
* @see http://yuroyoro.hatenablog.com/entry/2013/02/21/144004
* @see http://ymotongpoo.hatenablog.com/entry/2013/02/21/160646
* @see http://d.hatena.ne.jp/syohex/20130221/1361423585
* @see http://blog.livedoor.jp/dankogai/archives/51855038.html
* @see http://d.hatena.ne.jp/hasegawayosuke/20130221
* @see https://gist.github.com/tk0miya/5002917
* @see http://app2641.hatenablog.com/entry/2013/02/21/161928
@teramako
teramako / uniqArray.js
Last active December 13, 2015 20:28
Uniqな配列的オブジェクト。 Setオブジェクトを使ってる。Arrayの操作に加えて、UniqArray#has による存在真偽は Array#indexOf よりかなり高速なはず(参照: http://jsperf.com/array-indexof-vs-set-has )
/**
* @class UniqArray {{{1
* @constructor
* @extends Array
*/
function UniqArray(list = []) {
Object.defineProperty(this, "__set__", { value: new Set(list) });
list = [...this.__set__];
var len = list.length;
for (let i = 0; i < len; ++i) {
@teramako
teramako / getJSEngine.js
Created February 13, 2013 12:53
またしても、しょうもないJavaScriptEngine 判定を書いてしまった。
function getJSengine() {
if (typeof __proto__ === "undefined")
return "JScript(IE)";
switch (String(__proto__)) {
case "[xpconnect wrapped native prototype]":
return "SpiderMonkey(Firefox)";
case "[object Object]":
switch (__proto__.constructor.name) {
case "Object":