Arunkumar P

Wednesday, March 31, 2010

Boot Time of a linux box

Do you want to know the time when a linux machine was started/booted? It's stored in /proc/stat. For easy use, in the standard unix time format display,here's a 1 liner to print it out, in your local timezone:
perl -ne 'print scalar localtime $1 if /^btime (\d+)/' /proc/stat

Ref

Thursday, January 7, 2010

vi editor word auto complete

In vi editor, When you start typing a word, you can press "Cntrl+n" to search through all words in the current document that begin with the characters you've begun typing. this only searches the current file.

"Cntrl+P" is used for displaying list of matching keywords.

Monday, October 26, 2009

Tired of typing big directory path to change to it frequently? (or)

Tired of typing big command frequently in Linux/Unix?

Have your own (small)shortcut command for those long commands.

Steps :

· Create a shell script(.sh) file with the (long)command that needs to be run frequently.

For example,

Create a file '/root/p.sh' and add the following 'cd' command to it.

-------------

cd /var/www/html

· Create an alias to that shell script.

For example,

alias w=’. /root/p.sh’

[Note: dot in the beginning makes the command to be executed in the same shell.]

Add this alias command in ‘.bashrc’ file (anywhere in the file)


Next time, to change to the ‘/var/www/html’ directory, just need to use the command ‘p’.

Note: Any long command(s) can be added to that shell script as required.

Typical commands sequence may be as follows,

vi /root/p.sh

cd /path/to/long/directory

!wq

vi .bashrc

alias w=’. /root/p.sh’

Saturday, July 4, 2009

pyHook Example - Capture Mouse and Keyboard Events in Windows using Python

Here is a sample python program to capture mouse and keyboard events in windows.


import os
import time
import pyHook # http://sourceforge.net/projects/pyhook/
from win32gui import GetWindowRect, GetClassName, GetWindowText

curTime = time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))

if not os.path.exists("Messages"):
os.mkdir("Messages")

f = open("Messages\\messages"+ curTime +".txt", "w")

def Log(logStr):
print str(logStr)
f.write(logStr + "\n")


def OnMouseEvent(event):
Log('MessageName:' + str(event.MessageName))
Log('Message:' + str(event.Message))
Log('Time:' + str(event.Time))
Log('Window:' + str(event.Window))
if event.Window != 0:
Log('Window Rect:' + str( GetWindowRect(event.Window)))
Log('Window Class Name:' + str( GetClassName(event.Window)))
#Log('Window Text:' + str( GetWindowText(event.Window)))
Log('WindowName:' + str(event.WindowName))
Log('Position:' + str(event.Position))
Log('Wheel:' + str(event.Wheel))
Log('Injected:' + str(event.Injected))
Log('---')

# return True to pass the event to other handlers
# return False to stop the event from propagating
return True

def OnKeyboardEvent(event):
Log('MessageName:' + str(event.MessageName))
Log('Message:' + str(event.Message))
Log('Time:' + str(event.Time))
Log('Window:' + str(event.Window))
if event.Window != 0:
Log('Window Rect:' + str( GetWindowRect(event.Window)))
Log('Window Class Name:' + str( GetClassName(event.Window)))
#Log('Window Text:' + str( GetWindowText(event.Window)))
Log('WindowName:' + str(event.WindowName))
Log('Ascii:' + str( event.Ascii) + str( chr(event.Ascii)))
Log('Key:' + str( event.Key))
Log('KeyID:' + str( event.KeyID))
Log('ScanCode:' + str( event.ScanCode))
Log('Extended:' + str( event.Extended))
Log('Injected:' + str( event.Injected))
Log('Alt' + str( event.Alt))
Log('Transition' + str( event.Transition))
Log('---')

# return True to pass the event to other handlers
# return False to stop the event from propagating
return True

# create the hook mananger
hm = pyHook.HookManager()
# register two callbacks
hm.MouseAllButtonsDown = OnMouseEvent
hm.KeyDown = OnKeyboardEvent

# hook into the mouse and keyboard events
hm.HookMouse()
hm.HookKeyboard()

if __name__ == '__main__':
import pythoncom
pythoncom.PumpMessages()

My second open source project - Eyecare

I have released my second software "Eyecare". Here is the information about the software.

https://sourceforge.net/projects/eyecare/

* Simple application to take care of your eyes while working n computers for long time.

* This application sits in System Tray and keeps displaying a blank screen after every 20 minutes for 20 seconds.
Currently, this interval time is hard-coded/not configurable.

* Please stretch your legs, look at distance objects, move eyes around, *blink* your eyes and relax yourself during the rest duration.

* Incase you are doing very very important work and don't want the software to disturb you, you can disable blank screen display
by selecting "Disable" option in the system tray icon.
Even if the blank screen is displayed, you can still come out by clicking on the blank window and pressing "ESC" button/ by selecting "Close" option
from "File" Menu.
* My personal recommendation is not disable the software. Because of the "Breakout Principle" http://www.google.co.in/search?q=breakout+principle

* Initially, I have choosen "wxPython" to get the cross platform software. But, now there are some issues in linux machines :(.
Looking for supporting linux environment too.

Wish-List:
* Customizable timing.
* Still counting :)

Take care your vision!

Tuesday, May 12, 2009

My First Open Source Project

I have started writing a small system utility in python to schedule my system shutdown. Later, I thought of adding GUI to it and release it as open source project. Here we go! http://sourceforge.net/project/showfiles.php?group_id=260807

Locking the windows PC using python.

import ctypes
ctypes.windll.user32.LockWorkStation ()


Followers