26 September 2013
Bash in 5 minutes
Every time you login, /etc/profile script is run first to initialize.
Then these files are run
.profile
.bash_login
.bash_profile
these files are best to configure PATH variables.
when you logout, .bash_logout script is run.
#refers to home - /home/indu/
~/
#refers to current folder
./
#command to check the PATH variables
echo $PATH
#changing permissions
#chmod refer - http://ss64.com/bash/chmod.html
# change to rwxr-xr-x
chmod 755 file-or-folder
# all(a) get added(+) permissions rw to file
chmod a+rw file-or-folder
# others(o) get removed(-) permissions rw to file
chmod o-rw file-or-folder
# owner(u) get added(+) permissions x to file
chmod u+x file-or-folder
# change ownership
sudo chown username:group file-or-folder
#! - specifies a shell
#!/bin/bash
# Ubuntu version
lsb_release -r
--------------------------------------------------------
bash commands
--------------------------------------------------------
ps //lists what shell prompt you are usingcd //goes to home
cd ~/folder-at-home //this ~/ refers to home location
pwd //shows which directory you are working in
mv f1 f2 //moves file f1 to file f2 - can be used to rename file
cp f1 f2 //copies file f1 to file f2. If f2 exists, then it is overwritten without warning
cp -i f1 f2 //asks before copying and overwriting f2
ls //lists files in a directory
ls -lt // order the list by creation date
ls -ltr // order the list by creation date in reverse order
ls -l //lists files in more detail
ls -a //lists hidden files that start with '.'
ls -F //lets you identify directories with a slash
cat text-file-name //outputs contents of the file to the terminal
cat file1 file2 //outputs contents of file1 and then prints out file2
tail -f file-name //outputs the logs that are getting generated, live
less text-file-name //outputs contents page wise - use :q to quit to terminal
more text-file-name //outputs contents page wise and quits to terminal just like cat
rm //removes file
rm -r //removes a directory along with the files in it
rm -i //asks before deleting a file
hostname //displays the name of the system you are working on
//searches recursively in /directory/ for
//file or folder named item
$find /directory/ -name item -print
//searches and prints all lines that contain string in filename
grep 'string' filename
// searches for specified text in
// all files in the current directory
grep -lir "some text" *
grep -lir "some text" /this/folder/location // searches for specified text in the specified directory location
-l - files that match
-i - ignore case
-r - read all files under each directory recursively
head filename //displays first 10 lines of text in file
head -3 filename //displays first 3 lines of text in file
tail filename //displays last 10 lines of text in file
tail -6 filename //displays last 6 lines of text in file
sort //displays contents of file with lines sorted according to alphabetical order
:q //quits the man page and goes to terminal
| //pipe - output of one process will become the input to another process
echo //send messages from scipts to screen, and more
whereis java //lets you know where all java executable is installed
which java //locates utility copy that you are going to use
bzip2 file.txt //binary-sorting file compressor
bunzup2 file.txt.bz2 //uncompress
gzip file.txt //GNU zip compressor
gunzip file.txt.gz //GNU uncompressor
#tar //tape archive
tar -czvf allmyfiles.tar.gz * //gunzips all the files in the current folder
tar -czvf folder.tar.gz foldername/ //gunzips a folder
tar -zxvf allmyfiles.tar.gz //this will extract the zip file in the current folder
tar -ztvf file.tar.gz //list files that is zipped in this tar file
clear //clears the screen
fg //brings the background process to foreground
#redirecting standard output
command options > destination_file //output of command will be put in destination_file, by erasing the previous contents.
command options >> destination_file //output of command added to the end of destination_file.
#redirecting standard input
command options < filename //command's input to come from file with the provided options
#pipes
command options | command options // output of one command is input to another command
#same as
command options > tempfile
command options < tempfile
jobs //lists the current running jobs with process ids
kill %process_id //kills the process with the process
diff --brief --recursive folder1 folder2 > difference.txt // gets the difference between two folders
--------------------------------------------------------
chmod - chaning file permissions
--------------------------------------------------------
File permissions read(r), write(w) and execute(x) have numbers.
r = 4
w = 2
x = 1
0 - ---
1 - --x
2 - -w-
3 - -wx
4 - r--
5 - r-x
6 - rw-
7 - rwx
chmod 644 filename // user = -rw-, usergroup = -r--, all = -r--
chmod 777 filename // user = -rwx, usergroup = -rwx, all = -rwx
--------------------------------------------------------
short-cut keys
--------------------------------------------------------
ctrl+U //clears your typed matter at the terminal
ctrl+Z //kills the current running program
\q //escapes current view
Ctrl+D //quit or exit
31 August 2010
Logo design at Logosnap
I recently came across this amazingly simple and yet powerful site to design your own logos. Its called Logosnap.com and is owned by logodesignguru.com. I know how cash strapped we are when we are a recent start up. This site is ideal to come up with your own design. You also get to credit yourself to all your friends and family and share that you did it yourself. Its a feeling unmatched. Do visit them and give it a try. You may begin to love your own work, thanks to Logosnap.com
27 August 2010
Setting and Reading Cookies in python Django
I recently tried to figure out how to set and get cookie values. I knew how to do sessions, but I wanted to have my own custom cookie. I was looking for a key-value pairs I could let it be stored on user's browser instead of on the database which is the case with sessions.
Here's how to set a cookie.
Here's how to read the cookie.
That's it. Have fun with cookies.
Reference : http://docs.djangoproject.com/en/dev/ref/request-response/
Here's how to set a cookie.
response.set_cookie(key="mykey", value="myvalue")Here's how to read the cookie.
if "mykey" in request.COOKIES:
read_value = request.COOKIES["mykey"]
That's it. Have fun with cookies.
Reference : http://docs.djangoproject.com/en/dev/ref/request-response/
03 June 2010
Python Best Practices
Here are two interesting articles that will shed some light on the Python Best Practices
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://blog.apps.chicagotribune.com/2010/02/26/best-practices/
http://www.python.org/dev/peps/pep-0008/
Let me see if I can summarize it in the future post.
.
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://blog.apps.chicagotribune.com/2010/02/26/best-practices/
http://www.python.org/dev/peps/pep-0008/
Let me see if I can summarize it in the future post.
.
07 July 2009
Django using Eclipse with pydev extension
This article helps you configure eclipse so that you do web app development using django framework. Eclipse can be used for python programming using pydev plugin. The same plugin will be used for working with django framework also.
I assume you already have pydev plug-in for your eclipse. If not you can download it here. I assume that you have already installed django. If not you can download it here. Django installation instructions are here.
I assume you already have pydev plug-in for your eclipse. If not you can download it here. I assume that you have already installed django. If not you can download it here. Django installation instructions are here.
- Create your django project folder using the command line method as illustrated in the django tutorial. I assume you have used the project name as "mysite". For reference, I will consider it as located at "documents/mysite".
- In eclipse go to windows>preferences and then select Pydev>Interpreter-Python. Select the python interpreter (python dot exe). In the System PYTHONPATH section, please select the django folder you installed. Click Apply. Then click OK.
- Create a pydev project called "mysite" with src folder. For reference I will assume the project folder will be at "eclipse_workspace/mysite".
- Copy the entire "mysite" folder from "documents/mysite" and paste it into "eclipse_workspace/mysite/src" folder. Refresh your view in eclipse. You should now be able to see mysite package and polls package in the eclipse package explorer.
- Lets set up some run configurations. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "manage_config". Select the project as "mysite" and Main Module as "manage.py".
In "arguments" tab, add "runserver --noreload" in Program Arguments section.
In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button.
Now you can run the manage.py module, and this will start the django inbuilt development server. If you want to debug the app, run the manage.py module in debug mode. Just right click on manage.py and then select debug>debug configurations and select manage_config. Click on debug. Or right click on manage.py select debug as> python run, if you have only one run configuration defined for manage.py
- Create a package called "test" and a module called "test". Use this module to play with your Django API.
Lets set up some run configurations for test module. Go to Run>Run Configurations... In the Run Configuration window, select Python Run on the left. Right click and select New. Name it as "test_config". Select the project as "mysite" and Main Module as "test.py".
In "environments" tab, add variable DJANGO_SETTINGS_MODULE with value mysite.settings. You can add new variables by clicking on "New..." button. Now you can run the manage.py module, and this will start the django inbuild dev .
Now you can run or debug the test.py module and play with the Django API to your hearts fill.
Please feel free to test drive and let me know if you run into issues. This set up is pretty much independent of version numbers. If you have any specific problem with any specific version combination, please leave a comment.
23 June 2009
Unable to update Avira Antivir
Since couple of days, I found my Avira Antivir Personal edition (free) not updating properly, or taking for ever to do an update. I thought something might be wrong with my program or worse, my computer might be affected. After searching the web, I found that sometimes when the update files are big and if the update server get over burdened, you will not be able to automatically update.
Solution: Do a manual update. To do that, download the latest virus definition file (VDF) from Avira VDF update. After the file is downloaded, use your Avira Antivir program to do a manual update by clicking "Update" > "Manual Update".
Let me know if this works for you.
Solution: Do a manual update. To do that, download the latest virus definition file (VDF) from Avira VDF update. After the file is downloaded, use your Avira Antivir program to do a manual update by clicking "Update" > "Manual Update".
Let me know if this works for you.
16 June 2009
Paul Graham - Great Hack
Here is an article from Paul Graham. This is a gem of an article. Great Hackers by Paul Graham.
29 May 2009
Python is faster than Java!
I wanted to pitch Java and Python against each other and see how they perform. So I put in a simple program that puts some stress on the system. Data Structures would also be used. Both the programs should be run on same machine. There shouldn't be any other Java or Python process running in background. I wrote a simple program in both Java and Python and ran them.
Java Program (JVM version - 1.6.0_11-b03)
Multiple Run Result
Total time = 1.391
Total time = 1.375
Total time = 1.344
Total time = 1.422
Total time = 1.484
Python Program (CPython version 2.6.1)
Multiple Run Result
Total time = 0.888883333612
Total time = 0.878249380963
Total time = 0.991458537034
Total time = 0.850523498354
Total time = 0.860505161151
I see Python showing a huge advantage when it comes to speed of execution. Java is slow! Thats bad news for Java. I would like you to try same or similar program and let me know how it performs. If you run the same above programs, try increasing the hash size for both the programs. You will be surprised with what you see! I can't believe Java is not only slow, but also uses more memory. Python is not only simpler, but faster, more powerful and uses lesser memory than Java.
Java Program (JVM version - 1.6.0_11-b03)
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
public class PerformanceTester {
private final static int SIZE = 500000;
public static void main(String[] args) {
long start_time = System.currentTimeMillis();
Hashtablebuild_hash = new Hashtable ();
for(int i=0; ibuild_array = new ArrayList ();
for(Iteratorit = build_hash.keySet().iterator(); it.hasNext();){
Integer value = build_hash.get(it.next());
it.remove();
String strValue = (value.intValue()+8)+"add more";
build_array.add(strValue);
}
long stop_time = System.currentTimeMillis();
System.out.println("Total Time = "+((stop_time - start_time)/1000.0000));
}
}
Multiple Run Result
Total time = 1.391
Total time = 1.375
Total time = 1.344
Total time = 1.422
Total time = 1.484
Python Program (CPython version 2.6.1)
import time
start_time = time.clock()
SIZE = 500000
build_hash = {}
for a in range(1,SIZE):
build_hash[str(a)] = a
build_array = []
for key in build_hash:
build_array.append(str(build_hash[key]+8) + "add more")
build_hash[key] = None
stop_time = time.clock()
print "total time = ", (stop_time - start_time)
Multiple Run Result
Total time = 0.888883333612
Total time = 0.878249380963
Total time = 0.991458537034
Total time = 0.850523498354
Total time = 0.860505161151
I see Python showing a huge advantage when it comes to speed of execution. Java is slow! Thats bad news for Java. I would like you to try same or similar program and let me know how it performs. If you run the same above programs, try increasing the hash size for both the programs. You will be surprised with what you see! I can't believe Java is not only slow, but also uses more memory. Python is not only simpler, but faster, more powerful and uses lesser memory than Java.
28 May 2009
Java is loosing the grip while Python and Ruby gaining ground
We have come accross many instances that Java/J2EE is trying to get rid of its complexities, yet not very successful at it. First the misfortunes EJB 2, and then the obliteration of XML files in a large application. Finally the tedious and daunting task of putting all the types of frameworks and to make them work together for every new application. There has been a huge improvement in EJB 3, but architects and managers still dread the name EJB.
The management hates it when we tell them that we are throwing away code. They panic, as if we are throwing away used furniture. Why throw it, can't we re-use them somewhere! This statement looks very logical from the management perspective, but when it comes to we super technologists, it sounds ridiculous. For us, old code is like old milk. You refactor it and continually improve it or just throw the freaking thing away. Old code has a shelf life, just like milk. We are involved in developing and maintaining code, we know how bad it stinks. The smell is a good indicator that the application is deteriorating in quality and increasing in quantity.
If you are worried about your job prospects, Java/JEE is still a hot bed as of May 2009. The ecosystem is complex enough that you need people who are bright enough to make sense from it. Many companies still stick to Java as their primary web technology, but things might be changing soon.
Sun is now acquired by Oracle and I do not know what future holds for new Java apps. Oracle is big and they will push the Java technology to upper management in many large corporations. These companies have lot of money to invest and they are always more comfortable when they know that they are in company with large corporation such as Oracle. If you are very enthusiastic about web application development, and are willing to take some risks in the job market, you should try Rails or Django. Job prospects are improving for both, so you might not be in loss. But you will enjoy your work much better because I see either Ruby or Python to be much better programming languages than what Java is or going to become. After being with Java for this long, I see that Java has this inferiority complex with C# and does a catch up. I am in big favor of open source and you might know how I might feel about C#.
Ruby on Rails or Python with Django provide very powerful combination for web development. Job demands will come, but will come as the industry adoption grows. Both Python and Ruby are mature and have good community of users. The new features in the languages come from key persons. Just like Linus Torvalds drives Linux kernel development, Yukihiro Matsumoto will drive Ruby language development and Guido van Rossum will drive Python language development. I feel this is much better than a language being driven through a community similar to JCP.
21 March 2009
Ruby on Rails IDE for beginners
I have been a Java programmer for a long time and a big fan of eclipse. Lately I have been very interested to try out Ruby on Rails and Python with Django. I am not the guy who wants to program using text editors. I found that we have these following choices. I have listed here some IDEs and simple test editors which can turn into powerful programming environments for you as a new RoR explorer.
Programming environments listed in Alphabetical order
Note: If you are already using a tool for Ruby on Rails development, please leave a comment and let us know about it.
Eclipse based RadRails - If you are coming from Java shop and are already heavily into eclipse as your IDE, then you might want to check this out. It installs on Linux, Mac OSX and Windows. Because eclipse is java based, you will need jvm installed before you install RadRails with eclipse. RadRails can also be installed with Aptana Studio, an IDE bundle by RadRails creators.
JEdit - JEdit is a powerful programming tool for those who are good with using just a text editor for their coding requirements. Here are couple of good guidlines from Eric and Eadz for working with JEdit for RoR.
Komodo - This is an excellent IDE from ActiveState developers for scripting languages. You can program in Python, Perl, PHP, Ruby, and even HTML, CSS and javascript using Komodo. If you are also programming in other mentioned languages, then this IDE would be worth a look.
NetBeans- This is a java based IDE which has a good support for RoR. Comes bundled with Glassfish V3 Prelude. They provide RoR learning trails that can help you if you are a beginner.
TextMate - For all Mac enthusiasts, this is the editor of choice for RoR. This is pretty powerful and highly customizable. You defenitely want to check this out if you are on a Mac. If you use windows, there is a similar editor called eTextEditor, which is equally powerful.
Programming environments listed in Alphabetical order
Note: If you are already using a tool for Ruby on Rails development, please leave a comment and let us know about it.
Eclipse based RadRails - If you are coming from Java shop and are already heavily into eclipse as your IDE, then you might want to check this out. It installs on Linux, Mac OSX and Windows. Because eclipse is java based, you will need jvm installed before you install RadRails with eclipse. RadRails can also be installed with Aptana Studio, an IDE bundle by RadRails creators.
JEdit - JEdit is a powerful programming tool for those who are good with using just a text editor for their coding requirements. Here are couple of good guidlines from Eric and Eadz for working with JEdit for RoR.
Komodo - This is an excellent IDE from ActiveState developers for scripting languages. You can program in Python, Perl, PHP, Ruby, and even HTML, CSS and javascript using Komodo. If you are also programming in other mentioned languages, then this IDE would be worth a look.
NetBeans- This is a java based IDE which has a good support for RoR. Comes bundled with Glassfish V3 Prelude. They provide RoR learning trails that can help you if you are a beginner.
TextMate - For all Mac enthusiasts, this is the editor of choice for RoR. This is pretty powerful and highly customizable. You defenitely want to check this out if you are on a Mac. If you use windows, there is a similar editor called eTextEditor, which is equally powerful.
Subscribe to:
Posts (Atom)