Skip to content

Instantly share code, notes, and snippets.

View narusemotoki's full-sized avatar

Motoki Naruse narusemotoki

View GitHub Profile
@narusemotoki
narusemotoki / gengitignore.py
Created November 11, 2012 09:17
.gitignoreを生成する
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def android():
"""
Android用のgitignoreを書き込みます.
"""
ignore = """bin/
gen/
@narusemotoki
narusemotoki / putgitignore.py
Created November 11, 2012 09:59
GitHubから各環境用の.gitignoreを取得して書き出します
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import urllib2
def write(ignore):
"""
引数を.gitignoreに書き込みます.
"""
f = open(".gitignore", "w")
@narusemotoki
narusemotoki / DatabaseUtil.java
Created November 13, 2012 15:08
Androidのassetsからデータベースをコピーする
/**
* assetsからデータベースをコピーするためのユーティリティクラス
*
* @author motoki
*/
public class DatabaseUtil {
/**
* コピーを実行する
*
* @param context
@narusemotoki
narusemotoki / androidscreenshot.sh
Created February 7, 2013 02:24
Androidのスクリーンショットを撮影してパソコンのホームディレクトリに保存するシェルスクリプト。 adbの用意が必要です。 スクリーンショットのファイル名はscreen_shot_{timestamp}.png。 Ubuntuで動作確認しています。Macは動くだろうけどWindowsは動かないと思う。 Cygwinなら動くのかな? ICS以上じゃないと動かないかも。
#!/bin/sh
TIMESTAMP=`date +'%s'`$(printf '%03d' $(expr `date +%N` / 1000000))
SCREEN_SHOT_NAME=screen_shot_${TIMESTAMP}.png
adb shell /system/bin/screencap -p /sdcard/${SCREEN_SHOT_NAME}
adb pull /sdcard/${SCREEN_SHOT_NAME} ~/${SCREEN_SHOT_NAME}
adb shell rm /sdcard/${SCREEN_SHOT_NAME}
@narusemotoki
narusemotoki / randomfile.sh
Created February 14, 2013 08:25
dirに入ったパスのファイルをランダムに一個出力します。
#!/bin/sh
dir='/home/motoki/Documents'
file_count=`ls ${dir} | wc -l`
random=`od -vAn -N4 -tu4 < /dev/random`
rnum=$(( ${random} % $file_count ))
count=0
for f in `ls ${dir}`; do
if [ "${rnum}" -eq "${count}" ]; then
@narusemotoki
narusemotoki / Main.java
Last active December 14, 2015 02:09
JavaのgetCanonicalName()、getName()、getSimpleName()が外部クラス、外部クラス内匿名クラス、内部クラス、内部クラス内匿名クラスでそれぞれどういう値を返すのかを調べました。
package ho.ge;
/*
結果
Main
Canonical: ho.ge.Main
Name: ho.ge.Main
Simple: Main
-----
Annoymous
@narusemotoki
narusemotoki / screenpwd.sh
Last active December 14, 2015 02:19
screen(byobu)で新しいwindowを作って、それを行ったwindowでいたディレクトリに移動します。
#! /bin/sh
CURRENT=`pwd`
screen
cd ${CURRENT}
@narusemotoki
narusemotoki / gistsearch.py
Last active December 14, 2015 16:19
自分のGistを検索できないらしいので、ユーザ名とdescriptionに含まれていて欲しい文字列を引数で渡すと、引っかかったGistのdescriptionとURLを出力するスクリプト書いた。 指定したユーザのGistを全て持ってきてからdescriptionの中を見ていくので遅い。しかもすぐにAPI上限に届いてしまう。 $ python gistsearch narusemotoki python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from urllib import urlopen
import json
import sys
base_url = 'https://api.github.com/users/{username}/gists?page='
def fetch(username):
def fetch(page):
@narusemotoki
narusemotoki / angular_study.coffee
Last active December 14, 2015 23:49
スマートフォンなどでJavaScriptのクリックイベントが遅れるのを解消する(AngularJS) nd-click="hoge($event)"としても、hogeの中で$eventを取得できません。
angular.module('AngularStudy', []).directive 'ndClick', => ($scope, $element, $attrs) =>
isTap = isTapped = false
$element.bind 'click', => $scope.$apply $attrs['ndClick'] unless isTapped
$element.bind 'touchstart', => isTap = true
$element.bind 'touchmove', => isTap = false
$element.bind 'touchend', => if isTap
isTapped = true
$scope.$apply $attrs['ndClick'], $element
@narusemotoki
narusemotoki / .zshrc
Created May 23, 2013 05:37
zshでタイムスタンプを表示するコマンド。.zshrcに追記して設定を読みなおしてから「$ timestamp」
timestamp() {
printf '%ld\n' $(expr `date +%s%N` / 1000000)
}