Friday, March 28, 2008

Start Windows Installer Service in Safe Mode

Some software messed up some Windows system files and I couldn't log on any more. Wanting to remove the software, I logged into safe mode, just to find out that Windows Installer service is not allowed to run in safe mode! Good design.

After spending some time searching, I found a solution:

To start Windows Installer in Safe Mode:
1. Restart your computer and press F8 before the Boot Menu or splash screen.
2. Open a CMD.EXE window.
3. Type the following commands and press Enter:

REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Minimal\MSIServer" /VE /T REG_SZ /F /D "Service"
net start msiserver

NOTE: You can use this technique to uninstall an application in Safe Mode.

Friday, March 21, 2008

Print UTF-8 Characters in Eclipse Console

In eclipse, "Run Dialog", "Common" tab, change "Console Encoding" to UTF-8. The code below should print some CJK characters.


import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class TestClass {

public static void main(String [] args) throws UnsupportedEncodingException {
String chineseString = "\u4e00\u4e01\u4e02\u4e03\u4e04";
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
ps.println(chineseString);
}
}

Friday, January 11, 2008

Use a proxy with urllib2

This snippet from Rob Wolfe:

import urllib2

def getopener(proxy=None):
opener = urllib2.build_opener(urllib2.HTTPHandler)
if proxy:
proxy_support = urllib2.ProxyHandler({"http": "http://" + proxy})
opener.add_handler(proxy_support)
return opener

def fetchurl(url, opener):
f = opener.open(url)
data = f.read()
f.close()
return data

print fetchurl('http://www.python.org', getopener('127.0.0.1:8081'))
print fetchurl('http://www.python.org', getopener()) # without a proxy