Skip to content

Instantly share code, notes, and snippets.

@naosim
naosim / phaser_rope.js
Last active August 29, 2015 14:27
PhaserでRopeを使うサンプル
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'phaser-area');
var fish;
game.state.add('main', {
preload: function() {
game.stage.backgroundColor = '#ffffdd';
// 魚の画像をロード
game.load.image('fish', '../../common/img/fish.png');
},
create: function() {
var segmentWidth = 400 / 10;
@naosim
naosim / latestlog.md
Created May 15, 2015 03:17
時系列にならんだログファイルから最新を取得するワンライナー
ls /path/to/logs/* -d | tail -n 1

こんな感じで時系列にならんだログファイルから
最新のファイルの絶対パスを取得します。

log20150101.txt
log20150102.txt
@naosim
naosim / fabfile.py
Created May 5, 2015 23:44
Fabricデプロイ
# example
# fab -H [hostname] -u [user] -i [pubkey] deploy:[work dir]
from fabric.api import cd, run
def deploy(dir):
with cd (dir):
run("ls")
run("git pull")
run("npm install")
run("sh stop.sh")
@naosim
naosim / Apache_Lisence_Template.txt
Created April 10, 2015 23:12
Apache Lisence Template
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
var MD5 = function() {
var crypto = require('crypto');
return {
hex: function(src) {
var md5 = crypto.createHash('md5');
md5.update(src, 'utf8');
return md5.digest('hex');
}
};
};
@naosim
naosim / getQuery.js
Created March 29, 2015 14:25
URLからQueryを取得する
var getQuery = function() {
var result = {};
if(location.href.indexOf('?') == -1) return result;
var lastIndex = location.href.indexOf('#') != -1 ? location.href.indexOf('#') : location.href.length;
var kvs = location.href.slice(location.href.indexOf('?') + 1, lastIndex).split('&');
for(var i = 0; i < kvs.length; i++) {
var kv = kvs[i].split('=');
result[kv[0]] = kv[1];
}
return result;
var replaceAll = function(org, before, after){ return org.split(before).join(after); };
@naosim
naosim / zerofill.js
Created March 26, 2015 15:15
ゼロ埋め
var zerofill = function(num, zeros) { return (Array(zeros).join('0') + num).slice(-zeros); };
@naosim
naosim / textload.js
Last active August 29, 2015 14:16
node.jsでパイプと引数でテキストを取得する
var loadFromFile = function(file, callback) {
if(!file || file.trim().length == 0) {
callback('file not found', null);
return;
}
callback(null, ("" + require('fs').readFileSync(file)));
};
var loadFromPipe = function(callback) {
var text = "";
@naosim
naosim / file0.txt
Created February 28, 2015 10:43
HTTPステータスコード表をJSONにしてみた ref: http://qiita.com/naosim_/items/1d17d04df41f29191cc5
{
"100": "Continue",
"101": "Switching Protocols",
"102": "Processing",
"200": "OK",
"201": "Created",
"202": "Accepted",
"203": "Non-Authoritative Information",
"204": "No Content",
"205": "Reset Content",