Using Git With Multiple SSH Keys and Accounts

Generating SSH keys for GitHub Here are github account and work account. GitHub: SSH Key: github_id_rsa Account: oopsmonk Work: SSH Key: work_id_rsa Account: SamChen Add SSH config File Modify ~/.ssh/config # Default github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_id_rsa # Work git server Host work.gitserver.com HostName work.gitserver.com PreferredAuthentications publickey IdentityFile ~/.ssh/work_id_rsa Git Repository Configuation GitHub Project: $ git clone https://github.com/abc/projectA.git $ cd projectA #github account $ git config user.name "oopsmonk" $ git config user.email "oopsmonk@example.com.tw" Working Project: $ git clone https://work.com.tw/repo/projectW.git $ cd projectW #working account $ git config user.name "SamChen" $ git config user.email "SamChen@example.com.tw" Now you can deal with git repositories using different accounts. ...

December 12, 2014 · 1 min · oopsmonk

pyenv Quick Start (Utunbu 14.04)

installation Requirements $ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm install pyenv $ cd ~ $ git clone git://github.com/yyuu/pyenv.git .pyenv $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc install pyenv-virtualenv $ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv $ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc $ exec $SHELL Common Usage (Command Reference) List all available versions $ pyenv version -l Install python2.7.8 to pyenv $ pyenv install 2.7.8 List installed versions $ pyenv versions * system (set by /home/oopsmonk/.pyenv/version) 2.7.8 3.4.2 Creating a virtualenv $ pyenv virtualenv 2.7.8 mypy-2.7.8 List virtualenvs $ pyenv virtualenvs mypy-2.7.8 (created from /home/oopsmonk/.pyenv/versions/2.7.8) mypy-3.4.2 (created from /home/oopsmonk/.pyenv/versions/3.4.2) # current versions $ pyenv versions * system (set by /home/oopsmonk/.pyenv/version) 2.7.8 3.4.2 mypy-2.7.8 mypy-3.4.2 Use python via virtualenv # show current version oopsmonk@VBox:~/markdown-note$ python --version Python 2.7.6 # Change to other version oopsmonk@VBox:~/markdown-note$ pyenv activate mypy-2.7.8 (mypy-2.7.8)oopsmonk@VBox:~/markdown-note$ python --version Python 2.7.8 # Deactivate (mypy-2.7.8)oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 2.7.8 # Why current version is 2.7.8? it's supposed to 2.7.6. oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv activate mypy-3.4.2 (mypy-3.4.2) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv versions system 2.7.8 3.4.2 mypy-2.7.8 * mypy-3.4.2 (set by PYENV_VERSION environment variable) # delete a virtualenv $ pyenv uninstall mypy-2.7.8 # Go back to original system version $ alias pyenv_deactivate='pyenv deactivate && unset PYENV_VERSION' oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv activate mypy-3.4.2 (mypy-3.4.2) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv_deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 2.7.6 Use python via pyenv # Global python version $ pyenv global # python version in current folder oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv local mypy-3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by /home/oopsmonk/markdown-note/.python-version) oopsmonk@oopsmonk-VBox:~/markdown-note$ cd .. oopsmonk@oopsmonk-VBox:~$ pyenv version system (set by /home/oopsmonk/.pyenv/version) oopsmonk@oopsmonk-VBox:~$ cd - /home/oopsmonk/markdown-note oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by /home/oopsmonk/markdown-note/.python-version) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv local --unset oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version system (set by /home/oopsmonk/.pyenv/version) # python version in current shell oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv shell mypy-3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by PYENV_VERSION environment variable) oopsmonk@oopsmonk-VBox:~/markdown-note$ cd - /home/oopsmonk oopsmonk@oopsmonk-VBox:~$ pyenv version mypy-3.4.2 (set by PYENV_VERSION environment variable) oopsmonk@oopsmonk-VBox:~$ pyenv shell --unset oopsmonk@oopsmonk-VBox:~$ pyenv version system (set by /home/oopsmonk/.pyenv/version) oopsmonk@oopsmonk-VBox:~$ cd - /home/oopsmonk/markdown-note oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version system (set by /home/oopsmonk/.pyenv/version)

December 10, 2014 · 2 min · oopsmonk

Bash Quick Reference

