Skip to content

Instantly share code, notes, and snippets.

@koki-h
koki-h / nesstedDictionary.mm
Created May 11, 2017 05:39
ネストした辞書から値(int)の読み出し(Obj-C)
- (int) hls_param_get:(NSDictionary*) param key:(NSString*)key min_max:(int) min_max
{
NSArray *a = [param objectForKey:key];
NSNumber *nsnumber = (NSNumber*)a[min_max];
NSInteger value = [nsnumber integerValue];
return (int)value;
}
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@[@0,@15], @"HRange",
@koki-h
koki-h / ruby-onelliner.sh
Last active December 4, 2016 05:54
ファイルaaaから1,8カラム目を取り出し、1カラム目をキーとして同じキーを持つデータを横で持つようにするワンライナー
cut -f1,8 aaa | ruby -na -e 'require "pp";BEGIN{h={}}; h[$F[0]] ||= [];h[$F[0]] << $F[1]; END{pp h}'
@koki-h
koki-h / exec_all.sh
Created June 14, 2016 02:01
カレントディレクトリのファイル名全てをコマンドに食わせる(1ファイル1実行)
find * | xargs -n1 {command}
@koki-h
koki-h / remove_special_char.rb
Last active December 21, 2015 07:43
俺が分かる範囲ですべての全角/半角記号を除去(UTF8 とりあえずエラーにならない)
require 'nkf'
string = NKF::nkf( '-WwZ0', string ) #全角記号を半角に変換しておく
string.gsub!(/[\s\!\"\#\$\%\&\'\(\)\-\=\^\~\\\|\@\`\[\]\{\}\;\:\+\*\<\>\,\.\/\?\_]/,"") #とりあえず全部エスケープしたがわけがわからん。。
#差出人が自分の場合はSubjectにマークを付ける。
myaddress=`pwd | cut -d/ -f5` #自分のメールアドレス
if ( /^From:\s*(.*)${myaddress}@example.com/)
{
mark=`echo '[送信メール]' | nkf -jM`
xfilter "sed -e 's|^Subject: |Subject: $mark |' "
}
cc "[email protected]"
@koki-h
koki-h / .mailfilter
Last active December 18, 2015 04:58
自分から届いたメールを.Sentディレクトリに自動的に移動する
#差出人が自分の場合は送信済みフォルダにメールを移動する
myaddress=`pwd | cut -d/ -f5` #自分のメールアドレス
if ( /^From:\s*(.*)${myaddress}@example.com/) #この例では自ドメインはexample.comとする
{
to "maildir/.Sent/"
}
@koki-h
koki-h / avoid_dup_run2.sh
Created November 30, 2015 12:46
2重起動させないための起動スクリプト(pgrepを使う版)
#!/bin/bash
if [ $$ -ne $(pgrep -fo "$0") ]; then
echo "実行中。2重起動を禁止しています。"
exit 1
fi
trap 'kill $(jobs -p);echo 強制終了されました。' EXIT
#処理本体
@koki-h
koki-h / avoid_dup_run.sh
Last active November 30, 2015 12:45
2重起動させないための起動スクリプト
#!/bin/bash
SCRIPT_DIR=$(cd $(dirname $0);pwd) #スクリプトのフルパス
LOCK_FILE="$SCRIPT_DIR/lock.pid"
if [ -e $LOCK_FILE ]; then
#ロックファイルが存在する場合は何もしない
echo "実行中。2重起動を禁止しています。"
else
#ロックファイルがあれば作って処理を起動
echo $$ > $LOCK_FILE #とりあえずプロセスIDを書き込んでおく
@koki-h
koki-h / git-exec-ruby.sh
Last active November 23, 2015 01:16
WEB上のソースコードのURLを指定して実行
#!/bin/bash
curl $1 | ruby
# How to use
# $ ./git-exec-ruby.sh https://gist.githubusercontent.com/koki-h/9e004e2d683ec31fe00a/raw/2da2caf0b1ed6b69b0f396a2ee0389882ebb4841/sample.rb
#こういうの↓を実行するとき便利
# https://github.com/mame/trance-book
@koki-h
koki-h / mws.rb
Last active November 19, 2015 06:43
MWSのサンプルコードをオブジェクト指向っぽくしてみた。
# -*- encoding: utf-8 -*-
# Original code is http://aws.typepad.com/jp_mws/2012/12/amazon-mws-ruby-sample.html
require 'uri'
require 'time'
require 'openssl'
require 'base64'
require "net/https"
require "pp"
require 'active_support'