memo

.bashrcメモ

# .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias em='emacs' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi PS1="[\u@\h \W]# " if [ -f /etc/bash_completion ];…

Macで複数のバージョンのpythonを使う

python-selectというやつで、簡単にMacでpythonのバージョンを切り替えることができます。インストールはmacportsで。 $ sudo port python-select Pythonのバージョンを切り替えるとき。 $ sudo python_select python25 Password: Selecting version "python…

tarで2G超えファイルの圧縮/伸張を行う

個人的メモ 2G超えファイルの圧縮 $ tar cv test | gzip > test.tar.gz2G超えファイルの伸張 $ cat test.tar.gz | gzip -d | tar xv

vimでomuni補完を行う

個人的メモ autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType css set omnifunc=cssc…

Pythonで長い文字列を記述するときの便利技

丸括弧を使用することで、長い文字列を改行して記述することができる。 カンマを使用しないところに注意。 >>> print ('寿限無、寿限無 ' '五劫の擦り切れ ' '海砂利水魚の ' '水行末 雲来末 風来末 ' '食う寝る処に住む処 ' 'やぶら小路の藪柑子 ' 'パイポ…

pythonでのリストの比較

リストの比較は、要素ごとに比較される。一箇所でも、FalseがあるとFalseが返却されるっぽい。 リストの長さが違っても、OKっぽい。 >>> foo = [1, 2, 3] >>> bar = [1, 2, 4] >>> foo < bar True >>> foo = [1, 2, 3] >>> bar = [1, 3, 2] >>> foo < bar Tr…

pythonでの値の比較とオブジェクトの比較

「==」は値の比較。 「is」はオブジェクトの比較。 >>> foo = 'Boys Be Ambitious' >>> bar = 'Boys Be Ambitious' >>> foo == bar True >>> foo is bar False 短い文字列など、使用頻度の高いオブジェクトは使い回されるので、 「is」での比較は True とな…

pythonのvars()って便利!

vars()は、存在する変数の名前と値を辞書で返す。デバッグに使えそう。 >>> a = 123 >>> b = 456 >>> c = 789 >>> >>> >>> "%(a)s %(b)s" % vars() '123 456'

pythonではNull文字(\0)はただの文字

めもめも。Null文字(\0)は、C言語では、文字列の終端をあらわす。pythonでは、ただの文字。 >>> foo = "a\0b\0c\0" >>> foo 'a\x00b\x00c\x00' >>> len(foo) 6

Pythonの文法と戯れる

pythonの文法の興味深いところをメモってみました。 リストのスライス >>> list = [1, 2, 3, 4, 5] >>> list[1] 2 >>> list[1:] [2, 3, 4, 5] >>> list[1:3] [2, 3] >>> list[:3] [1, 2, 3] >>> list[:] [1, 2, 3, 4, 5] >>> list[-1] 5 >>> list[-2] 4 >>> …