Category Archives: Tips & Tricks

Java Build System for Sublime Text 3

The Problem

Sublime Text is my primary text editor and I often need a build system which let me compile the source then run it if success. The build system ships with Sublime Text only compile.

Continue reading

Advertisements

How to type Vietnamese on Windows 7

Typing Vietnamese on Windows 7 does not require any third-party software. All we need is to enable the Vietnamese keyboard and learn how to type special characters.

Installation

Image

Open Control Panel and click on Clock, Language and Region.

Image

Click on Change keyboards or other input methods at the bottom of the right pane.

Image

Click Change keyboards…

Image

In the Text Services and Input Languages window, click Add…

Image

Select Vietnamese from the list and click OK.

Image

We will see the Vietnamese keyboard added. Click  OK and we are done with the installation.

 

How to Type Vietnamese Text

The first step is to switch the keyboard from English (or your current language) to Vietnamese.  Look at the bottom of right of the screen, we will see “EN” for English. Click on it and select “VI” for Vietnamese.

Image

 

Next, we will learn how to type special Vietnamese characters:

Huyền = 5
Hỏi = 6
Ngã = 7
Sắc = 8
Nặng = 9

ă = 1
â = 2
ê = 3
ô = 4
đ = 0
ư = [
ơ = ]

Good luck.

 

How to Install .apk File onto an Android Device

The Problem

I am new to the Android platform. At work, I need to side-load our app for testing. My device is an HTC one of 2012. At first, I installed and ran the HTC Sync Manager from my MacBook Pro with hope that it could help me, but after half an hour, I gave up: I copied the .apk file to the file section, sync, then check the phone: I could not find that .apk file anywhere. It could be me, but for the life of me, I could not find a way to copy the file in question onto the device. There must be a better way.

My Solution

As I stated before, the problem is with me being a novice. However, I did spend a good half an hour googling for solutions to no avail. Finally, an idea came to me: what if I can transfer the file from my Mac to the HTC One via HTTP? With that though, I opened up a terminal session, cd to the directory where my .apk file is, and issued the following command:

python -m SimpleHTTPServer

That command created an impromptu web server to serve all the files within the current directory. From the HTC One, I fired up a web browser and jumped to my server: haiv-mac1.local:8000 and expected to see the directory listing. However, I could not connect to my Mac at all. Frustrated, I tried again and again, prepending http:// to the address, check my spelling, knelt down and prayed… But nothing worked. I tried the same address using my iPhone and it works. So the problem was with the Android device. Finally, I was able to connect using my Mac’s IP address. How I love Android!

Once I downloaded the file, it was a simple matter of tapping the Downloads icon, find my file, and tap on it to install.

Conclusion

I like the Android platform for giving me the ability to side-load apps, which is great for testing. However, the process could be simpler. Veteran Android users and developers might laugh hearing this story, but it is no joke to me. Until I gain enough expertise, I’ll stay with my trusty iPhone.

Drobo Saved My Day for the Third Time

A few hours ago, I went home to see one of the lights on my Drobo blinking in red color: one of my hard drives in the Drobo has died. For those who don’t know, a Drobo is an external hard drive enclosure which houses five (in my model) 3.5-inch hard drives. Drobo offers protection against drive failures such as the one I am currently experienced.

In the old days, a failed hard drive meant data loss—that is how I lost several photographs and video clips of my family. When I lost my first batch of files due to hard drive failure, I got wiser and backed up my desktop’s hard drive. Sadly, when my hard drived failed the second time, I found out my back-up CDs (those old days) also turned bad. For years, I struggled with back-up solutions, none were reliable enough for my use. Then came Drobo.

The first time I saw this black box, I knew it should be part of my data storage and back up plan. The initial price for the empty Drobo S, my model, was nearly 700 USD—a very steep price indeed. However, the more I thought about my past incidents, the more sense the Drobo makes. Finally, I bit the bullet and purchased one. Let me cut right to the point: I experienced today’s episode twice before, and had not lost a single file due to hard drive failure. I believe that was the best $680 I have ever spent.

Tonight, I will replaced the doomed drive knowing that my Drobo is working hard to ensure my data integrity. My Drobo has saved my day yet again.

How I Name My Printers

At home, we have two printers that I set up so the whole family can print. Their names were HP LaserJet xxx and Epson xxx, the default my OS gave them. Things were fine until my wife and kids start asking me which one is the color printer.

What? Don’t they know that the Epson printer is the color one? The truth is, for the people who wants to print, they don’t care if the printer is laser or inkjet, made by HP or Epson. All they care about is which one can print in color and which one cannot.

Finally, I named them Black & White Printer and Color Printer. This makes a lot of sense for them: they don’t have to wonder which one is which. It also releases me of the answering duty.

Easy Way to Create Colorful Bash Prompt

The Problem

I often want to fiddle with the bash prompt, but don’t want to deal with bash prompt escape sequences. I wish for a utility which simplify setting a bash prompt. I finally wrote that utility myself: mkprompt

Install

Copy mkprompt to a directory in the path.

Using mkprompt

The best way to show mkprompt usage is via a couple of examples.

PS1=$(mkprompt "red workdir" space dollar)  
PS1=$(mkprompt "cyan Workdir" space "green dollar")  
mkprompt # display help

For more information, see my shell_tools page.

