Executing bash commands via python

In python, executing bash commands can be done using subprocess module. It’s pretty easy to use and it’s a powerful module. For simple commands,  we can use subprocess.call


import subprocess


subprocess.call(["command1", "arg1", "arg2"])


import subprocess

subprocess.call(["ls", "-l"])
total 4

-rw-rw-r-- 1 tevin tevin 15 Sep 3 15:29 test.txt

You can also use subprocess.check_call  and subprocess.check_output


For more flexibility, you can use Popen . Using this you can store the output of command as well as any error occurred during command execution.


process = subprocess.Popen(["ls", "-l"])
(output, err) = process.communicate()

communicate  method interacts with process and waits for the process to complete. It returns a tuple consisting of stdout and stderr.

Executing commands in background:

subprocess.Popen() only runs a process in the background if nothing in the python script depends on the output of the command being run. For example, the following code won’t be executed in background.

import subprocess

process = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE)

Thinking about what is subprocess.PIPE?

subprocess.PIPE: Special value that can be used as the stdin, stdout or stderr argument to Popen and indicates that a pipe to the standard stream should be opened.

Changing directory(cd command):

You might be thinking that why ‘cd’? Why it can’t be executed using subprocess?

If you use subprocess.call(“cd ..”), it will throw an error ‘No such file or directory’. It is because cd is a shell internal. So you can only call it as

subprocess.call('cd ..', shell=True)

But it is pointless to do so.  As no process can change another process’s working directory (again, at least on a UNIX-like OS, but as well on Windows), this call will have the subshell change its dir and exit immediately. Don’t worry you can change directory using os.chdir(path).

Calm.com – An answer to meditate at workplace

All are stressed at your workplace for one reason or other. Listening to music or seeing beautiful places will release your pressure upto an extent. Calm.com is an answer to get relieved at your workplace. It comes with calming music and beautiful nature scenes.  In fact, it helps you to meditate.

You can choose either guided calm or setting a timer. In guided calm, a person(recorded voice) will guide you to be calm. The person will give you proper instructions. You can set timers ranging from 2 minutes to 20 minutes. Also, you can change music as well as nature scenes as you wish.

Luckily for mobile phone users,  there are iPhone and android apps for the same. I assure you, it will be a nice experience and should make you calm.

Wearable Computers…

Introduction to wearable computers

Simply put , its a technology that incorporate in things you wear on day to day basis and it could be anything from a smart watch, augmented reality glasses or even a personal health monitor in the form of a bracelet.

The idea is that technology will increasingly become more part of our day to day lives, and it will become more intrusive as it will be part of our clothing and sometimes even part of our bodies.

The design of wearable computers is still a topic of research and a variety of user interfaces are being developed each day.

Brief history of Wearable Computers

Due to the varied definitions of “wearable” and “computer”, the first wearable computer could be as early as the first abacus on a necklace, a 16th-century abacus ring, the first wristwatch made by Breguet for the Queen of Naples in 1810 or the pocket watch from the 1500′. The first wearable computer that fits into the 20th century image was a computer designed to predict Roulette Wheels, this was invented in 1961 by Edward O Thorpe. A data tracker hidden in his shoes would track the speed of the Roulette Wheels and the computer would indicate what to bet on.

In 1967, Hubert Upton developed a technology which allowed the person wearing the glasses to lip read, this was using the LED device.

Steve Mann’s Concept…

Steve Mann, a professor at the University of Toronto, defined computer is not merely a time-keeping or calculating device, but rather a user-programmable item for complex algorithms, interfacing, and data management.

By this definition, he in 1981 Steve Mann designed and built a backpack-mounted CMOS 6502-based wearable multimedia computer with text, graphics, and multimedia capability, as well as video capability (cameras and other photographic systems). Mann went on to be an early and active researcher in the wearables field, especially known for his 1994 creation of the Wearable Wireless web cam

Steve Mann’s Wear-Comp Concept.

