code snippets

List files in subdirectories as relative paths (in Windows)

@echo off
c:\msys\1.0\bin\find . -name .svn -prune -o -print | c:\msys\1.0\bin\sed "s/^.\///g" > _files
ls _files

Delicious posting bookmarklet for Firefox keyword

javascript:location.href='http://del.icio.us/new/yourusername?v=2&url=' +encodeURIComponent(location.href)+'&title='+ encodeURIComponent(document.title)+'&tags='+ encodeURIComponent('%s')

Colt Firefox extension link copy formats

HTML Link: <a href="%U">%T</a>
Article at: "%T" at %U
Wikipedia: [%U %T]

Git commands to track changes to a software installation

git init
git config core.autocrlf false
git add .
git commit -m "init"

Git: Push to remotes (add to .git/config)

[guitool "Push to remotes"]
	cmd = "git push github $REVISION; git push assembla $REVISION"
	revprompt = yes

Python to replace string in group of files

import os

def replaceText(fileName, oldValue, newValue):
    with open(fileName, "r+") as file:
        fileText = file.read()
        if fileText.find(oldValue) != -1:
            print ("Found %r in %s" % (oldValue, fileName))
            newFileText = fileText.replace(oldValue, newValue)
            file.seek(0)
            file.truncate()
            file.write(newFileText)

def replaceTextInFiles(dir, extensions, oldValue, newValue):
    for dir, subdirs, files in os.walk(dir):
        print("dir = %s" % dir)
        for file in files:
            fileName = os.path.join(dir, file)
            print(" file = %s" % fileName)
            includeFile = False
            for extension in extensions:
                if fileName.endswith(extension):
                    includeFile = True
            if includeFile:
                print(" file = %s" % fileName)
                replaceText(fileName, oldValue, newValue)
            else:
                print(" (skip %s)" % fileName)

# replaceTextInFiles("c:/mydir", [".ext1", ".ext2", ".ext3"], "old", "new")