Saturday, August 20, 2011

Let your computer say hello

CreateObject("SAPI.SpVoice").Speak "Hello"

Output into a .wav file

set x = createobject("SAPI.SpVoice")set ofs = createobject("SAPI.SpFileStream")ofs.Open "msg.wav", 3, vbFalseset x.AudioOutputStream = ofsx.Speak "Try me"

Output what you input

Dim message, sapimessage=InputBox(“Enter the text you want spoken”,”Speak This”)Set sapi=CreateObject(“sapi.spvoice”)sapi.Speak message

Saturday, August 13, 2011

Http Download with Python

Simple download

import urlliburllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3")

Download with progress

 import urllib2url = "http://download.thinkbroadband.com/10MB.zip"file_name = url.split('/')[-1]u = urllib2.urlopen(url)f = open(file_name, 'wb')meta = u.info()file_size = int(meta.getheaders("Content-Length")[0])print "Downloading: %s Bytes: %s" % (file_name, file_size)file_size_dl = 0block_sz = 8192while True:    buffer = u.read(block_sz)    if not buffer:        break    file_size_dl += len(buffer)    f.write(buffer)    status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)    status = status + chr(8)*(len(status)+1)    print status,f.close()

Friday, August 12, 2011

Best web browser for old computer

If you have a old computer like mine (1.6GHZ, 512 Memory & 30GB) & looking for a decent web browser. I strongly recommend Opera 11, this version is much faster than any modern browser, firefox 5, ie 9, google chrome even safari.

This was really surprised me yet after test all those browsers on my computer, Opera is the fastest web browser that I have tested.

http://www.opera.com/browser/

Thursday, August 11, 2011

Recursive syntax check with php command line

find . -name \*.php -exec php -l “{}” \;

.Net Assembly Redirection

Sometimes, we need redirect an assembly to a different version, we can do it like this:

<?xml version="1.0" encoding="utf-8" ?><configuration>    <runtime>        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">            <probing privatePath="libs"/>            <dependentAssembly>                <assemblyIdentity name="MathLibrary"                    publicKeyToken="8210BDCE54DAB3C2"/>                <bindingRedirect oldVersion="1.1.1.1"                    newVersion="1.1.2.2"/>            </dependentAssembly>        </assemblyBinding>    </runtime></configuration>

 

In element “probing, “privatePath” is additional seraching path for assemblies.

In element “assemblyIdentity“, “name” is the assmebly you want to redirect, “publicKeyToken” is its public key. So the assembly must be strong-named to make a redirection.

After set the assembly, you can make your redirection. In element “bindingRedirect“, use “oldVersion” & “newVersion” to redirect it.

 

Friday, August 5, 2011

Connect to mysql database using python with MySQLdb cursor

import sysimport MySQLdbimport MySQLdb.cursorsconn = MySQLdb.Connect(    host='localhost', user='vroom',    passwd='vroom', db='vroom',compress=1,    cursorclass=MySQLdb.cursors.DictCursor)cursor = conn.cursor()cursor.execute("SELECT * FROM posts")rows = cursor.fetchall()cursor.close()conn.close()for row in rows:    print row['title'], row['create_date']

Tuesday, August 2, 2011

Execute PHP script in background mode in Windows

Create a .vbs file

Dim objshellSET objshell = WScript.CreateObject ("WScript.Shell")objshell.run "c:\php5\php.exe YourPHP.php", 0SET objshell=Nothing

And execute this vbs file in windows schedule task manager