What’s Next?

The following are improvements which I plan for mkprompt, depends on my free time:

  • Implement the rest of the prompt escape sequences
  • Improve the help output
  • Implement installation script

The Script

I current host my script as part of my shell_tools collection on GitHub.

Squeeze Multiple Blank Lines within vim

The Problem

I want to squeeze multiple blank lines into just one while editing in vim. I often receive source code which the author used multiple blank lines to separate functions. I don’t mind if functions or code block are one or two lines apart, but I have seen sources where functions are four or more blank lines from each other. This is annoying and I want to squeeze many of them into one.

The Solutions

The obvious solution is to use vim’s search-and-replace feature, as discussed in this post. However, my regular expression skill is very basic and I tend to forget the syntax when I need it. Hence, I devised my own solution, one which I have better luck memorizing.

My solution involes the cat command:

:%!cat -s

This short little command applies ‘cat -s’ on my entire file contents, which squeezes multiple blank lines down to one. Note that this solution will only work on Unix-like systems such as BSD, Linux, and Mac OS X. It does not work on Windows. This is one of the shortcoming of this method compare to the previous one.

Upgrade My Mac’s Hard Drive

My 4.5 year-old MacBook is getting slower every day due to its age against the new OS and applications. To give it a new lease in life, I replaced its 500GB hard drive with a 120GB SSD from OWC. This post discusses the upgrade process.

Before the Upgrade

Unwind Applications

This step disconnects the applications from their services. For example, I de-authorized my iTunes account after one last sync with my iPhone. I also disconnected from Dropbox, quit Mail. I quitted all applications which connects to the internet to ensure their data not to change during the back up. I also took note of the Dropbox’s user name and password, along with the password to my 1Password data file. These information are crucial for bringing my system up after the upgrade.

Prepare Applications List

This step is crucial. I made a list of applications I installed on my MacBook. I also hunt down all the license keys to allow me to reinstall later. Since I store my license keys in 1Password, this step is relatively simple. I then prioritize my applications list: priority means I must have them. 1Password and Backblaze back up falls into this category. Priority 2 means I should have them for my every day tasks: Aperture, Path Finder, and Alfred are examples in this category. Applications that do not fall into these two categories will be installed only when absolutely needed.

Back up Data

Next, I disconnected my internet connection to ensure no data change during the back up. I then created a bootable clone of my hard drive using SuperDuper. This is the last snapshot of my old hard drive. This step also means that after upgrade, I will have two copies of my old hard drive. I will keep one of those copies in case I ever need any old data from it.

Upgrade and Post Upgrade

I will not discuss the actual replacement of the drives as there are several how-to videos showing this procedure–just search for them.

Install the Operating System and Updates

After installing the new drive, I installed the operating system from the disc. Then connect to the internet and run software update. This step might spans several minutes.

Restore Dropbox and 1Password

Since I stored my 1Password’s data in Dropbox, I connected to the internet, downloaded Dropbox, installed it, copied the Dropbox data from the old drive to the new, and brought Dropbox online. Next, I downloaded and installed 1Password. Amazingly, the first time I launched 1Password, the application found its data from the Dropbox folder and asked me if I want to use it. After saying yes, I got all my 1Password back as if the upgrade never occurred. I have the 1Password team to thank for that.

Restore Other Applications and Data

Most applications store their data in ~/Library/Application Support, so after re-installing the application and before the first launch, I copied the data from the old drive over to the new drive at the same location and applications will pick up where they left off. Many people suggested to use Apple’s application migrations, but I don’t want to use it because I need the absolute control of which application to move. Besides, I am more comfortable with this level of details. If you are not familiar with the file structure of Mac OS X, you should use application migration.

Lessons Learned

  • Backup, backup, backup. My drive were backed up by three means: The Backblaze online service, SuperDuper and Time Machine. Over the years, I had lost many valuable family photos and videos due to the lack of backing up. I made that mistake twice (yes, its dumb.) With the new SSD, I keep all three back up methods. The Backblaze backup is especially useful because it is offsite.
  • Preparation ensures smooth transition. By taking notes of the essential services’s user names and passwords, I was able to pick up quickly. By learning the data location of my applications, I avoided headaches of not having my data migrated.
  • Only installed application when absolutely necessary. This time around, I not install applications just because it is cool. This will save me from bloating my hard drive and operating system, slowing down my already-aging MacBook.
  • 1Password is a life-saver, especially for storing my applications’ license. Some applications, such as Hazel, store their keys in a file, which 1Password can also handle via the attachment feature. Go 1Password!

Use subst to Deal with Long Path Names

The Problem

I want to shorten the paths to a directory that is buried deep in the file system. In my daily work, I often need to cd into such directory as long as:

C:\projects\tests\utilities\fileutil

Although Windows command line has file name completion, it is still a long and tedious process to change into and out of these directories.

The Solution

There are several solutions, such as using environment variable to point to the destination directory, or to create alias to cd there (via doskey). My favorite solution uses subst to substitute the long path with a drive letter:

subst F: C:\projects\tests\utilities\fileutil

From this point on, I can switch to this long directory using the shorter drive alias. Instead of

cd C:\projects\tests\utilities\fileutil

I can get to it by changing the drive:

F:

By using a drive to access a deeply buried directory, I also get around the problem of 260-character path name limit in Windows.