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 |
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
# create user | |
adduser gitrepo | |
usermod -aG gitrepo akirattii | |
# create remote git repos | |
su - gitrepo | |
mkdir hoge.git | |
cd hoge.git # pwd: `foo_server:/home/gitrepo/hoge.git/` | |
git --bare init --shared | |
git update-server-info |
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
## Install browserify: | |
$ npm install -g browserify | |
# Install uglify-js: | |
### First remove already installed one: | |
$ npm remove uglify-js -g | |
### Install the ES2015 compatible version from 'harmony' branch: | |
$ npm install -g https://github.com/mishoo/UglifyJS2.git#harmony | |
# Try uglify of ES2015 code: |
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
// Load elements having `id` attr on `document` as global variables (in directly under `window`) | |
// They are loaded as jQuery object named as camelcase with prefix "$". | |
// eg. An element is loaded as a variable named like this: id="ipt-name" -> `$iptName` | |
exports.loadElements = function() { | |
console.log(`[${moduleName}] auto-loading elements as jQuery elements...`); | |
check(); | |
let els = document.getElementsByTagName("*"); | |
let el, camelId, varname; |
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
// fire `hoge` event. | |
window.dispatchEvent(new Event('hoge')); | |
window.addEventListener('hoge', function(e) { | |
// callbacked on `hoge` event fired. | |
console.log('"hoge" event fired.'); | |
}); |