Saturday, June 1, 2013

Bash to Python migration cheat sheet

Explanation Bash Python
change directory cd os.chdir(“/some/path/”)
print working directory pwd os.getdir()
print 4th line sed -n “4p” somefile linecache.getline(‘somefile’, 4)
list files ls subprocess.call(“ls”, shell=True)
remove/delete a file rm somefile subprocess.call(“rm somefile”, shell=True)
print 3rd column in a line echo ‘this is a line’ | awk ‘{ print $3 }’ “this is a line”.split()[3]
print 3rd column in a file awk ‘{ print $3 }’ somefile
for line in somefile
    line.split()[2]    

Monday, January 21, 2013

gitit as personal wiki

These days I am playing around with gitit  to see if it can make a good personal wiki. In fact, I am also curious how a personal wiki will improve my life.  In order to turn gitit to a personal wiki I did the followings.
  • standard installation from ubuntu repository with apt-get 
  • modify config file for minor things like if login required or session expiry time. In order to print a default config file see gitit man page or help file.
  • one needs a folder under which config file will be put along with the whole wiki. So I created a folder under home: ~/personal_wiki
  •  the main thing which makes gitit a personal wiki is restricting it's access to the local host. So created the following command alias:  alias pwiki='cd ~/personal-wiki/ ; gitit -f gitit.conf -l 127.0.0.1 -p 12000 & cd -' 
  • I don't like using mouse; so I edit wiki page files (*.page) under ~/personal-wiki/wikidata/ with a simple text editor, then I commit it using another comman alias I created: alias commit='cd ~/personal-wiki/wikidata/ ; git commit -am "committed from command line"; cd -'
  • Finally, I preview the wiki withing a web browser by typing http://127.0.0.1:12000/ in adresbarr which is nothing but locahost ip and port number assigned to gitit.