This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* dl an external image resource and append it as an img element into the rootEl | |
* | |
* @param {String} | |
* image resource's url | |
* @param {Element} Optional | |
* root element to be appended an img element. | |
* @param {Function} Optional | |
* callback function. 'function(imgEl){...}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// manifest.json | |
/* | |
... | |
"permissions": [ | |
"*://*.amazon.co.jp/*", | |
"*://*.amazon.com/*" | |
or | |
"<all_urls>" | |
], | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// buf is ArrayBuffer | |
function ab2str(buf) { | |
return td.decode(new Uint8Array(buf)); | |
} | |
function ab2dom(buf) { | |
let html = ab2str(buf); | |
let rootEl = document.createElement('html'); | |
rootEl.innerHTML = html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First, | |
// $ git clone https://github.com/kzahel/web-server-chrome.git | |
// $ ./minimize.sh | |
// and ... | |
// load wsc-chrome.min.js in your html | |
function request(url, headers, cb) { | |
let xhr = new WSC.ChromeSocketXMLHttpRequest; | |
let headersLen = headers.length; | |
let k, v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var reg = new RegExp(/e(.*?)e/g); | |
var result; | |
while((result = reg.exec(targetText)) !== null) { | |
doSomethingWith(result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* File Manager for Chrome apps | |
*/ | |
var fileManager = function() { | |
/** | |
* write a file using opendir dialog interactively. | |
* @param {String} filename | |
* @param {String} text to output into the file | |
* @param {Function} callback(function(err, fileEntry){...}) Optional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ループ内の非同期なfunctionからループ実行のタイミングを制御して、処理全体を同期っぽく動かす方法。 | |
// この方法なら setInterval を使ったループよりも効率的。 | |
var arr = ["a", "b", "c"]; | |
var iter = function* () { | |
let i = 0; | |
let lastIdx = arr.length - 1; | |
while (true) { | |
console.log("Before yeild"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moment = require('moment-timezone'); | |
// All timezone? See: node_modules/moment-timezone/data/meta/latest.json | |
let d = moment().tz('Asia/Tokyo').format(); // 2016-10-27T07:31:29+09:00 | |
// let d = moment("2016-09-15 23:59:59").tz('America/Phoenix').format(); // 2016-09-15T07:59:59-07:00 | |
// let d = moment().tz('America/Phoenix').format(); // 2016-10-26T15:31:16-07:00 | |
console.log(d); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Usage: | |
# ### Connect: | |
# $ ./mobile-internet up | |
# ### Disconnect: | |
# $ ./mobile-internet down | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Device E3:28:E9:21:61:5E TaoTronics TT-BH07 | |
mac="E3:28:E9:21:61:5E" | |
devname="TaoTronics TT-BH07" | |
# このshを使う前にあらかじめペアリングしておく: | |
# $ bluetoothctl | |
# ... | |
# [NEW] Device E3:28:E9:21:61:5E TaoTronics TT-BH07 |