Saturday, April 20, 2013

New Posts on Gists

Here are some new JavaScript articles on my github's Gist:

https://gist.github.com/lucastan

I may start posting to Gist more often since it has more builtin code friendly features like syntax highlighting.

Sunday, February 10, 2013

Configuring a development environment for Mac OS X

Here are the steps I took for installing and configuring the various tools I needed for C++/C and Java development in Mac OS X:

  1. Terminal
    1. iTerm2 is recommended over the native Terminal as it is more Linux-compatible.
    2. Configure ~/.bash_profile and put your favorite aliases in it.
    3. Add color to your terminal. There is also a cool LS color generator
    4. Configure ~/.vimrc if you use vim/vi :)
    5. Add syntax on to ~/.vimrc if you want color syntax highlighting.
  2. Git
    1. If you use git for source control, then google for and download it. Installation is straightforward.
    2. Don't forget to do git config --global user.name / user.email
    3. To add color to git output, do this: git config --global color.ui true
  3. SSH keys
    1. SSH keys are needed for git. 
    2. mkdir -p ~/.ssh ; pushd ~/.ssh ; ssh-keygen -t rsa -C "your_email@youremail.com"
    3. Upload the generated public key to your github / bitbucket account.
  4. XCode (clang/clang++, gcc, g++, make, ...)
    1. Install XCode from the App Store. (You'd need an Apple ID)
    2. Put XCode in your dock.
    3. After installation, open XCode, and go to Preferences -> Downloads from the menu bar.
    4. Click to install Command line tools.
    5. Be warned that the version of gcc that shipped with XCode 4.6 (latest as of now) is only 4.2.1 (July 2007), without any support for C++ TR1 and v11. It is seriously ancient. clang on the other hand is relatively newer (LLVM v3.2). I guess they are conservative about g++'s unstable support for C++ 11.
  5. Java
    1. JDK and JRE come installed by default.
    2. Type javac -version and java -version to check their versions.
    3. You'd probably want to install an IDE such as Eclipse.
  6. Ruby / Perl / Python / PHP
    1. Also, these come installed by default. There is also the Apache web server!
    2. Actually, in general, don't expect default-packaged software to be bleeding edge. I haven't tried replacing the default copies yet so I can't tell you how to.
  7. Homebrew (Package manager)
    1. Check out this awesome package manager which is similar to Ubuntu's apt-get.
    2. You use this to install your favorite utilities such as pkg-config, wget, dos2unix and etc.
  8. Sublime Text
    1. This is my personal favorite programmer's text editor that functions like a mini IDE, with simple building functionality and folder browsing. Pretty much reminded me of Notepad++ in Windows!
  9. TextWrangler
    1. In my opinion, this is pretty good but lacks the building and folder browsing ability.
  10. pkg-config (Forget this if you wanna use homebrew)
    1. This handy tool spits out the gcc/g++ compatible compilation/linking flags for specified libraries.
    2. Download and install from http://macpkg.sourceforge.net/
    3. This installer installs to /opt (instead of /usr/local)
    4. Add pkg-config to the path (system-wide):
      1. Create a file /etc/paths.d/pkgconfig with /opt/pkgconfig/bin as its content.
    5. Configure the PKG_CONFIG_PATH environment variable. You'd probably want to set this environment variable system-wide. I have this set to /usr/lib/pkgconfig:/usr/local/lib/pkgconfig
Other stuff:
  1. UI enhancements: such as adding a spacer to your dock and making lists look better.
  2. Multi-media
    1. uTorrent for your ahem, ____ needs.
      1. Don't forget to enable IPFilter. In the main window, do Command+Option+, to bring up the options window with the advanced tab. Set ipfilter.enable to true.
        You can get the ipfilter auto updater 
    2. Spotify, for music to help keep you sane while you code away.
    3. VideoLAN, the ultimate video player that can handle almost every format.

Friday, February 8, 2013

More tips on Chrome

If you're curious, you can take a look at chrome://chrome-urls/
This has lots of information on the internal workings and statistics

Thursday, February 7, 2013

Configuring Google Chrome cache size in Mac

Just bought a new MacBook Air for ~S$2100 (inclusive of GST) and it felt great! I initially had a struggle with the high cost, but finally decided to part with my money for this sexy machine. It is indeed awesome, sleek, easy to use and definitely worth every cent that is spent!

The first thing I had to install is Chrome. I recently found that Google Chrome stores old copies of itself after every auto-update, even if the update is very minor, for e.g., from version 23.0.0.1 to 23.0.0.2. Each copy could take up 100-200 MB and several of them could easily add up to say, 1 GB of disk space! These old copies could be safely deleted if you care about the wastage of disk space.

To do so, if you're using Windows, you can simply go to C:\Program Files (x86)\Google Chrome\ (or a similar path) and delete the folders with versions as their names. If you're using Mac, you can go to /Applications/Google Chrome.app/Contents/Versions (if you installed in that location). Well, actually I'm not even sure whether the Mac version of Chrome stores old copies of itself in there. And sorry folks, I don't know the location for the *nix version. :(

Another nuisance for a disk-space-conscious person like me is that Chrome is configured by default to use an unlimited amount of disk space for its cache! Fortunately, you can limit the cache size by adding the command line argument --disk-cache-size=XX in the shortcut to Chrome (in Windows), where XX is the size in MB. In Mac, this is a bit more involved. But fret not, just follow these steps:

  1. Close all Chrome windows and quit the entire application before you proceed with the steps below.
  2. Go to /Applications/Google Chrome.app/Contents and open the file Info.plist using a text editor.
    • In case you have difficulty in even going to that folder, you'd have to select "Browse Package Contents" after right-clicking on Google Chrome.app (the large Chrome icon) in Applications.
  3. Find the following text:
    • <key>CFBundleExecutable</key>
    • <string>Google Chrome</string>
  4. Replace Google Chrome with wrapper and save the file.
  5. Next, go to ..../Contents/MacOS and create a plain-text file named wrapper
  6. In the file wrapper, add the following contents and save it:
    • #!/bin/sh
      /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$@" --disk-cache-size=50 &
  7. Please ensure the path to Google Chrome.app is exactly correct. Every single space counts. In case you're wondering, the sequence "\ " is used to escape a single space. If you don't know what escaping is, it's fine. Just take it that you have to replace all spaces with "\ " (without the quotes). You can also change the number 50 if you wish.
  8. Viola! You're done. Click the Chrome icon in your dock to open it.