Advanced Bash-Scripting Guide sed awk Internal Variables #current parent pid $$ #last background process pid $! #last exit status $? #current instance pid, Bash 4.x above. $BASHPID Arithmetic Expansion a=12 b=$(($a + 10)) b=`expr $a + 1` b=$(expr $a + 1) let b=$a+3 #let b=$a + 3 #incorrect let "b = $a + 3" declare -i b=$a+$a Manipulating Strings String is a number if [[ $var =~ ^-?[0-9]+$ ]]; then echo "$var is a number" fi if [[ ! $var =~ ^-?[0-9]+$ ]]; then echo "$var is not a number" fi Find String between two words or characters var="Hello there are (123340) and (123)" #last string between '(' and ')'. substr=$( echo $var | sed 's/.*(\(.*\)).*/\1/' ) #String between '(' and ')'. substr=$( echo $var | awk -v FS="(\(|\))" '{print $2 " " $4}' ) #String between 'there' and 'and'. substr=$( echo $var | awk -v FS="(there|and)" '{print $2}' ) #String between 'there' and 'and'. substr=$( echo $var | sed 's/.*there\(.*\)and.*/\1/' ) #String between 'there' and 'and'. substr=$( echo $var | grep -o -P '(?<=there).*(?=and)' ) Loop read variables #read from file echo "123, abc, hello world!" > /tmp/test echo "12 43, ddd, !" >> /tmp/test while IFS=',' read var1 var2 var3 do echo "var1=$var1 var2=$var2 var3=$var3" done < "/tmp/test" #read from variable x="one, two, three" while IFS=',' read var1 var2 var3 do echo "var1=$var1 var2=$var2 var3=$var3" done <<< $x iterate IP address #iterate class C ip address for i in 192.168.100.{1..10} do echo "$i" done #iterate class B ip address for x in 192.168.{1..5} do for i in $x.{1..10} do echo "$i" done done infinite while loop while : do echo "infinite loops [ CTRL+C to stop]" sleep 5 done Array # Simple array arrayA=( Mon Tue Wed Thu Fri Sat Sun ) echo "${!arrayA[*]}" # 0 1 2 3 4 5 6 echo "${#arrayA[*]}" # 7 echo "${arrayA[*]}" # Mon Tue Wed Thu Fri Sat Sun echo "${!arrayA[@]}" # 0 1 2 3 4 5 6 echo "${#arrayA[@]}" # 7 echo "${arrayA[@]}" # Mon Tue Wed Thu Fri Sat Sun echo "${arrayA[2]}" # Wed echo "$arrayA" # Mon echo "${arrayA[20]}" # null arrayA=( one two ) echo "${arrayA[*]}" # one two arrayA+=( three "four" ) echo "${arrayA[*]}" # one two three four # Key/Value declare -A arrayB=( ["Mon"]="Monday" ["Tue"]="Tuesday" ["Wed"]="Wednesday" ["Thu"]="Thursday" ["Fri"]="Friday" ["Sat"]="Saturday" ["Sun"]="Sunday" ) echo "${!arrayB[*]}" # Thu Tue Wed Mon Fri Sat Sun echo "${#arrayB[*]}" # 7 echo "${arrayB[*]}" # Thursday Tuesday Wednesday Monday Friday Saturday Sunday echo "${!arrayB[@]}" # Thu Tue Wed Mon Fri Sat Sun echo "${#arrayB[@]}" # 7 echo "${arrayB[@]}" # Thursday Tuesday Wednesday Monday Friday Saturday Sunday echo "${arrayB[2]}" # null echo "$arrayB" # null echo "${arrayB["Tue"]}" # Tuesday declare -A arrayB=( ["one"]=1 ["two"]="2" ) echo "${!arrayB[*]}" # one two echo "${arrayB[*]}" # 1 2 arrayB+=( ["three"]="3" ["four"]=4 ) echo "${!arrayB[*]}" # four one two three echo "${arrayB[*]}" # 4 1 2 3 arrayB+=( ["four"]="aa" ["five"]="5a1c" ) echo "${!arrayB[*]}" # four one five two three echo "${arrayB[*]}" # 4aa 1 5a1c 2 3 I/O redirection Forking Processes pid_perfix="/tmp/proc-" function doSomething(){ local pid_file="$pid_perfix$BASHPID" echo "this is task $1 : $pid_file " > $pid_file sleep 5 } w_pid="" for task in {1..5} do doSomething $task & w_pid+="$! " sleep 1 done for p in $w_pid do wait $p done #clean up for p in $w_pid do #del pid file rm "$pid_perfix$p" done exit 0

December 4, 2014 · 3 min · oopsmonk

Raspberry Pi Monitor

