Tuesday, January 20, 2015

Git cheat sheet


git clone
git branch hotfix@tianli
git checkout hotfix@tianli

modify code

git commit –a

arc diff


git checkout master
git pull

git checkout hotfix@tianli
git rebase master

git checkout master
git merge hotfix@tianli
git push


next round …


Monday, January 19, 2015

Phabricator + Git: a good practice for Scrum

Phabricator can be used to record all the backlogs for your sprint. The most amazing thing is to integrate with Git you can submit your code changes for review whenever you like.

Monday, January 5, 2015

Problem: sum for each column in a text file(ignoring the first line)

Solution:
cat file |awk -F " " 'function abs(x){return ((x < 0.0) ? -x : x)}NR>1{sum1+=$1; sum2+=abs($2)} END{print sum1;print sum2}'

Example:
$cat file
1000    1000
8       8
2       -2
3       0
7       5
$.my.sh
20
15

Ignore the first line in a text file

Problem:
    ignore the first line in a text file under Linux

Solution:
    1)  cat file |awk 'NR>1{print$0}'
    2)  cat file |sed 1d


Example:
$ cat file
1000    1000
8       8
2       -2
3       0
7       5

$ cat file |sed 1d
8       8
2       -2
3       0
7       5

Monday, December 29, 2014

Friday, December 26, 2014

Python Regex

Problem:
    To list all the files in a directory in format with: ama.xxxx or ama.xxxx.gz (x is digital) and print them in the chronological order.

import os
import re

def listdir_fullpath(d):
    return [os.path.join(d, f) for f in os.listdir(d)]

AMA_FILE_NAMING = ".*ama.\d{4}(.gz|)$"
amaFilePattern = dirName + "/" + AMA_FILE_NAMING
amaFiles = sorted( [f for f in listdir_fullpath(dirName) if re.match(AMA_FILE_NAMING, f)], key=os.path.getmtime)

for f in amaFiles:
    print f

@http://hilite.me/


For a simple match, glob can be used.

Wednesday, December 24, 2014

Find the Median - To be continued

The median is the "middle number" in a sorted list of numbers. If it's odd, then it is the middle value. If it's even, it's the average of the two middle values.

/* Problem:
 * How to find the median of a sorted array?
 * How to find the median of an unsorted array?
 * How to find the median of an unsorted array without sorting?
 *
 * How to find the median of two sorted array? - from LeetCode
 * How to find the median of given N sorted arrays?
 */




Reference:
    http://en.wikipedia.org/wiki/Median_of_medians