Last active
March 27, 2017 08:43
-
-
Save hackugyo/6d148596c0f305b7d97d to your computer and use it in GitHub Desktop.
snippets
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/sh | |
# Pythonのpercolを使って,シェルスクリプトを簡単に選択する方法を作った | |
set -e # stop when an error happens | |
# set -x # show commands in strderr before execute it | |
# sed '/^$/d 空行削除 | |
# sed '1d' 先頭行だけ空行なのになぜか残ってしまうのでこれも削除 | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| while read line; | |
do | |
echo "execute for " ${line}; | |
adb -s ${line} $@; | |
echo ""; | |
done; |
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 | |
# originally from http://stackoverflow.com/a/12914297/2338047 | |
REQUIRED_ARGS=4 | |
ADB_PATH=/Users/kwatanabe/android-sdks/platform-tools/adb | |
PULL_DIR=`pwd`/ | |
if [ $# -ne $REQUIRED_ARGS ] | |
then | |
echo "" | |
echo "Usage:" | |
echo "android_db_move.sh [package_name] [dir_name] [db_name] [e|d]" | |
echo "eg. android_db_move.sh lt.appcamp.impuls databases impuls.db d # for one real device" | |
echo "eg. android_db_move.sh lt.appcamp.impuls databases impuls.db e # for one emulator" | |
echo "" | |
exit 1 | |
fi; | |
echo"" | |
cmd1="$ADB_PATH -$4 shell 'run-as $1 cat /data/data/$1/$2/$3 > /sdcard/$3' " | |
cmd2="$ADB_PATH pull /sdcard/$3 $PULL_DIR" | |
cmd3="$ADB_PATH -$4 shell 'rm /sdcard/$3' " | |
echo $cmd1 | |
eval $cmd1 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd2 | |
eval $cmd2 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd3 | |
eval $cmd3 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
exit 0 | |
# http://stackoverflow.com/a/22751947/2338047 | |
#cat <<EOF | adb shell | |
#run-as jp.eplus.android.all.app.staging | |
#cd databases | |
#cat eplus.db > /mnt/sdcard/eplus.db | |
#exit | |
#exit | |
#EOF | |
#adb pull /mnt/sdcard/eplus.db ~/Documents/eplus/eplus_new.db | |
# コピーされたdbを削除 | |
#cat <<EOF | adb shell | |
#rm /mnt/sdcard/eplus.db | |
#exit | |
#EOF |
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 | |
set -e # stop when an error happens | |
PACKAGE_NAME="$1" | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| while read line; | |
do | |
echo "execute for " ${line}; | |
echo ${PACKAGE_NAME}; | |
adb -s ${line} shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:${PACKAGE_NAME} | |
done; |
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
adb shell 'pm list packages -f'| sed -e 's/.*=//' | |
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 | |
# adb devices を選んで返します | |
# | |
# adb_peco | adb -s ${パイプされた標準入力} shell 'pm list packages -f' | |
# みたいなことをしたいが,標準入力を-sに渡すのが難しすぎる | |
# | |
# adb-pecoは動かなかった | |
# https://github.com/tomorrowkey/adb-peco/blob/master/bin/adb_peco.sh | |
# readで代入した変数は別のプロセスからは参照できない | |
# http://labs.timedia.co.jp/2011/09/shell-read-pipe-and-environment-variables.html | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| percol #\ | |
#| while read -r deviceId; do echo $deviceId; done | |
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 | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| percol \ | |
| xargs -I % adb -s % shell pm list packages -f \ | |
| percol \ | |
| sed -e 's/^package://g' \ | |
| sed -e 's/\.apk=.*/.apk/g' \ | |
| xargs -I % adb pull %; | |
ls -tdF *.apk | head -n 1 | sed -e "s% %\\\ %g" |
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 | |
# adb devices を選んで返します | |
# | |
# adb_peco | adb -s ${パイプされた標準入力} shell 'pm list packages -f' | |
# みたいなことをしたいが,標準入力を-sに渡すのが難しすぎる | |
# | |
# adb-pecoは動かなかった | |
# https://github.com/tomorrowkey/adb-peco/blob/master/bin/adb_peco.sh | |
# readで代入した変数は別のプロセスからは参照できない | |
# http://labs.timedia.co.jp/2011/09/shell-read-pipe-and-environment-variables.html | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| percol \ | |
| xargs -I % adb -s % shell pm list package \ | |
| percol \ | |
| sed -e 's/^package://g' |
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 | |
# originally from http://stackoverflow.com/a/12914297/2338047 | |
REQUIRED_ARGS=3 | |
ADB_PATH=/Users/kwatanabe/android-sdks/platform-tools/adb | |
PULL_DIR=`pwd`/ | |
if [ $# -ne $REQUIRED_ARGS ] | |
then | |
echo "" | |
echo "Usage:" | |
echo "adb_push_android_db.sh [package_name] [db_name] [e|d]" | |
echo "eg. adb_push_android_db.sh lt.appcamp.impuls impuls.db d # for one real device" | |
echo "eg. adb_push_android_db.sh lt.appcamp.impuls impuls.db e # for one emulator" | |
echo "" | |
exit 1 | |
fi; | |
echo"" | |
cmd1="$ADB_PATH push $2 /sdcard/$2" | |
cmd2="$ADB_PATH -$3 shell 'run-as $1 cat /sdcard/$2 > /data/data/$1/databases/$2' " | |
cmd3="$ADB_PATH -$3 shell 'rm /sdcard/$2' " | |
echo $cmd1 | |
eval $cmd1 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd2 | |
eval $cmd2 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd3 | |
eval $cmd3 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
exit 0 | |
# http://stackoverflow.com/a/22751947/2338047 | |
#cat <<EOF | adb shell | |
#run-as jp.eplus.android.all.app.staging | |
#cd databases | |
#cat eplus.db > /mnt/sdcard/eplus.db | |
#exit | |
#exit | |
#EOF | |
#adb pull /mnt/sdcard/eplus.db ~/Documents/eplus/eplus_new.db | |
# コピーされたdbを削除 | |
#cat <<EOF | adb shell | |
#rm /mnt/sdcard/eplus.db | |
#exit | |
#EOF |
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 | |
set -e # stop when an error happens | |
DATE=`date +$@` | |
if [ $# -ne 1 ]; then | |
DATE=`date +"%Y%m%d_%H%M%S_%s"` | |
fi | |
FILENAME="s_${DATE}" | |
echo "capturing ${FILENAME}_*.png..." | |
adb devices \ | |
| sed -e "s/device//" \ | |
| sed '/^$/d' \ | |
| sed '1d' \ | |
| while read line; | |
do | |
echo "execute for " ${line}; | |
FILENAME_INNER="${FILENAME}_${line/:/_COLON_}.png"; | |
adb -s ${line} shell screencap -p "/sdcard/${FILENAME_INNER}"; | |
adb -s ${line} pull "/sdcard/${FILENAME_INNER}"; | |
adb -s ${line} shell rm "/sdcard/${FILENAME_INNER}" | |
echo ""; | |
done; | |
echo "saved ${FILENAME}_*.png." |
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
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSUInteger UIInterfaceOrientationMaskPortrait = 1 << 0; | |
NSUInteger UIInterfaceOrientationMaskPortrait2 = 1 << 1; | |
NSUInteger i = UIInterfaceOrientationMaskPortrait2 & UIInterfaceOrientationMaskPortrait; | |
NSLog(@"useData %d", UIInterfaceOrientationMaskPortrait); | |
NSLog(@"useData %d", i); | |
} | |
} |
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
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSString *str = [[NSString alloc] initWithData:nil encoding:NSShiftJISStringEncoding]; | |
NSData *useData = [str dataUsingEncoding:NSUTF8StringEncoding]; | |
NSLog(@"use Data exist? %d %d", useData != nil, YES); | |
NSLog(@"useData %@", [useData description]); | |
NSLog(@"useData length: %@", [[useData length] stringValue]); // [useData length] だとNSUIntegerになって0のときうまくlongとして表示できない | |
NSLog(@"useData length: %d", (int)[useData length]); | |
} | |
} |
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 | |
# originally from http://stackoverflow.com/a/12914297/2338047 | |
REQUIRED_ARGS=3 | |
ADB_PATH=/Users/kwatanabe/android-sdks/platform-tools/adb | |
PULL_DIR=`pwd`/ | |
if [ $# -ne $REQUIRED_ARGS ] | |
then | |
echo "" | |
echo "Usage:" | |
echo "android_db_move.sh [package_name] [db_name] [e|d]" | |
echo "eg. android_db_move.sh lt.appcamp.impuls impuls.db d # for one real device" | |
echo "eg. android_db_move.sh lt.appcamp.impuls impuls.db e # for one emulator" | |
echo "" | |
exit 1 | |
fi; | |
echo"" | |
cmd1="$ADB_PATH -$3 shell 'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2' " | |
cmd2="$ADB_PATH pull /sdcard/$2 $PULL_DIR" | |
cmd3="$ADB_PATH -$3 shell 'rm /sdcard/$2' " | |
echo $cmd1 | |
eval $cmd1 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd2 | |
eval $cmd2 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd3 | |
eval $cmd3 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
exit 0 | |
# http://stackoverflow.com/a/22751947/2338047 | |
#cat <<EOF | adb shell | |
#run-as jp.eplus.android.all.app.staging | |
#cd databases | |
#cat eplus.db > /mnt/sdcard/eplus.db | |
#exit | |
#exit | |
#EOF | |
#adb pull /mnt/sdcard/eplus.db ~/Documents/eplus/eplus_new.db | |
# コピーされたdbを削除 | |
#cat <<EOF | adb shell | |
#rm /mnt/sdcard/eplus.db | |
#exit | |
#EOF |
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 | |
# originally from http://stackoverflow.com/a/12914297/2338047 | |
REQUIRED_ARGS=3 | |
ADB_PATH=/Users/kwatanabe/android-sdks/platform-tools/adb | |
PULL_DIR=`pwd`/ | |
if [ $# -ne $REQUIRED_ARGS ] | |
then | |
echo "" | |
echo "Usage:" | |
echo "android_file_move.sh [package_name] [db_name] [e|d]" | |
echo "eg. android_file_move.sh lt.appcamp.impuls impuls.db d # for one real device" | |
echo "eg. android_file_move.sh lt.appcamp.impuls impuls.db e # for one emulator" | |
echo "" | |
exit 1 | |
fi; | |
echo"" | |
cmd1="$ADB_PATH -$3 shell 'run-as $1 cat /data/data/$1/files/$2 > /sdcard/$2' " | |
cmd2="$ADB_PATH pull /sdcard/$2 $PULL_DIR" | |
cmd3="$ADB_PATH -$3 shell 'rm /sdcard/$2' " | |
echo $cmd1 | |
eval $cmd1 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd2 | |
eval $cmd2 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
echo $cmd3 | |
eval $cmd3 | |
if [ $? -eq 0 ] | |
then | |
echo ".........OK" | |
fi; | |
exit 0 | |
# http://stackoverflow.com/a/22751947/2338047 | |
#cat <<EOF | adb shell | |
#run-as jp.eplus.android.all.app.staging | |
#cd databases | |
#cat eplus.db > /mnt/sdcard/eplus.db | |
#exit | |
#exit | |
#EOF | |
#adb pull /mnt/sdcard/eplus.db ~/Documents/eplus/eplus_new.db | |
# コピーされたdbを削除 | |
#cat <<EOF | adb shell | |
#rm /mnt/sdcard/eplus.db | |
#exit | |
#EOF |
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 | |
# http://qiita.com/GeneralD/items/a4af8d1ac2b13a8c0bc8 | |
# Decompile Java classes recursively keeping hierarchy | |
jadr() { | |
jad -8 -s java -d $2 -r $1/**/*.class | |
} | |
# Decompile Android application | |
#deapk(file) { | |
# local dst=${PWD} | |
dst=${PWD} | |
dst=${dst}'/.depackaged' | |
echo $dst | |
echo $0 | |
echo $1 | |
echo $file | |
unzip -q $1 -d $dst | |
dex2jar ${dst}/classes.dex | |
unzip -q ${dst}/classes_dex2jar.jar -d ${dst}/Classes | |
jadr ${dst} ${dst}/src > ${dst}/log 2> ${dst}/errorlog | |
#} | |
#deapk |
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 | |
# 文字列に含まれる半角スペースをエスケープします | |
if [ -p /dev/stdin ]; then | |
sed -e "s% %\\\ %g" | |
exit 0 | |
else | |
echo 1>&2 "No args"; | |
exit 1 | |
fi |
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 | |
set -euxC # stop when an error happens | |
DATE=`date +$@` | |
if [ $# -ne 1 ]; then | |
DATE=`date +"%Y%m%d_%H%M%S_%s"` | |
fi | |
FILENAME="s_${DATE}" | |
echo "capturing ${FILENAME}_*.tiff..." | |
idevice_id -l \ | |
| while read line;\ | |
do | |
echo "execute for " ${line}; | |
FILENAME_INNER="${FILENAME}_${line}"; | |
idevicescreenshot -u ${line}; | |
mv *.tiff ${FILENAME_INNER}.tiff; | |
sips -s format png ${FILENAME_INNER}.tiff --out ${FILENAME_INNER}.png; | |
rm ${FILENAME_INNER}.tiff; | |
done; | |
echo "saved ${FILENAME}_*.png." | |
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 | |
# Simulatorからスクリーンショットをとると落ちるのでコマンドラインから叩く | |
set -euxC # stop when an error happens | |
# http://qiita.com/m-yamashita/items/889c116b92dc0bf4ea7d | |
DATE=`date +$@` | |
if [ $# -ne 1 ]; then | |
DATE=`date +"%Y%m%d_%H%M%S_%s"` | |
fi | |
FILENAME="s_${DATE}" | |
echo "capturing ${FILENAME}_*.png..." | |
xcrun simctl io booted screenshot ${FILENAME}.png | |
echo "saved ${FILENAME}.png." |
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/sh | |
# Pythonのpercolを使って,シェルスクリプトを簡単に選択する方法を作った | |
set -e # stop when an error happens | |
set -x # show commands in strderr before execute it | |
# ヒアドキュメントをパイプする際は,ヒアドキュメントの1行めでパイプする | |
cat <<'__EOT__' | percol | sh -x | |
ruby -i -pe '$_.gsub!(",","\t")' # ファイル名を指定すると,中のカンマをタブに置換してファイル上書き | |
ruby -r active_support/core_ext -nle 'puts %q(m) + $_.downcase.camelize' # ファイル名を指定すると,大文字スネークケース(定数)をメンバ変数に変換 | |
ruby -r active_support/core_ext -lne 'puts $_ + %Q( = "#{$_}")' # ファイル名を指定すると,変数名 = "変数名"の形に変換 | |
ruby -r active_support/core_ext -nle 'puts %Q(m#{$_.downcase.camelize} = cursor.get(#{$_}))' # ファイル名を指定すると,メンバ変数 = curosr.get(定数)の形に変換 | |
ruby -r active_support/core_ext -nle 'puts %Q(cursor.set(#{$_}, m#{$_.downcase.camelize}))' # ファイル名を指定すると,cursor.set(定数, メンバ変数)の形に変換 | |
ruby -e '60.downto(0) do |i| puts "#{i} "+"|"*i; sleep 1 end; `say 終了`' # 60秒後にMacが「終了」としゃべる | |
ruby -run -e httpd . -p 8000 & # 8000番ポートでWebrickサーバを立てる | |
(ps a | grep ruby | percol | cat) # rubyプロセスをkill -9するためのPIDを探る. | |
cat <<EOF > file.txt" # file.txtを作成し,数行の文字列を入力する.ここからは実行できない | |
echo "lsnewest ~/Desktop/ | xargs -J% mv % ./" # デスクトップの最新のファイルを移動させる | |
dscl localhost -list /Local/Default/Users #ユーザの一覧を表示 | |
git grep -n -e SEARCH_WORD #SERACH_WORDでディレクトリ内を検索 | |
git grep -l -e SEARCH_WORD #SERACH_WORDでディレクトリ内を検索してファイル名だけ表示 | |
git ls-files --stage | grep 160000 # submoduleを一覧表示する | |
git log -1 --format='%cI' # 最新のpull日時を調べる | |
git log --all -- path/to/your/file # 対象のパスのファイルがコミットされた履歴を表示 | |
git add -p # Gitで部分的にコミットする.y,n,eが使えればOK | |
echo 'seq -f "201303%02g.rst" 31 | xargs touch' #create_serial_files | |
echo 'for F in btn_z01_*; do mv $F ${F/z01/new};done' | |
echo "find . -type f -iname 'btn_cancel_*.png' -print0 | xargs -0 rename 's/.png/_off.png/i'" #置換 | |
echo 'aapt dump badging' # apkファイル名を指定するとパッケージ情報がダンプされる | |
echo 'appinfo' # パッケージ名を指定すると設定画面を起動する | |
echo 'find ./ -name NAME | percol | xargs git log --follow' #見つけたファイルをリネーム追跡しつつgit logする | |
git rebase -i develop/develop # 現在のブランチを開発ブランチに生やしなおす | |
cat ~/.mysql_history #mysqlのコマンドシェルのログを見る | |
cat export.sql | sed -e 's/.*(\(.*\));/\1/g' | tr -s ',' '\t' | sed -e "s/\\'//g" # LitaでエクスポートしたSQL文をtsvにして吐く | |
terminal-notifier -message hogehoge #Growlふうの通知を出す | |
echo 'count_length $1' #引数として与えた文字列の長さを数える | |
echo 'chmod a+w $1' #引数として与えたファイルを,全ユーザ書き込み可能にする | |
echo 'chmod 755 $1' #引数として与えたファイルを,全ユーザ実行可能にする | |
aapt dump badging *.apk #引数として与えたapkファイルから,パッケージ情報をとる | |
ruby -ne 'puts "<string name=\"#{$_.chomp}\">#{$_.chomp}</string>" if ($_ && $_.chomp.length > 0) ' # 内容と同名のstringを作る | |
adb shell dumpsys alarm # 端末のAlarmManagerの状況を確認する | |
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.DEFAULT --include-stopped-packages # 端末に再起動インテントを送る http://osa030.hatenablog.com/entry/2015/07/16/152713 | |
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png # スクリーンショットを撮影 | |
echo "adb shell input text a@a #端末に文字入力" | |
adb shell dumpsys activity top_ #端末のアクティヴィティ階層を表示 | |
adb pull `adb shell pm list packages -f | sed -e 's/package:\([^=]*\).*/\1/g'|percol` # Android端末からapkファイルをコピーする | |
~/bin/copy_android_db.sh # Android端末から指定パッケージのDBファイルをコピーする | |
./gradlew --stop # Android Studioのgradle実行を止める | |
echo -n "文字列の長さを知る" | wc -c | |
ln -s sourcedir destpath #シンボリックリンクを作成する | |
echo 'readlink $1' # lnで作ったシンボリックリンクの実体パスを調べる | |
keytool -v -list -keystore ~/.android/debug.keystore #キーストアファイルのfingerprintを閲覧.デバグの場合パスワードはandroid | |
bundle install --path vendor/bundler # bundleインストール時はちゃんとパスを切ろう | |
scp -r kwatanabe@remothost:srcdir dstdir #ディレクトリごとscpダウンロード | |
echo "やばい情報" | openssl enc -e -aes-256-cbc -salt -base64 # パスワードを1行で暗号化 | |
echo "U2FsdGVkX18ik3JVgQcV855vDqI1FpD0VjXMVByh8Sc4lBrrJ9ShE9n3xPUaDAqY" | openssl enc -d -aes-256-cbc -salt -base64 # 暗号化したパスワードを複号化 | |
ruby -e 's = "";ARGV[0].split(%q{,}).each{|line| s += %{ + \", #{line} = \" + #{line}}};puts s' # 与えられた変数列をJavaのLogに吐きやすい形に結合 | |
javap -classpath path/to/your/jarfile.jar your.package.YourClass # jarファイルのメソッド一覧を表示する | |
ruby -ne 'puts $_.chomp.gsub(/^\t*/, %{})' #引数で受け取ったファイルの各行から先頭のTabを削除して出力 | |
ruby -e 's = "";open(ARGV[0]).lines.each{|line|result = %{#{line.match(/#{ARGV[1]}=\"(.*?)\"/).to_a[1]}\n};s += result};puts s' # 与えられたxml列の指定attributeを表示 | |
xattr -d com.apple.quarantine $1 # 開発元が未確認のappを開けるようにする | |
tar zxvf $1 # tar.gzの解凍 | |
ruby -e 'puts open(ARGV[0]).read.gsub(/\n/, "").gsub(/<script.*?\/script>/,"")' $1 | ruby -ne 'puts $_.gsub(/<style.*?\/style>/,"")' |sed 's/<[^>]*>//g' # 指定したHTMLファイルの本文だけを抜き出す | |
echo 'mkdir -p $1 && cd $_ ; pwd' # $1のディレクトリを作ってcdする | |
echo 'sips -g pixelWidth -g pixelHeight $1' # $1の画像ファイルの画像サイズを表示 | |
echo 'convert -size $1 xc:white' # $1(1242x2208とか)のサイズの白い画像を作成 | |
echo 'convert $1 -format %c -depth 8 histogram:info:-' #画像のヒストグラム表示 | |
echo 'mobiledevice uninstall_app jp.co.hatena.hackugyo.APNs' #指定したbundle identifierのアプリをiOS端末からアンインストールする | |
instruments -s devices | percol | sed -e "s/.*\[\(.*\)\].*/\1/g" | xargs -I % echo ~/Library/Developer/CoreSimulator/Devices/%/data/Containers/Data/Application/ # iOSのシミュレータをリストアップし,1つを選んでアプリケーションディレクトリに遷移 | |
nkf -w -Lu --overwrite * #kill CRLF and SJIS!! | |
echo "tree | ruby -ne 'puts %Q(#{\$_.encode(%q(UTF-8), %q(UTF-8-MAC))})'" # OSX用のまともなtree | |
(exec 3>&1 ;echo 3 2 1 | tr ' ' '\n' | tee /dev/fd/3 | sort;exec 3>&-) # http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=44341&forum=10 teeを使って,標準入力に出力したあとパイプする | |
echo "echo \`date -j 02252014 '+%a'\`曜日 #日付から曜日を出力。なぜかmmddyyyy以外の入力フォーマットを指定するオプションはない" | |
cat results.txt | sed 's/.*result=\"\([0-9]*\).*/\1/' | xargs | perl -pe "s/ /+/g" | bc # result="100"の数値部分を合計するスクリプト | |
echo "exrex '^(a|b)*$' -r" # 正規表現に当てはまる文字列をランダムに1つ生成する(min_repeatの?は使えないままなので注意) | |
# Webツール | |
open http://smallpdf.com # pdf 縮小 結合 | |
open https://jex.im/regulex/ # 正規表現 視覚化 regex | |
cd ~/Library/Application\ Support/Skype/kwatanabe.kbmj;echo 'select datetime(timestamp,"unixepoch","localtime"), author, body_xml from Messages where chatname="19:e012e76dd9c6436c8d6710ae501a9006@thread.skype";' | sqlite3 ./main.db; | |
cat full.json | jq -cM # jqで長いJSONを1行にして出す&モノクロ化 | |
cat full.json | jq -cM . | sed -e "s/\"/\\\\\"/g" # jqで長いJSONを1行にして出す&モノクロ化&エスケープ | |
cat ~/Library/Application\ Support/Firefox/Profiles/cr0d9ru9.default/sessions/backup.session | sed 1,4d | jq '.windows[0].tabs[].entries[0] |select(.url | startswith("http")) | .url' | xargs open # Firefoxのタブを復帰させる | |
cat ~/Library/Application\ Support/Firefox/Profiles/*.default/sessionstore-backups/recovery.js | jq '.windows[].tabs[].entries[].url' # Firefoxの現在開いているタブの一覧を表示する | |
perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si' # htmlからタイトルを取り出す | |
echo 'a=1,b=2,c=3' | tr ',' '\n' | paste -s -d ',' - # csvを行ごとにし,また戻している | |
ag "sign_in\b" # "sign_in"を引っかけるが"sign_in_and"は引っかけないメタ文字 http://qiita.com/jkr_2255/items/d4305540de50a82cce03 | |
(type oneliners_ruby | sed -e "s/^.*is //" | xargs "${EDITOR}" --no-wait) # edit this file | |
__EOT__ | |
#echo $candidates | percol | sh -x |
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 | |
ruby -rdate -e "exit Date.today.day.even?" && echo "うづら" || echo "うっちー" | |
# http://qiita.com/udzura/items/2afb647fa148ceea7802 |
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
# -*- coding: utf-8 -*- | |
require 'set' | |
require 'pp' | |
module StringUtils | |
def to_snake_case | |
self.gsub(/::/, '/'). | |
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). | |
gsub(/([a-z\d])([A-Z])/,'\1_\2'). | |
tr("-", "_"). | |
downcase | |
end | |
def to_camel | |
self.split(/[_\s]+/).map{|i| | |
a,b,c = i.split(/^(.)/) | |
"#{b.upcase}#{c}" | |
}.join('') | |
end | |
end | |
String.send :include, StringUtils | |
class DB | |
attr_reader :tables, :name | |
def initialize(name, tables) | |
@tables = tables | |
@name = name | |
end | |
def find_similar_table(table) | |
similarities = @tables.map.with_index {|my_table, index| | |
similarity = Float::MAX | |
if (table && my_table) then | |
similarity = (my_table.table_map.size - table.table_map.size).abs | |
end | |
[similarity, index] | |
} | |
index = similarities.sort{|a, b| | |
(a[0] <=> b[0]).nonzero? || (a[1] <=> b[1]) | |
}[0][1] | |
@tables[index] | |
end | |
end | |
class Table | |
attr_reader :table_name, :table_map | |
def initialize(table_name, table_map) | |
@table_name = table_name | |
@table_map = Set.new | |
table_map.split(',').each {|table_key| | |
table_key.gsub!(/^[ ]*/, '').gsub!(/ .*$/, '') | |
@table_map.add(table_key) | |
} | |
@table_map.freeze | |
end | |
end | |
# | |
# 引数として与えられた文字列のSetを比較し, | |
# table_map - other_table_mapの差集合を返します. | |
# このとき,文字列の比較は,snake_case / lowerCamelCase / UpperCamelCase を無視しようとします. | |
# | |
def keep_unknown_columns(table_map, other_table_map) | |
result = table_map.clone | |
result.keep_if {|item| | |
!(other_table_map.include?(item) || | |
other_table_map.include?(item.upcase) || | |
other_table_map.include?(item.downcase) || | |
other_table_map.include?(item.downcase.to_snake_case) || | |
other_table_map.include?(item.downcase.to_camel) || | |
other_table_map.include?(item.downcase.to_camel.gsub(/^([A-Z])/){|head| head.downcase}) || | |
other_table_map.include?(item.to_snake_case.upcase) || | |
other_table_map.include?(item.to_snake_case.upcase.gsub(/_([^_]*)([0-9]+)/, '_\2\1')) || | |
other_table_map.include?(item.to_snake_case.upcase.gsub(/([^_])([0-9]+)/, '\1_\2')) | |
) | |
} | |
result | |
end | |
# main | |
exit if (ARGV.size != 2) | |
dbs = [] | |
ARGV.each do |arg| | |
# まず,文字列をすべて受け取る | |
lines = "" | |
File.open(arg) {|file| | |
file.lines.each {|line| | |
lines += line.chomp.gsub(/^\t*/, %{}) | |
} | |
} | |
# CREATE TABLEはじまりにする | |
tables = lines.split('CREATE TABLE').map {|table| | |
ignore, table_name, table_map = table.match(/(.*)\((.*)\)/).to_a | |
table_name.gsub!(/\"| /, '') if table_name | |
Table.new table_name, table_map if table_name and table_map | |
} | |
dbs << DB.new(arg, tables) | |
end | |
# 差分をとる | |
# でもどうやってとれば?? | |
# keep_ifとかを使おうと思うが,そもそもどのテーブルとどのテーブルとが同じなのかわからない | |
# とりあえず配列の数がいちばん近いやつを探そう! | |
puts dbs[0].name | |
dbs[0].tables.each do |table| | |
next unless table | |
counterpart = dbs[1].find_similar_table(table) | |
puts "*****" | |
puts "#{table.table_name} is similar to #{counterpart.table_name}" | |
table_map = keep_unknown_columns(table.table_map, counterpart.table_map) | |
table_map2 = keep_unknown_columns(counterpart.table_map, table.table_map) | |
if (table.table_map.size - table_map.size <= 1) then | |
puts " ... dissmilar." | |
elsif (table_map.size != 0) then | |
puts " #{table_map.size} columns in #{table.table_map.size}@#{dbs[0].name}, #{counterpart.table_map.size}@{dbs[1].name} (#{table_map.inspect})" | |
else | |
puts " ... indeed they are same!" | |
end | |
end | |
puts "\n *** \n\n" | |
puts dbs[1].name | |
dbs[1].tables.each do |table| | |
next unless table | |
counterpart = dbs[0].find_similar_table(table) | |
puts "*****" | |
puts "#{table.table_name} is similar to #{counterpart.table_name}" | |
table_map = keep_unknown_columns(table.table_map, counterpart.table_map) | |
table_map2 = keep_unknown_columns(counterpart.table_map, table.table_map) | |
if (table.table_map.size - table_map.size <= 1) then | |
puts " ... dissmilar." | |
elsif (table_map.size != 0) then | |
puts " #{table_map.size} columns left in #{table.table_map.size}@#{dbs[0].name}, #{counterpart.table_map.size}@#{dbs[1].name} (#{table_map.inspect})" | |
else | |
puts " ... indeed they are same!" | |
end | |
end | |
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 | |
# ln -s A Bでリンクを作ったとき,Bを食わせるとAを表示する | |
set -e # stop when an error happens | |
ls -l $@; |
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 | |
# パイプされた行を長さでソートします | |
if [ -p /dev/stdin ]; then | |
awk '{print length, "|", $0;}' | sort -n | sed -e 's/^[0-9]* | //g' | |
exit 0 | |
else | |
echo 1>&2 "No args"; | |
exit 1 | |
fi |
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 | |
# tsvのファイル名を受け取って、転置行列にして返します. | |
( if [ -p /dev/stdin ]; then | |
argv=$(cat -); | |
else | |
argv=("$@"); | |
fi; | |
N=$(head -n 1 $argv | wc -w); | |
for i in `seq 1 $N` | |
do | |
awk '{print $'$i'}' < $argv | tr '\n' '\t' ; | |
echo; | |
done) |
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
# treeコマンドはOSXではUTF-8を返さない | |
tree | ruby -ne 'puts %Q(#{$_.encode(%q(UTF-8), %q(UTF-8-MAC))})' |
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/sh | |
# git diffでOfficeファイルの差分を見る | |
# http://qiita.com/shuhei/items/6a18d968051378d7ac1a | |
set -e # stop when an error happens | |
tika -t "$1" |
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 | |
# パイプされた行を長さでソートします | |
if [ -p /dev/stdin ]; then | |
ruby -ne 'puts %Q(#{$_.encode(%q(UTF-8), %q(UTF-8-MAC))})' | |
exit 0 | |
else | |
echo 1>&2 "No args"; | |
exit 1 | |
fi |
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
# -*- coding: utf-8 -*- | |
# 日本語でメンバ変数の名前をつけたあと,それを英語に変換します | |
ruby -nle 'puts %Q(\ | |
#{$_\ | |
#{$_.gsub("private TextView m","/** ").gsub(";", " **/")}\n\ | |
.gsub("日本語変数名", "VariableNameInJapanese")\ | |
.gsub("クリンゴン語変数名", "VariableNameInKlingon")\ | |
})' $1 | |
# gsubの部分をつくるワンライナー | |
# ruby -nle 'puts %Q(#{$_.gsub("private TextView m",".gsub(\"").gsub(";","\", \"\")\\")})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment