Python: Manipulate Date and Time variables

February 17th, 2008 mysurface

When comes to data time related calculations, we usually calculate for time difference, for example How long is the down time for a particular service? How many days or hours are used to finish a task? etc. With python datetime and time class, it makes calculation simple. Let us look at some simple examples of […]

Posted in Developer, python | Hits: 52436 | 1 Comment »

python: user define sorting with callback

January 8th, 2008 mysurface

Theres a lots of people treated python as scripting language like bash, but I am going to tell you, python is real programming language. Python support callback like c/c++, and this feature is really God-like, because it is so simple to implement callback in python. What is Callback? In computer programming, a callback is executable […]

Posted in Developer, python | Hits: 58068 | 11 Comments »

Python: Careful with equal sign

December 8th, 2007 mysurface

To store data, object reference to a variable is very easy in python. For example, to assign an integer 5 to a a=5 Same thing goes to string str=”hello world” Assign data to a data structured variable, let say list, L=[1,2,3,4,5] Even assign a function to a variable. import sys wstderr=sys.stderr.write wstderr(“hello world\n”) Observed that […]

Posted in python | Hits: 85138 | 7 Comments »

How to redirect output to a file as well as display it out

December 6th, 2007 mysurface

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example: echo “hello world” > test.txt But what if I want to display it out as well as store into a file? Answer: tee echo “hello world” | tee test.txt Okay it seems very easy, how about […]

Posted in pipeline, python, tee, Text Manipulation | Hits: 354200 | 47 Comments »

Python: How to access ssh with pexpect?

November 25th, 2007 mysurface

I have research on how to access ssh using scripting language for quite sometimes. For python, there are three libs is in my list: Twisted – an event-driven networking engine written in Python. Paramiko – implements the SSH2 protocol for secure connections to remote machines. Pexpect – spawn a child application and control it as […]

Posted in python | Hits: 204075 | 24 Comments »

python: handle string from pipelines and list of param

November 13th, 2007 mysurface

While I was searching ways to implement pipeline input for my python apps, I read an article from that mention about how easy that python can works with pipeline. Here is the code quote from that article. #! /usr/local/bin/python import sys sys.stdout.write( Well, I understand that served as a simple example to show how […]

Posted in Developer, python | Hits: 85675 | 11 Comments »

python: how to identify the type of your variable

November 10th, 2007 mysurface

In python, every single variable is an object, every object must have a type, it is either data structure or class instances. Python’s variable can be dynamically change easily during runtime, for example >>> d={1:’one’,2:’two’} >>> print d {1: ‘one’, 2: ‘two’} >>> d=[‘one’,’two’] >>> print d [‘one’, ‘two’] First line d is declare as […]

Posted in Developer, python | Hits: 364634 | 22 Comments »

Help yourself in python

October 31st, 2007 mysurface

If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-like programming language that are so famous today. You can type python into google, the first link is not about the reptile but the programming language. There are plenty of apps and scripts written […]

Posted in Developer, python | Hits: 27893 | 3 Comments »

Use gprof to check your codes for performance issues

August 29th, 2007 mysurface

By reading the article Speed your code with the GNU profiler from IBM DevelopWorks, I have gain the knowledge of using gprof to easy my work to identify my module’s performance’s bottleneck. Here, I would like to share my experience on how I discover the clog of my codes. Let us first look at the […]

Posted in Developer, gcc, gprof | Hits: 61898 | 13 Comments »

perform grep and make in vim

June 15th, 2007 mysurface

We can do grep and make in vim, the advantage of doing that in vim compare to terminal is you can use the result to track the error and warning for make or goto the line and files of the grep results. How to make in vim? :make In order to make, the current directory […]

Posted in grep, make, Text Manipulation, vi, vim | Hits: 95051 | 3 Comments »