Use RRDTool monitor Raspberry Pi, include CPU temperture, Memory usage, Disk I/O, Network I/O… Install install packages $sudo apt-get install libcairo2-dev libpango1.0-dev libglib2.0-dev libxml2-dev \ librrd-dev python2.7-dev rrdtool python-rrdtool $wget https://pypi.python.org/packages/source/p/psutil/psutil-2.1.1.tar.gz $tar xf psutil-2.1.1.tar.gz $cd psutil-2.1.1 $sudo python setup.py install Download or clone rpi-monitor on github https://github.com/oopsmonk/rpi-monitor Setup Crontab By defualt, the cron.log is disabled in Raspbian. To enable it: sudo vi /etc/rsyslog.conf find the line and uncomment it. # cron.* /var/log/cron.log Restart rsyslog via: ...

July 21, 2014 · 1 min · oopsmonk

Baking 2013

起司麵包 綜合麵包 平底鍋做麵包 戚風蛋糕 香蕉核桃馬芬蛋糕 鮭魚炒飯

December 31, 2013 · 1 min · oopsmonk

GitHub SVN Upstream (on Ubuntu12.04)

This is a git tutorial, create svn upstream on GitHub. Use MOC project as a example. #Checkout SVN and push to GitHub. Install packages $ sudo apt-get install subversion git-svn Create git repository (it will take a long time) $ git svn clone svn://daper.net/moc/trunk --no-metadata ./moc-svn-git $ cat moc-svn-git/.git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [svn-remote "svn"] noMetadata = 1 url = svn://daper.net/moc/trunk fetch = :refs/remotes/git-svn Update SVN repository ...

August 26, 2013 · 2 min · oopsmonk

Building MOC

clone MOC svn repository to github Ref: Converting a Subversion repository to Git $ sudo apt-get install subversion git-svn $ mkdir moc-svn $ cd moc-svn $ svn co svn://daper.net/moc/trunk $ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt $ cd .. $ mkdir moc-git $ git svn clone svn://daper.net/moc/trunk --no-metadata -A ./moc-svn/authors-transform.txt ./moc-git $ cd moc-git $ git svn show-ignore > .gitignore $ git add -f .gitignore $ git commit -m "Convert svn:ignore to .gitignore." $ mkdir ../moc-bare $ git clone --bare ../moc-bare $ cd ../moc-bare/moc-git.git #Create empty repository on GitHub. $ git push --mirror https://github.com/oopsmonk/moc-git.git install develop package for MOC (Ubuntu) $ sudo apt-get install build-essential libdb-dev gettext Optional libraries: Sound driver: ALSA - libasound2-dev JACK - libjack-dev Decoder: FLAC - libflac-dev MP3 - libmad0-dev, libid3tag0-dev sndfile, vorbis - libsndfile1-dev Network: libcurl4-gnutls-dev RCC: librcc-dev Resample : libsamplerate0-dev MIME magic: libmagic-dev After release 2.5 MOC will require libpopt. $ sudo apt-get install libasound2-dev libjack-dev \ libflac-dev libmad0-dev libid3tag0-dev libsndfile1-dev $ sudo apt-get install libcurl4-gnutls-dev librcc-dev \ libsamplerate0-dev libmagic-dev libpopt ----------------------------------------------------------------------- MOC will be compiled with: Decoder plugins: flac mp3 sndfile vorbis Sound Drivers: OSS ALSA JACK DEBUG: yes RCC: yes Network streams: yes Resampling: yes MIME magic: yes ----------------------------------------------------------------------- install develop package for MOC (Raspberry Pi) $ sudo apt-get install build-essential autoconf automake libtool $ sudo apt-get install libncurses5-dev libdb-dev gettext $ sudo apt-get install libasound2-dev libjack-dev libflac-dev \ libmad0-dev libid3tag0-dev libsndfile1-dev $ sudo apt-get install libcurl4-gnutls-dev librcc-dev libsamplerate0-dev libmagic-dev Build libpopt $ wget http://rpm5.org/files/popt/popt-1.16.tar.gz $ tar xf popt-1.16.tar.gz $ cd popt-1.16 $ autoreconf $ ./configure --prefix=/usr/lib --enable-shared $ make $ sudo make install check out from repository $ svn co svn://daper.net/moc/trunk moc-svn Build step $ cd moc-svn $ autoreconf $ ./configure --enable-debug --perfix=/path/to/dev $ make && make install Debugging $cd /path/to/dev $ ./bin/mocp --debug

August 23, 2013 · 2 min · oopsmonk