Archive

Archive for August, 2009

PHP: Save As Dialog box for file download.

August 25th, 2009

< ? PHP
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename='temp.txt'");
readfile("./temp.txt");
?>

Uncategorized

Python: Convert Epoch to GM Time.

August 24th, 2009

>>> import time
>>> timestamp=float(’1251157271.796′)
>>> print time.gmtime(timestamp)
time.struct_time(tm_year=2009, tm_mon=8, tm_mday=24, tm_hour=23, tm_min=41, tm_sec=11, tm_wday=0, tm_yday=236, tm_isdst=0)
>>> start_time=time.gmtime(timestamp)
>>> for x in start_time:
…     print x

2009
8
24
23
41
11
0
236
0

Uncategorized

Common PHP Memcache Error - enable the module!

August 24th, 2009

memcache class  not found in php page.

problem: i’ve install memcache for php, restarted apache but get the follwoing
error…
“Fatal error: Class ‘Memcache’ not found in /var/www/loadscript/index.php on line 2″

resolution: Add this line to php.ini and restart apache

extension=memcache.so

Uncategorized

Storing data in Memcache with Python

August 24th, 2009

$ apt-get install memcached python-memcache

jesterj@jesterj-laptop:~$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>import memcache
>>>memcache = memcache.Client(['10.10.10.45:11211'])
>>>datavar=”some data here”
>>>memcache.set(’1234′,datavar,60)
>>>memcache.get(’1234′)

’some data here’

Ref: http://dev.mysql.com/doc/refman/5.1/en/ha-memcached-interfaces-python.html

Do the same above to connect from remote machine…

Uncategorized

Sub-process /usr/bin/dpkg returned an error code (1)

August 14th, 2009

Error uninstalling/installing Ubuntu package.

If you have a problem with a certain package run this…

sudo dpkg -r <packagename>

Then reinstall with apt!

Uncategorized

Python: Tuples vs Lists

August 13th, 2009

Tuple are immutable. Lists are mutable.

a=(1,2,3) #tuples have ()
a[0]=100

Error! Tuple values cannot be changed!

a=[1,2,3] #list have brackets
a[0]=100

success!

Note: dicts have curly braces ie: a={}

Uncategorized