Steve Mann's Wear-Comp Concept

Applications & Future…

For the past few years, industry pundits have been predicting the death of the personal computer. I guess the personal computer is not dying, but is becoming even more personal. It is now something you’re going to wear – in your clothing, jewelry, shoes, glasses, watches, and even on your skin.

Military :

The wearable computer was introduced to the American Army in 1989. This was a small computer that was meant to assist soldiers at the battlefield. Since this the concept has grown into the current Land Warrior program and proposal for future systems The most extensive military program in the wearables arena is the US Army’s Land Warrior system, which will eventually be merged into the Future Force Warrior system.

F-INSAS is an Indian Military Project, designed largely with wearable computing. Indian Scientist, Prof. Dr. Andrews Samraj, Suggests an Ambush, emergency response, Life saving and rehabilitation for all operation strategists by the non invasive wearable technology.

Health care Industry :

Smart electronic “tattoos” will enable continual fetal monitoring. Today, the data must be uploaded by going near a reader, but in the future the data will be uploaded to the cloud in real time, from anywhere.

Smart electronic “tattoos”

There are some more examples like wearable automatic calorie monitoring and balancing system and health monitoring devices.

Entertainment Industry :

Wearable computer as devices to immerse the player more fully in the computer games or experiences him/she is currently interacting with. Currently there are already VR headsets which allows the user to change his view just by moving his head.


Wearable Computers would dominate in the near future, years ago you would not have thought that you could do some of the things you can do today as computers are getting smaller and more powerful they can be integrated into virtually anything.

Advantages & Disadvantages….

  1. Enhanced Communication
  2. Can be used to recognize a person in a high alerted area
  3. Flexibility
  4. Freedom
  5. Work from anywhere
  6. User Convenience
  1. Expensive
  2. Can cause irritation in heat
  3. Side Effects such as Headaches
  4. Wearable Computers can invade privacy
  5. Costly

Wearables From India

F-INSAS (Futuristic Infantry Soldier as A System )

Is an Indian Military Project, designed largely with wearable computing


Is a Tiny Wearable Device that you can wear on the Thumb of your hand as a ring and it will make your whole Palm, Fingers as Numeric Keypad and Gesture space. Developed in Kochi by a small company called RHL Vision Technologies.

Smart Cap

Arvind Sanjeev based out of Kochi India took less than a month and around INR 4500 to replicate Google glass via open source hardware.


Whatever area wearable computer technology is applied to you can see that it willl improve the quality of life and make day-to-day life less complicated. It is only our imagination which will limit the number of applications for this new emerging technology.

It may take some time for wearables to be commonly accepted. After all, it was once unusual to see people using cell phones or wireless microphones, but they have been embraced.

CSSDeck – Learn crazy CSS

CSSDeck - Learn crazy CSS

This week’s write-up is about CSSDeck, literally a deck filled with lots of amazing CSS codes. The Labs section is the primary part of this site, with the intention to allow users to share, edit and collaborate on creating and debugging HTML, CSS and JS codes. The site also allows to send in “cool crazy stuff created with the powers of CSS3 and JS” that they could feature in the gallery helping the creator “get some fame as well as helping others learn about the cutting edge practices and methodologies“. In addition to these, there are codecasts that users can create or watch to help with the learning experience.

Interested enough ? What are you waiting for ? Take a look @ CSSDeck.

A few interesting examples of crazy CSS stuff (Watch the codecasts to learn how these were created 😉 ):

  1. Pac Pac Pac
  2. Flickr Loader
  3. Macbook icon

Concept of Mutable & Immutable objects in Python

An Immutable object, in the lime light of object-oriented and functional programming, is an object whose state cannot be modified after it is created.

Objects of built-in types like (intfloatboolstrtupleunicode) are immutable,

Mutable object, can be mutated or state can be modified after it is created. A mutable object will have at least a single method able to mutate the object.

Objects of built-in types like (listsetdict) are mutable, Custom classes are generally mutable. To simulate immutability in a class, one should override attribute setting and deletion to raise exceptions:

Please refer “names concept” in python, if you don’t have a clear concept onobjects,identifier, `variables.

A practical example to findout the mutablity of object types

x = 10
x = y

We are creating an object of type int. identifiers x and y points to the same object.

id(x) == id(y)
id(y) == id(10)

if we do a simple operation.

x = x + 1


id(x) != id(y)
id(x) != id(10)

The object in which x was tagged is changed. object 10 was never modified. Immutable objects doesn’t allow modification after creation

In the case of mutable objects

m = list([1, 2, 3])
n = n

We are creating an object of type list. identifiers m and m tagged to the same list object, which is a collection of 3 immutable int objects.

id(m) == id(n)

Now poping an item from list object does change the object,


object id will not be changed

id(m) == id(n)

m and n will be pointing to the same list object after the modification. the list object will now contain [1, 2]

Unexpected results can be expected if you use mutable objects in

  • Function’s default arguments
  • Class inheritance

Optimize the DBMS – Whoosh! goes the App

As we all are aware, SQL optimizations are required for speeding up applications. There situations in my career where we felt like MySQL’s MyISAM engine is not fast enough! There are multiple factors that may slow down the SQL. They could be categorized into three categories.

  1. The database Software/Engine
  2. The database design/architecture
  3. The SQL used

We will get to each of this one by one.

1. The database Software/Engine

For normal websites including e-commerce sites, the most executed SQL statement is SELECT. There may be updates when someone buys a product. Admin will be doing INSERT and DELETE too. Still the most used one is SELECT statements. So experts recommend DBMS which are fast in SELECT statements and MySQL with MyISAM engine is always recommended for faster SELECT statements. Problem with MyISAM is the lack of foreign key support. InnoDB engine supports foreign Keys, but is slower compared to MyISAM engine.

Again we can see that MySQL 5.0x.xx is slower than MySQL 5.1x.xx. You can read more about it here.

So we need to choose a database/engine that fits our requirement. If you intend to have only few hundred SELECT statements per minute; it won’t be a big concern.

2. The database design/architecture

The design has a huge impact on performance. For those who have a computer science degree are aware of database normalization. Unfortunately, I have never heard a non CMM level company’s Project Manager or team lead talk about normalization. On the other hand I heard people saying that ‘normalization will slow down the application’. In reality, its both true and false.

When a database is designed in 3rd normal form, the database is considered ‘normalized’ and you can go to BCNF or 4th normal form.

When we normalize a database, we have four goals: 1. Arranging data into logical groupings such that each group describes a small part of the whole. 2. Minimizing the amount of duplicate data stored in a database 3. Organizing the data such that, when you modify it, you make the change in only one place. 4. Building a database in which you can access and manipulate the data quickly and efficiently without compromising the integrity of the data in storage.

When it’s mostly SELECT only system like a blog where few people insert or update data and thousands view it, it’s Ok to have denormalized DB design. But for ecommerce systems or similar that have extensive use of inserts/updates, it’s always better to reduce no. of places to update for each transaction. Denormalization may make the system to use less number of SELECT queries and make complex SQLs more simple, but when it’s time to insert or update, the application needs to execute multiple INSERT or UPDATE statements. In effect, normalization may make the system to use complex SELECT statements with joins, but denormalization may make the application slower by needing us to execute more INSERT/UPDATE statements.

We need to analyse the system first to see how normalized our system needs to be. A standard piece of database design guidance is that the designer should first create a fully normalized design; then selective denormalization can be performed for performance reasons.

Another important fact is that, all fields that appear in a WHERE clause should be indexed for better performance of SELECT statements. on the other hand, over indexing will slow down the INSERT/UPDATE statements.

3. SQL Used

We can optimize SQLs used in the application. Simplest tip is: never use * in a select statement. Select the fields you need. Another is to specify the table names if we join tables. For example

Let A and B be two tables in a database; and we need only field1 and field2 from table A and field1 from table B, then instead of

SELECT * FROM A, B WHERE A.id = B.t1id


SELECT A.field1. A.field2, B.field1 FROM A, B WHERE A.id = B.t1id`

