Wednesday, September 23, 2009

python: writing your own urllib2 redirect_handler

class SmartRedirectHandler(urllib2.HTTPRedirectHandler):

    def redirect_request(self, req, fp, code, msg, headers, newurl=''):
        global intermediateURL
        intermediateURL = newurl

        if code in (301, 302, 303, "refresh") or (code == 307 and not req.has_data()):
            newRequest = urllib2.Request(   
                                            newurl,
                                            headers=req.headers,
                                            origin_req_host=req.get_origin_req_host(),
                                            unverifiable=True
                                        )
            newRequest._origin_req = getattr(req, "_origin_req", req)
            
        return newRequest
        
        else:
            raise HTTPError(req.get_full_url(), code, msg, headers, fp)

source

Tuesday, September 15, 2009

how to enable tap zones on dell mouse drivers

To unlock the native touchpad features which are masked by Dell's touchpad software:

1. Go to control panel and select MOUSE to see what options are available (very few) and close that all up.

2. Next click on the Windows Start icon and type regedit in the search box.
Windows Registry will open.

Navigate to HKEY_LOCALMACHINE\SOFTWARE\Alps\Apoint and look for the key UseCustomGUI (it's the 2nd to last entry on the list)

Change the value from 1 to 0 and click on OK

3. Next minimize the registry (don't close it yet).
Goto Control Panel and select MOUSE.
Now all the ALPs settings are unlocked and appear here.

For example the GESTURES feature is now showing.
Select GESTURES tab and check ON the box for
Use Back/Forward Buttons.
Then click APPLY and OK.
Close the Mouse settings and close the Control panel.

4. Now go back to your registry setting and change
UseCustomGUI back to it's original value of 1 and close it and the reg editor.

Everything is back exactly as it was but the feature remains enabled.

All done....now when your surfing just swipe your finger along the top edge of the touch pad to go back and forward.


source

Monday, September 14, 2009

vbscript: create system restore points with no fuss

Here's how to create a simple VBscript that will create a restore point when you double-click it:

1. Save the code below to, say, c:\system_restore.vbs:

Set SRP = GetObject( "winmgmts:\\.\root\default:Systemrestore" )
CSRP = SRP.CreateRestorePoint( "Before Changes", 0, 100 )

2. Double-click the script file you just created, any time you want to create a fresh System Restore Point.

It only takes a few seconds to do this. And no dialogues are shown to confirm that a Restore Point was created. If you want to double-check you can click "Start | All Programs | Accessories | System Tools | System Restore" and click "Restore My Computer To An Earlier Time."

You'll see the restore point you just created (called "Before Changes") right there. Now be sure to cancel out of System Restore.

source

Tuesday, August 25, 2009

linux: creating and using arrays in shell scripts

Bash arrays have numbered indexes only, but they are sparse, i.e. you don't have to define all the indexes.

An entire array can be assigned by enclosing the array items in parenthesis:
arr=(Hello World)

Individual items can be assigned with the familiar array syntax (unless you're used to Basic or Fortran):
arr[0]=Hello
arr[1]=World


But it gets a bit ugly when you want to refer to an array item:
echo ${arr[0]} ${arr[1]}

To quote from the man page:

The braces are required to avoid conflicts with pathname expansion.

In addition the following funky constructs are available:
${arr[*]};  # All of the items in the array
${!arr[*]}; # All of the indexes in the array
${#arr[*]}; # Number of items in the array
${#arr[0]}; # Length of item zero

The ${!arr[*]} is a relatively new addition to bash, it was not part of the original array implementation.

source

Monday, August 24, 2009

vim: commenting-out lines of code esaily

For short ranges of basic prefixing comments (# or //), I've become fond of vim's visual block mode and block insert. To do this:
  1. start visual block mode (with Ctrl-V)
  2. adjust the selection with movement keys as needed. (marks can be used here)
  3. once the selections are made, start block insert with 'I' (or append with 'A')
    NOTE: don't use the usual lowercase 'i' or 'a'
  4. type the comment text (e.g. "#")
  5. when you hit escape, comments will be added to all selected lines

source

Tuesday, August 11, 2009

nice quote about indesign

Adobe has always said that InDesign is “the future of page layout”—but we think they’re selling themselves a bit short. With InDesign, the future is here today.

And, to our eyes, at least, it looks pretty cool.

source: "Real World Adobe InDesign CS4" (Kvern and Blatner)

Monday, August 3, 2009

linux: rename multiple files with one command

We're going to do this simple task with a simple regex find+replace in sed:

for i in *.avi
do
    j=`echo $i | sed 's/mymovies/myflicks/g'`
    mv "$i" "$j"
done

Can also be written on a single line as:
for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

source