February 2012
1 post
oclint-xcode
#!/bin/bash
LANGUAGE=objective-c
ARCH=armv7
SYSROOT=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
CLANG_INCLUDE=/usr/lib/clang/3.0/include
FRAMEWORKS=''
if [ $# -ne 2 ]; then
printf "\033[1musage:\033[22m `basename "$0"` /path/to/project MyApp-Prefix.pch \n"
exit 1
fi
PROJECT_PATH="$1"
PCH_PATH="$2"
INCLUDES=''
for folder in `find "$PROJECT_PATH" -type d`
do
...
January 2012
3 posts
xcode のプロジェクト設定で Other Linker Flags を 下記のように書き換えればシミュレータでも正常に動かすことができます。 (実機・シミュレータ確認済み)
修正前: -weak_library /usr/lib/libSystem.B.dylib
修正後: -weak-lSystem /usr/lib/libSystem.B.dylib
UIView debug
- (NSString *)recursiveDescription;
- (NSDictionary *)scriptingInfoWithChildren;
@implementation UIView (Debug)
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
BOOL pointInside = CGRectContainsPoint(self.bounds, point);
if (pointInside) NSLog(@"%@", self);
return pointInside;
}
@end
jshint config
{
"curly": true, // curly braces around all blocks should be required
"noempty": true, // empty blocks should be disallowed
"newcap": true, // constructor names must be capitalized
"eqeqeq": true, // if === should be required
"eqnull": true, // if == null comparisons should be tolerated
"es5": true, // Allow ecma5
"undef": true, // if variables should be declared before...
December 2011
3 posts
SSL NSURLRequest
@interface NSURLRequest(SSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host;
@end
@implementation NSURLRequest(SSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host {
// do some filter based off of "host" here
return YES;
}
@end
uiwebview debug
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
:
:
[NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)];
:
:
}
safari
http://localhost:9999
uiview dump
NSLog(@"%@", [view performSelector:@selector(recursiveDescription)]);
November 2011
2 posts
javascript inherits
function inherit(C, P) {
var F = function () {};
F.prototype = P.prototype;
C.prototype = new F();
C.uber = P.prototype;
C.prototype.constructor = C;
}
// test
function Parent() {}
function Child() {}
inherit(Child, Parent);
// testing the waters
var kid = new Child();
kid.constructor.name; // "Child"
kid.constructor === Parent; // false
mac sed
$ grep -rl hoge *|xargs -I@ sed -i "" "s/hoge/fuga/g" @
October 2011
1 post
postfix REDIRECT
/etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks
/etc/postfix/header_checks
/^To:.*@debian.local/ OK
/^To:.*/ REDIRECT myuser@debian.local
/^To:.*/ REJECT myuser
/^Cc:.*/ REJECT myuser
/^Bcc:.*/ REJECT myuser
September 2011
3 posts
1 tag
.vimrc
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif
syntax on
set number
set tabstop=2
set expandtab
set autoindent
set ignorecase
set hlsearch
bash dirname
#!/bin/bash
echo $(cd $(dirname $0);pwd)
ssh-agent
$ cat ~/.ssh/config
--------------------
Host myserver
ForwardAgent yes
HostName 192.168.1.1
User myuser
IdentityFile ~/.ssh/myuser.key
--------------------
$ eval `ssh-agent`
$ ssh-add ~/.ssh/myuser.key
$ slogin myserver
August 2011
4 posts
inotifywait
$ sudo aptitude install inotify-tools
#!/bin/bash
ROOTDIR=/path/to/dir
inotifywait -qrm --format "%T %e %w%f" --timefmt "%Y-%m-%d %H:%M" -e modify -e attrib -e move -e create -e delete $ROOTDIR | while read line; do
echo $line
done
git rm
削除したファイルをgit rmするコマンド
git ls-files --deleted | xargs git rm
–
gitweb.cgi で日本語 (Shift_JIS) の文字化け回避
to_utf8 という関数があるのですが、ここを以下のようにすると
日本語が文字化けしなくなるはずです。
Perl は長らく書いてないので正直適当です。
sub to_utf8 {
my $str = shift;
return undef unless defined $str;
my $enc = guess_encoding($str, qw/shiftjis/);
if (ref $enc && $enc->name eq "shiftjis")...
–
関数の循環的複雑度
次に,関数の簡潔さ/複雑さを測定するにはどのようにしたらよいでしょうか。簡潔に記述された関数は,十分な命名と抽象化がなされていることが多く,読みやすく改修しやすいものになります。関数の簡潔さ/複雑さを測定する指標の一つに,ロジックの循環的複雑度(Cyclomatic Complexity)というものがあります。
まず単一の関数の循環的複雑度(M)は,次の式によって得られます。
M=E-N+2P
E:グラフのエッジ(関数内の処理のブロックをつなぐ線)数
N:グラフのノード(関数内の処理のブロック)数
P:連結されたグラフの数
...
July 2011
2 posts
1 tag
git remote tips
■pushして追跡
git push -u origin hoge
■チェックアウトして追跡
git checkout -t origin/hoge
■リモードブランチ削除
git push origin :hoge
■削除されたリモートブランチを解除
git remote prune origin --dry-run
bookmarklet
bookmark hatena
June 2011
1 post
mkpasswd
$ sudo aptitude install libstring-mkpasswd-perl
$ mkpasswd.pl --help
Usage: mkpasswd.pl [-options]
-l # | --length=# length of password (default = 9)
-d # | --digits=# min # of digits (default = 2)
-c # | --lower=# min # of lowercase chars (default = 2)
-C # | --upper=# min # of uppercase chars (default = 2)
-s # | --special=# min # of special chars (default = 1)
...
skipfish
$ ./skipfish -W /dev/null -LV -g 1 -d 3 -o log/ http://localhost/
May 2011
4 posts
parrallel
$ parallel -u ssh {} 'tail -f hoge' ::: host1 host2
symfony sfValidatorError
// sfValidatorErrorSchema でラッピング
throw new sfValidatorErrorSchema($validator, array(
'field_name' => new sfValidatorError($validator, 'invalid'),
));
ctags for sakura editor
■定数なし
ctags -a -R --langmap=PHP:.php.inc --php-types=c+f -n
■定数含む
ctags -a -R --langmap=PHP:.php.inc --php-types=c+f+d -n
April 2011
4 posts
capistrano stream
require 'capistrano_colors'
## settings
default_run_options[:pty] = true
default_user = "myuser"
set :user, default_user
set :password, "mypass"
## roles
role :local, "localhost"
## tasks
desc "sudoid"
task :sudoid do
run "#{sudo :as => "www"} id"
end
task :svnup do
run "#{sudo :as => "www"} /home/www/bin/svnup.sh" do |channel, stream, data|
if data=~ /\(p\)ermanently\?/
...
SVN: SSL handshake failed
$ svn co --username=xx https:/yy zz
“SSL handshake failed: Secure connection truncated”
$ sudo apt-get install libneon27
$ cd /usr/lib/
$ sudo rm libneon-gnutls.so.27
$ sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27
mysql drop table
SET FOREIGN_KEY_CHECKS = 0;
1 tag
phpmd
$ sudo pear upgrade PEAR
$ sudo pear channel-discover pear.phpmd.org
$ sudo pear channel-discover pear.pdepend.org
$ sudo pear install --alldeps phpmd/PHP_PMD
$ phpmd /path/to/project text codesize,unusedcode,naming
March 2011
1 post
1 tag
mysql pager
mysql> \P less -S
PAGER set to 'less -S'
mysql> select * from user;
mysql> \P grep test | less -S
PAGER set to 'grep test | less -S'
mysql> select * from user;
mysql> \P cat > ~/dump.txt
PAGER set to 'cat > ~/dump.txt'
mysql> select * from user;
$ mysql --pager='less -S' -uroot -p
February 2011
2 posts
1 tag
apache memory check
#!/bin/sh
for i in `pgrep apache2`;
do
cat /proc/$i/status|grep VmHWM;
#cat /proc/$i/status|egrep '(^Pid:|VmHWM)';
done
1 tag
logresolve
logresolve -c < access_log > resolve.log
January 2011
12 posts
1 tag
slow-log
[mysqld]
#slow_query_log=1 # <- 不要?
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 0.1
log-queries-not-using-indexes
1 tag
.gitconfig
[user]
name = myname
email = myname@example.com
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
[color]
ui = true
1 tag
favicon
AddType image/vnd.microsoft.icon .ico
1 tag
getty (ubuntu)
# vi /etc/default/console-setup
-----
#ACTIVE_CONSOLES="/dev/tty[1-6]"
ACTIVE_CONSOLES="/dev/tty[1-2]"
-----
# vi /etc/init/tty[3-6].conf
-----
## comment out all line
-----
2 tags
sshd_config
/etc/ssh/sshd_config
Port 10022
## ipv6無効時は 0.0.0.0 のコメント解除
#ListenAddress ::
ListenAddress 0.0.0.0
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
PubkeyAuthentication yes
UsePAM no
1 tag
javascript Template
var Template = {};
Template.apply = function(str, obj, replacement) {
return str.replace(/#\{(.+?)\}/g, function() {
try {
return eval('obj.' + arguments[1]);
}
catch (e) {
return replacement ? replacement : '';
};
});
};
1 tag
.zshrc
export LANG=ja_JP.UTF-8
autoload -U compinit
compinit
setopt auto_pushd
setopt noautoremoveslash
autoload colors
colors
PROMPT="%{${fg[blue]}%}[%n@%m] %(!.#.$) %{${reset_color}%}"
PROMPT2="%{${fg[blue]}%}%_> %{${reset_color}%}"
SPROMPT="%{${fg[red]}%}correct: %R -> %r [nyae]?...
2 tags
github ssh/config
http://help.github.com/multiple-keys/
$ vi ~/.ssh/config
-----
Host github.com
HostName github.com
User git
IdentityFile /Users/joe/.ssh/id_rsa
-----
1 tag
find | xargs
find . -type d -name .svn -print0 | xargs -0 rm -rf
1 tag
disable ipv6 (ubuntu)
$ sudo vi /etc/sysctl.conf
-----
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
-----
$ sudo sysctl -p
1 tag
node-dev
https://github.com/fgnass/node-dev
Node-dev is a supervisor for Node.js that spawns a node child-process and restarts it when changes are detected in the filesystem.
$ npm install node-dev
$ node-dev script.js
1 tag
TerminalColors
SIMBLE
http://www.culater.net/software/SIMBL/SIMBL.php
TerminalColors
https://github.com/brodie/terminalcolours/downloads
$ mkdir ~/Library/Application\ Support/SIMBL
$ mkdir ~/Library/Application\ Support/SIMBL/Plugins
$ mv TerminalColours.bundle ~/Library/Application\ Support/SIMBL/Plugins/
December 2010
7 posts
1 tag
finder(mac)
$ defaults write com.apple.finder AppleShowAllFiles true
$ defaults write com.apple.desktopservices DSDontWriteNetworkStores true
$ killall Finder
1 tag
ruby rvm
$ sudo apt-get install ruby rubygems
$ sudo gem install rvm
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
$ vi ~/.bash_profile
-----
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
-----
$ rvm install 1.9.2
$ rvm use 1.9.2 --default
$ gem install rails
1 tag
nvm
$ sudo apt-get install build-essential libssl-dev pkg-config git-core
$ git clone git://github.com/creationix/nvm.git ~/.nvm
$ . ~/.nvm/nvm.sh
$ nvm install v0.3.3
$ nvm use v0.3.3
$ vi .bash_profile
-----
. ~/.nvm/nvm.sh
nvm use v0.3.3
-----
1 tag
BASIC AUTH
AuthUserFile /path/to/.htpasswd
AuthGroupFile /dev/null
AuthName "Secret Area"
AuthType Basic
require valid-user
<Files ~ "^.(htpasswd|htaccess)$">
deny from all
</Files>
2 tags
awkで後ろから数える
$ awk '{print $(NF - 1)}' hoge.tsv
2 tags
$ seq 1 10
for i in `seq 1 10`; do
echo "${i}"
done
2 tags
$ arp -a
? (192.168.0.4) at xx:xx:xx:xx:xx:xx on en1 ifscope [ethernet]
? (192.168.0.6) at xx:xx:xx:xx:xx:xx on en1 ifscope [ethernet]
? (192.168.0.8) at xx:xx:xx:xx:xx:xx on en1 ifscope [ethernet]
? (192.168.0.255) at ff:ff:ff:ff:ff:ff on en1 ifscope [ethernet]