Thursday, May 31, 2012

Issues after installing VirtualBox 4.1.16

After upgrading to VirtualBox 4.1.16 on my Windows 7 laptop, I found several issues.
  • My Guest "Host-Only Network Interface" stopped working.

    IP address for my guest CentOS 5.6 was, but CentOS said the address was already occupied. I found that there WERE processes in Resource Monitor using that address and listening on 137/138/139. It turns out that my "VirtualBox Host-Only Network adapter" was using

    Here is how you can access Resources Monitor:

    • Right click task bar
    • Start Task Manager
    • Performance
    • Resource Monitor
    • Network
    • Listening Ports

    After installing/uninstalling VirutalBox several times, "VirtualBox Host-Only Network" adapter went back to

  • Then another weird thing happened: I lost all printers and couldn't even access any Window File server. After several tries, I found that Network feature "Client for Microsoft Networks" were gone for "Local Area Connection" and "Wireless Network Connection". I forget if I deleted it or it was deleted during upgrading VirtualBox. Installing "Client for Microsoft Networks" restored my printers and I can access all file servers.

Wednesday, May 30, 2012

Setup Git-P4 using puppet

git-p4 is included into git RPM in CentOS 5.6, but it is not setup by default. Here is my puppet module for setup git-p4:
class git (
  $version = ""
) {

  package { "git-$version":
    ensure => present

  file { "/usr/local/bin/git-p4":
    source => "/usr/share/doc/git-$version/contrib/fast-import/git-p4",
    mode => 0755,
    require => Package["git-$version"]


Git-p4: create a new project in Perforce

The wiki and tutorial of Git-P4 usually ask you to clone a project from perforce. Can I create a new project in git and import it into Perforce using Git-P4? I don't know if there is a better way to do it. Here is how I do it:
  • Create a new p4 client spec: bewang-my-app-ws with this map "//depot/my-app/... //bewang-my-app-ws/..."
  • Create a p4 workspace directory: ~/p4-ws/my-app
  • Create .p4config with one line "P4CLIENT=bewang-my-app-ws" under ~/p4-ws/my-app
  • Create a new file in ~/p4-ws/my-app, and check it into perforce.

    Although you can see a Perforce file in nested folders/directories, but there are not such objects (folders/directories) in perforce indeed. You cannot just create an empty folder and check it into Perforce.

    This step creates the depot folder. Otherwise you may see this error when you run "git p4 rebase":

    [bewang@pmaster my-app]$ git p4 rebase 
    Traceback (most recent call last):
      File "/usr/local/bin/git-p4", line 1926, in ?
      File "/usr/local/bin/git-p4", line 1921, in main
        if not
      File "/usr/local/bin/git-p4", line 1716, in run[])
      File "/usr/local/bin/git-p4", line 1673, in run
        changes = p4ChangesForPaths(self.depotPaths, self.changeRange)
      File "/usr/local/bin/git-p4", line 442, in p4ChangesForPaths
        assert depotPaths
  • Create a folder for git repository: ~/git/my-app
  • Copy ~/p4-ws/my-app/.p4config to ~/git/my-app/.p4config
  • Run "git p4 clone //depot/my-app ."
  • You should see the file you just checked in and .git folder under ~/git/my-app
  • Work on your git repository
  • Run "git p4 rebase" before you want to check-in into perforce
  • Then run "git p4 submit" to submit each git commit to perforce
  • I can totally work offline without Perforce server

Thursday, May 17, 2012

Implements CORS using Backbone.js and Rails3

I encountered "406 Not Aceeptable" issue when my Backbone.js application fetch models in json from Rail server using CORS. Because this is a CORS call, I always doubt if something is wrong in my CORS headers, but it is Rails who causes the problem, because it tries to handle the request as HTML, see the log:
Started GET "/components/1" for at 2012-05-14 07:48:08 -0700
Processing by ComponentsController#show as HTML
  Parameters: {"id"=>"1"}
Completed 406 Not Acceptable in 1424ms (ActiveRecord: 1283.8ms)
The reason why I got this error is that my application is supposed to accept and respond JSON only. So my controller only responds a JSON result.
  def show
    @components = ComponentModel.today_component_status(params[:id]).first
    respond_to do |format|
      format.json { 
        render :json => @components 
This page is very helpful on stackoverflow: