Monday, July 06, 2009

Macbook: Know Your Battery's Capacity

I wanted to check how's my Macbook's battery was doing. In Ubuntu, it pretty straightforward.


zaher@zaher-macbook:~$ cat /proc/acpi/battery/BAT0/state
present: yes
capacity state: ok
charging state: charged
present rate: 0 mW
remaining capacity: 47490 mWh
present voltage: 12435 mV

And ...
zaher@zaher-macbook:~$ cat /proc/acpi/battery/BAT0/info
present: yes
design capacity: 50200 mWh
last full capacity: 48750 mWh
battery technology: rechargeable
design voltage: 10950 mV
design capacity warning: 250 mWh
design capacity low: 100 mWh
capacity granularity 1: 10 mWh
capacity granularity 2: 10 mWh
model number: ASMB016
serial number:
battery type: LION016
OEM info: DPON016

Ahh, 48750/50200 = 97%, Not bad after 2 years of 24x7 punishment (yeah I keep it running all day, because I download a lot :P). Let me know your's too.

Saturday, June 27, 2009

Python: Simple Singleton for Mysql Access

I was trying to come up with a simple implementation of Singleton pattern in python, its a bit different from other language constructs. Here is the code implementing a single point database access using MySQLdb.


#! /usr/bin/python

import MySQLdb
import sys

class Conn(object):
__instance = None
__conn = None


def __init__(self):
try:
if Conn.__instance == None:

Conn.__instance = self
Conn.__conn = MySQLdb.connect (host="localhost", user="user", passwd="pass", db="dbname")

except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])

sys.exit(1)


def get_connection(self):
return Conn.__conn


if __name__ == "__main__":
conn = (Conn()).get_connection()

''' Do your thing '''
conn.close()


It's not perfect I guess, but right now it serves the purpose. You are welcome to put down any valuable advice into this.

Friday, June 26, 2009

Mysql: Dumping only stored procedures

I had to find a way to dump ONLY the stored procedures from a mysql database. Here is how I did it.
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt "databasename" > stored_procedure.sql



PS. This is the shortest post that I ever made. :)