Thursday, July 30, 2015

./configure options

When building packages, often we need to run ./configure with a bunch of options to build the package. To find out what the last options were used for configure, use this command:
./config.status --config

How to remember ./configure script arguments a year later

Monday, July 13, 2015

Execute a command, display output and get it's return code in Python

Often in my tests, I need to display the output and use the return code of the command I want to run. But I can't use check_output because my tests need to support RHEL6 and RHEL7 and RHEL6 is still on python 2.6.x and check_output is only available in Python 2.7

The following code snippet is modified from another website:

from subprocess import Popen, PIPE
 
cmd = "blah blah"
process = Popen(cmd.split(), stdout=PIPE)
process.communicate()    # execute it, the output goes to the stdout
exit_code = process.wait() # when finished, get the exit code


Thursday, July 2, 2015

Access Environment Vars in Python

To access environment variables in Python, import os module and run the following command
import os
print os.environ['ENV_VAR_YOU_WANT']

Monday, June 29, 2015

Combine 2 commits into one and update pull request

Finally, I was able to combine 2 commits into 1 commit and update the pull request. This will save me lots of time instead of creating a new pull request everytime and re-do work.

First time:
git clone <my-clone-of-upstream-repo>
cd <upstream-repo>
git remote add upstream <upstream-repo>
git config --global push.default simple
When starting a new pull request:
git checkout -b <new-branch>
Make changes, commit and send pull request. 

When combining n commits:
git fetch upstream
git merge-base new-branch master => This will generate a commit hash
git rebase --interactive <commit hash>
Your text editor will open with a file that lists all the commits in new-branch, and in front of each commit is the word "pick". For every line except the first, you want to replace the word "pick" with the word "squash" or "fixup". Save this file. 
git rebase upstream/master
git push -f

Thursday, June 11, 2015

Start vim without .vim settings

In my .vim settings, I have audo indent and smart indent enabled. Sometimes when I'm copying code, this causes the code to completely go wonky.

So, to avoid this and just copy the code, I disable the vim settings and open the file using
vim -u NONE filename
 

Wednesday, May 27, 2015

Restarting gnome-shell

Often, my desktop will get stuck into a weird position - particularly when I plug in and out of my dock (multi-monitors). Restarting gnome-shell fixes the problem.

You can restart the gnome-shell by pressing Alt+F2 and then typing in either "restart" or just "r" and pressing enter

Tuesday, April 28, 2015

Commenting a block of code in vi

Many times, when modifying code or debugging, I comment out blocks of code. This is tedious to do manually.

I searched around for a way to do it fast and came across this tip:

For commenting a block of text is almost the same: First, go to the first line you want to comment, press CtrlV, and select until the last line. Second, press ShiftI#Esc (then give it a second), and it will insert a # character on all selected lines. For the stripped-down version of vim shipped with debian/ubuntu by default, type : s/^/# in the second step instead.