Archive for February, 2015


Useful Git Commands

  • $ git init
    #initialize an empty Git repoistory
  • $ git status
    #see the current state of the project
    untracked file: it is a new file and not be tracked by Git
    staged:Files are ready to be committed.
    unstaged: Files with changes that have not been prepared to be commited.
    untracked: Files aren’t tracked by Git yet. This usually indicates a newly created file.
    deleted: File has been deleted and is waiting to be removed from Git.
  • $ git add <filename>
    $ git add -A .
    # add all, “.” stand for the current directory
    $ git reset <filename>
    #remove a file or files from the staging area
  • $ git commit -m “a message about the changing”
    # Staging Area: A place where we can group files together before we “commit” them to Git.
  • $ git add ‘*.txt’
    # Wildcards: need quotes
  • $ git log
    # see all the changes
    $ git log –summary
    # see more information for each commit
  • $ git remote add origin…
    # push local repository to the GitHub server, “origin” is the name for remote repository
  • $ git push -u origin master
    # push local changes to the “origin” repository
    # -u : remember the parameters, so that next time simply run git push
  • $ git pull origin master
    # check for changes on repository and pull down any new changes by running
  • $ get diff HEAD
    # diff of most recent commit using HEAD pointer
    # HEAD: a pointer that holds your position within all different commits. By default HEAD points to most recent commit, so it can be used as a quick way to reference that commit without having to look up SHA.
  • $ git diff –staged
    # –staged : see the changes you just staged.
  • $ git reset <filename>
    # unstage files, but not delete the files
  • $ git checkout — <target>
    # change the file back to the last commit
    # — : promising the command line that there are no more options after the ‘–‘.
  • $ git branch <new branch name>
    # create a new branch
  • $ git checkout <branch>
    # switch to the branch
    $ git checkout -b <branch>
    # create and checkout a new branch at the same time
  • $ git rm <filename>
    # remove a file
    $ git rm ‘*.txt’
    # remove all file
    $ git rm -r <folder>
    # remove a folder and all its content
  • $ git commit -am “message”
    # if you happen to delete a file without using ‘git rm’, then you still have remove it from the working tree with the command “git rm”. ‘-a’ option means auto removes deleted files.
  • $ git checkout master
    # switch to master branch
  • $ git merge clean_up
    # merge the branch
  • $ git branch -d <branch name>
    # delete branch: -d means if something isn’t merged, it will not allow be deleted
    # –force (-f) : force to be done
    $ git branch -D <branch name>
    # -D combines -f -d into one command
  • $ git push
    # push everything to remote repository
  • $ git add file && git commit -m “removed merge conflicts”
    $git add file && git commit -m “resolved merge conflicts”
    # If pull failed (When conflict with your local file happens), you need this command
  • $ git push origin master –force
    $ git pull –rebase
    $ git push
    # If push failed
  • $ git log origin/master..HEAD
    # Viewing Unpushed Git Commits
    $ git diff origin/master..HEAD
    #  view the diff using the same syntax
    See: Viewing unpushed git commits?
  • git reset –soft HEAD~1
    # Delete the most recent commit, keeping the work you’ve done
    $ git reset –hard HEAD~1
    # Delete the most recent commit, destroying the work you’ve done
    See: How do I delete unpushed git commits?

Vector calculation in python and in R

There are different ways doing math for vector in python

1. use loop

# Create a vector,which begin with 0 to 10, and 200 different elements
x = numpy. linspace(0,10,200)

# Turn numpyarray to list
x = list(x)

for member in x:

2. use loop, but in list

# Method 2: use loop but in list
y=[math.sin(member) for member in x ]

3. use numpy

# Method 3: use numpy
x = np.array(x)
y = np.sin(x)

4. use map and lambda functions

# Method 4: use map and lambda functions
map(lambda member: math.sin(member), x)

In R language, the vector math is relative easy

> a <- seq(1,10, length.out=200)
> b <- sin(a)

Alternative for creating the vector “a”

> a <- seq(1,10, 0.1)
> a <- seq(1,10,by = 0.1)

How to change the document root in XAMPP for Windows

Do the following steps:

  • XAMPP Control Panel -> Apache -> Config -> httpd.conf
  • find the codes:
    DocumentRoot “C:/xampp/htdocs”
    <Directory “C:/xampp/htdocs”>
  • change them to your new folder:
    DocumentRoot “D:/www”
    <Directory “D:/www”>
  • copy all the contents from “C:/xampp/htdocs” to “”D:/www” “
  • restart the Apache