There are cases where multiple SELECT statements and the language you use to write the application is faster than complex joins in SQLs. Think wisely 🙂

In MySQL, they support specifying which index to use using index hint statements like FORCE INDEX, USE INDEX etc. You have to look into the features provided by the DBMS being used to find out the best method to optimize your SQL.

Database Design
Database Normalizations wiki
Database Normalizations explained
MySQL index hint statements

A shack of designs

DesignShack - The One stop designs site.

Over the last few weeks, we have been sharing details about sites that people like you and me could find handy sometimes. This week’s write-up is about DesignShack. This is a site dedicated to showcasing inspiring web designs along with the resources that you could use to succeed in the same way. The authors curate the latest happenings in design section of the Internet leading to articles, tutorials and designs which can be termed as crème de la crème. DesignShack not only show you the best web designs but also enable you to create stuff like those.

The site offers membership as well as an RSS feed for those who want to get regular updates. There are 3 main sections, namely Articles, Gallery and hidden section of Freebies. While you can find the first two sections right on the home page menu, the Freebies is listed under the Articles section.

Take a sneak peek @ DesignShack

A few articles that we recommend

  1. Why User Experience (UX) matters?
  2. Ten Crucial Elements in Web Design
  3. Five Steps to Improve Your CSS Knowledge

Snippets, Books & Questions – Programmer’s Heaven

Programmer's Heaven
Last week, we had shared Programmer’s Heaven through our Nu-bits’s session. The site, as seen from the homepage, looks like a Q&A forum which is one of it’s secondary functions. But it’s primary focus is on sharing code snippets between programmers. If you are wondering how do they do that, that’s where the Q&A comes into play, along with other sections like user-uploaded-files. Along with these, the Articles section and E-Books section are worth having a look at. However, to participate in the forum and upload files, you will need to sign up.

Looking for more ? Look @ ProgrammersHeaven

A few interesting ebooks that caught our sight were:

  1.  Learning JavaScript Design Patterns
  2. AngularJS in 60 Minutes
  3. The Not So Short Introduction to LaTeX

Googling tips

Google is part of everyone’s life.  Especially people who are working in software industry, google is inevitable. If you can search google effectively, you can become a king in software industry. So, here are some tips and tricks that make your life easier 🙂

  • define : If you want to get the definition of a word use ‘define’ keyword.

    Eg: define  word
  • time: Get the time of a location.

    Eg: time ottawa
  • weather: Get the weather of a location

    Eg: weather ottawa
  • Calculations: Do your mathematical calculations in the search box

    Eg: sin(ln(sqrt(31E4)))
  • “search_term”: Search for the exact term.

    Eg: "India"
  • -search_term : Used for excluding a word. This is especially useful for words with multiple meanings, like Jaguar the car brand and jaguar the animal.

    Eg: jaguar speed -car
  • filetype: Used for filtering your results with given file type.

    Eg: If you are searching for css tutorial and you only need ppt files. Then, search css tutorial filetype:ppt
  • site: Search within a site or domain. It used when you want to get results from a particular site.

    Eg: If you want to get results only from stackoverflow.com, search python comprehension site:stackoverflow.com
  • related: Search for pages that are related to the given url.

    Eg: You know facebook is a social networking site and you want to know what are the other social networking sites. Search related:facebook.com
  • info: Get information of site.

    Eg: If you want get information about a site, say, nuventure.in  search info:nuventure.in
  • conversions: For unit conversions use in or to operator

    Eg: 1 pound in kg

Happy googling 🙂

For more information, go to https://support.google.com/websearch/answer/134479?hl=en