Email Me
The University of Texas at Austin

Useful Snippets

Java:

Clip - April 4, 2012

Tiny program with a single static method that copies a string you pass in to the clipboard. Can be used for things like copying long solutions to Project Euler or for using in other applications that need to access clipboard: Clip.java

Python:

Batch Image Resize - June 27, 2013

Resize either a single image or many images to a new width. Takes into account portrait and landscape mode so specified width may become height in some pictures. Can be used to resize high resolution photos for web/publishing, or in my case resizing images so they could be emailed: resize.py
*(Uses Python Image Library for resizing images)

Convert ANSI-Chinese Files to UTF8 - July 13, 2013

I watched a lot of Netflix with my parents over the summer, but unfortunately they don't speak or understand English. Luckily, there are a lot of websites that offer Chinese subtitles (e.g. shooter.cn). The bad part is, most of these .srt files are encoded in one of four formats: big5, gb2312, gbk, or gb18030. None of which are readable by a Windows machine not set in that locale, even if the language pack is installed. In the beginning, I would open each file in Microsoft Word, have it auto detect the format, copy into clipboard, paste into Notepad, and then save as a UTF-8 file. For TV shows, this got tiring very fast. I looked high and low for a solution online but no seemed to have the same problem. Since I was taking an online Python course, I decided to code up my own solution. In Windows, you can just drag and drop one or more subtitle files directly onto the script. Otherwise, just execute the script with the filenames as parameters: convertutf8.py
*(Uses python-jianfan library for translating Simplified Chinese to Traditional Chinese)

Jonathan Lee
University of Texas at Austin
Phone: 214.609.0803