Skip to content

Instantly share code, notes, and snippets.

View narusemotoki's full-sized avatar

Motoki Naruse narusemotoki

View GitHub Profile
#!/bin/bash
cd ~
echo "apt-getを使用するためにパスワードを入力"
sudo apt-get update
sudo apt-get install -y zsh
echo "シェルをzshに変更するためにパスワードを入力"
chsh -s /bin/zsh
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class _Singleton(type):
"""
Python 2.xと3.xの両方をサポートするためには、このように継承しなければならない。
class SubClass(_Singleton('Singleton', (object, ), {})):
pass
@narusemotoki
narusemotoki / gitprepush.sh
Created July 7, 2013 13:59
git push -nを行い、pushするコミットがあった場合いに、それらのログを表示します。 パスの通った場所にgitprepush.shを置き、実行権限を与えてください。 .gitconfigにprepush = "! gitprepush.sh"を書くとgit prepushと利用できるようになります。
#!/bin/sh
# Copyright (c), Naruse Motoki (motoki@naru.se)
# Licensed under The MIT License
dryrun=`git push -n 2>&1`
echo "$dryrun"
fromto=`echo $dryrun | sed -e "s/.* \([0-9a-z]\+\.\.[0-9a-z]\+\) .*/\1/g"`
if expr "$fromto" : "^[0-9a-z]\+\.\.[0-9a-z]\+$" >/dev/null; then
echo "`git log --date=short --pretty=format:"%h %ad %an %s" $fromto`"
fi
@narusemotoki
narusemotoki / gist:5820566
Created June 20, 2013 05:45
シェルスクリプトで線を引く
printf '=%.0s' {1..80}
@narusemotoki
narusemotoki / .zshrc
Created May 23, 2013 05:37
zshでタイムスタンプを表示するコマンド。.zshrcに追記して設定を読みなおしてから「$ timestamp」
timestamp() {
printf '%ld\n' $(expr `date +%s%N` / 1000000)
}
@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 / 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 / screenpwd.sh
Last active December 14, 2015 02:19
screen(byobu)で新しいwindowを作って、それを行ったwindowでいたディレクトリに移動します。
#! /bin/sh
CURRENT=`pwd`
screen
cd ${CURRENT}
@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 / 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