Monday, February 02, 2009

Helpful Python Methods

import os

def getFreeSpace(path):
  # Gets the number of free bytes in the given path
  st = os.statvfs(path)
  return st.f_bsize * st.f_bavail

def getFileSize(filepath):
  # Gets the size of the file in bytes
  try:
    st = os.stat(filepath)
except IOError:
print "Failed to get size of", filepath
else:
return st[6]

Wednesday, January 07, 2009

Disable Image Dragging in Firefox 3

Put this line inside the image tag:

onmousedown="if (event.preventDefault) { event.preventDefault(); }"

Counting Files Recusively In Linux

Just change the .mp3 extension below.

$ ls -1R | grep -i .*.mp3 | wc -l

Tuesday, January 06, 2009

Performing / Managing Background Jobs in Linux

To perform processes in the background in Linux, use the command screen (instead of the session-tied-up nohup).

Screens are terminal sessions which can be detached (placed in the background) and reattached (placed in the foreground). When detached, these screens still run and can be brought back again for use in future connections.

Command list:

screen -list
     Displays all the running screens and their socknames
screen -S
     Creates a new screen with as the name instead of a generated one
screen -r
     Reattaches a detached screen

When a screen is attached, you can either use..

Ctrl+A then Ctrl+D to detach the current screen, or
Ctrl+D to terminal the screen.

Connecting to CVS Using Alternate Port With SSH Tunneling

Create / Modify the file ~/.ssh/config and add the lines:

Host 123.123.123.123
Port 56789


Then use the following connection string in bash:

$ cvs -d :ext:username@123.123.123:/home/devel/cvs ...

Sunday, November 09, 2008

IE Blocks IFrame Session Cookies

I had trouble persisting session data between two transitioning pages in an iframe in IE (7+ i think). The page in the iframe and the parent page (containing the iframe) are in two different domains.

For the browser to allow the cookie in PHP, just add:
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

Source:
http://adamyoung.net/IE-Blocking-iFrame-Cookies

Wednesday, July 30, 2008

Bug: Zend Framework 1.5.1-1.5.3 Zend_Rest_Client

When contacting the Rest Server via the Zend_Rest_Client's get() method, you will get errors when passing a string argument that's roughly 500+ characters long.

The code:
$client = new Zend_Rest_Client($restServer);
// $arg1 has 1000 length
$result = $client->MyMethod($arg1, $arg2)->get();

would yield:
string '

Invalid Method Call to MyMethod. Requires 2, 1 given.

failed
'
(length=242)

You can get the data sent back from contacting the rest server by dumping the variable $data before line 43 in Zend/Rest/Client/Result.php (ZF 1.5.3):
var_dump($data);

Fix:
Use the method post() instead of get().