Monday 31 December 2012

Mount DVD drive in Ubuntu

mount /dev/cdrom [dir]
In my case, I mount it in the existing media directory.

Monday 10 December 2012

Playing videos in Ubuntu

Recently I've been having a problem playing videos in Ubuntu: all I see is a green screen. This happens for Totem Movie Player, mplayer and VLC. So far I fixed the problem in VLC. What I need to do is  to go to Tools > Preferences > Video and choose X11 video output (XCB) under Display Output. Un-checking the "Accelerated video output (Overlay)" works too. Using Xvideo as the output will cause the green screen.

Another useful tool for converting ogv file to high definition mp4 file is Arista Transcoder. You can install it from Ubuntu Software Center.

Also I installed all the libraries for media support mentioned in this post: 3 things to do after installing or upgrading to Ubuntu 12.04. Now I can also play mp4 file in the Chrome browser.

Thursday 6 December 2012

Video and audio conversion

For video conversion, avidemux is a good tool. Today I used it to rotate a mp4 video by 180 degrees. The instructions can be found here.

For audio conversion, soundconverter is good. I used it to convert a wma file to mp3. The instructions can be found here.

Wednesday 28 November 2012

Tuesday 13 November 2012

Buying air miles is a bad idea

For United Airlines, a saver award round trip ticket from Boston to Shanghai requires 65,000 miles. The round trip usually costs around $1000. This means 1 mile is worth $0.015. When I buy miles, each mile costs $0.035. So it's not worth it to buy miles.

I made the mistake by considering how much it costs to earn miles through taking flights. But earning miles this way is basically free because I'm taking the flight anyways.

So in conclusion, it is almost always a bad idea to buy air miles.

Thursday 1 November 2012

Law of total probability

If \(\{B_n:n=1, 2, 3, \ldots\}\) is a finite partition of a sample space (i.e., a set of pairwise disjoint events whose union is the entire sample space), then for any event A of the same probability space:
$$Pr(A) = \sum_n Pr(A\cap B_n)$$
or, alternatively,
$$Pr(A) = \sum_n Pr(A|B_n)Pr(B_n)$$

Decision Tree

Decision trees are classifiers for instances represented as feature vectors. Nodes are tests for feature values. There is one branch for each value of the feature. Leaves specify the category.

The central choice in the algorithm to build a decision tree is selecting which attribute to test at each node in the tree. We would like to select the attribute that is most useful for classifying examples. A good quantitative measure of the worth of an attribute is information gain, which measures how well a given attribute separates the training examples according to their target classification.

Information gain is related to entropy, that characterizes the (im)purity of an arbitrary collection of examples. Given a collection S, containing positive and negative examples of some target concept, the entropy of S relative to this boolean classification is
$$Entropy(S)\equiv -p_\oplus \log_2 p_\oplus-p_\ominus\log_2 p_\ominus$$
where \(p_\oplus\) is the proportion of positive examples in S and \(p_\ominus\) is the proportion of negative examples in S.

Information gain  is simply the expected reduction in entropy by partitioning the examples according to this attribute. Gain(S, A) of an attribute A, relative to a collection of examples S, is define as
$$Gain(S, A) \equiv Entropy(S) - \sum_{v\in Values(A)}\frac{|S_v|}{|S|}Entropy(S_v)$$

Friday 19 October 2012

Kinect depth variance analysis


Here are the visualizations of absolute depth differences for each pixel for 40 frames using a Kinect. The setup is like this.

White color shows all pixels with absolute difference greater than 4mm

The high variance at the bottom right corner is due to the mouse which has a shiny surface and the Kinect does not work very well with shiny surfaces.  

White color shows all pixels with absolute difference greater than 2mm

White color shows all pixels with absolute difference greater than 1mm

Absolute depth variance shown as a heat map. The color changes from black, red, yellow and white as the value increases. The difference values are clipped between 0.8 and 2.

Monday 15 October 2012

Music I like

One of the Pandora stations I listen all the time is based on Lux Aeterna by Clint Mansell on Requiem For A Dream. The music is usually instrumental with electronic string ensembles and has classical influences .

Friday 12 October 2012

A review of smoothing techniques

Recently I need to smooth the Kinect-based finger tracking result. Without smoothing, there are a lot of jitters as shown in this demo video:

In searching for the best solution, I think it's good to have a review of different smoothing techniques. 

Simple moving average

$$s_t = \frac{1}{k}\sum_{n=0}^{k-1}x_{t-n}=\frac{x_t + x_{t-1} + ...+x_{t-k+1}}{k}=s_{t-1}+\frac{x_t-x_{t-k}}{k}$$

- Disadvantage: cannot be used on the first k-1 terms.

Weighted moving average

Give more weight to the recent terms in the time series. 
- Disadvantage: same as the simple moving average method, it cannot be used on the first k-1 terms. It also requires more complicated calculation at each step as it cannot be written as a inductive formula.

Exponential moving average

$$s_1 = x_0$$
$$s_t = \alpha x_{t-1} + (1 - \alpha)s_{t-1}$$

Exponential smoothing and moving average smoothing are similar in that they both assume a stationary, not trending, time series, therefore lagging behind the trend if one exists. Exponential smoothing also take into account all past data, whereas moving average only takes into account k past data points.

Double exponential smoothing

Double exponential smoothing can be used when there is a trend in the data.

Let {\(x_t\)} be the raw data sequence, {\(s_t\)} be the smoothed value for time t, and {\(b_t\)} be the best estimate of the trend at time t. The output of the algorithm is now written as \(F_{t+m}\). The formulae are:

$$s_1 = x_0$$
$$b_1 = x_1 - x_0$$

And for t>1
$$s_t = \alpha x_t + (1 - \alpha)(s_{t-1} + b_{t-1})$$
$$b_t = \beta(s_t - s_{t-1}) + (1 - \beta)b_{t-1}$$
where \(\alpha\) is the smoothing factor, \(0 < \alpha < 1\), and \(\beta\) is the trend smoothing factor, \(0 < \beta < 1\).



Wednesday 29 August 2012

Awesome WM configuration

Today I started to use Awesome on my desktop in the office. I've been using it for 3 months during my internship at Google and it was awesome! It requires a little bit of configuration at the beginning.

To make Awesome appear as a choice of WMs in the Ubuntu login screen, delete "NoDisplay=true" in /usr/share/xsessions/awesome.desktop. Apparently this is a bug in Ubuntu.

To create a user configuration file, copy the default one to the ~/.config folder:
$cd ~
$mkdir -p .config/awesome
$cp -r /etc/xdg/awesome/* .config/awesome
Note that there are some other files under /etc/xdg/awesome besides rc.lua, and you need to copy all the files. Otherwise there will be errors and the user configuration will be ignored (I tripped over this).

Configure screen locking
Install xscreensaver. Add the following lines to rc.lua.
# In globalkeys = ...
awful.key({ modkey }, "F12", function() awful.util.spawn("xscreensaver-command -lock") end)
# At the end of the file:
awful.util.spawn_with_shell("xscreensaver -no-splash")

Shortcuts

  • Close dialog windows: meta+shift+c

Sunday 5 August 2012

Granola

Recently I've been obsessed with granola. It's so delicious! But it's very high in calories. One cup of granola can have 500-600 calories. Oatmeal is much better than granola. Oatmeal has soluble fiber  that slows down digestion, making you feel full longer (this is a good characteristic in food that I should look for). Oats contain photochemicals, which are antioxidants that help eliminate free radicals.

Granola also has oats as its base, but it has added sugar which increases its calories a lot. So should eat oatmeal instead!

Sunday 1 July 2012

Recycling etiquette

I've been wondering about whether we need to wash the bottles or the cartons before putting them into the recycling bin. I had a vague impression that we need to do that, but I feel that it's kind of a waste of water to do that. Today I found the answer to this question. So we should wash those containers before recycling to reduce contamination and improve recycling efficiency, but we can use washing-up water. This is in the spirit of reuse as well. In this way, we won't waste clean water and the recyclate does not need to be very clean anyways.

Thursday 28 June 2012

Latte art

Yet another failure for my latte art today. I think this time the problem was not enough foam. This is indicated by liquid and runny milk which creates a homogeneous, light-brown coffee with no patterns. So to get more foam, I need to introduce more air during the frothing (stretching) phase. Today I was a little bit conservative in doing this because I was afraid of getting too many bubbles. I think my problem before may not be too many bubbles, but is not mixing the bubbles well enough with the milk during the second phase (mixing, texturing). During the frothing phase, the key is listening for a slight hissing sound and the milk should expand to two thirds of the pitcher. The holes of the steamer is about 1cm below the surface of the milk to introduce air into the milk.

Friday 15 June 2012

Common shell scripts

if statement

The most compact syntax of the if command is:
if TEST-COMMANDS; then CONSEQUENT-COMMANDS; fi
The TEST-COMMAND list is executed, and if its return status is zero, the CONSEQUENT-COMMANDS list is executed. The return status is the exit status of the last command executed, or zero if no condition tested true. Expression used with if

  • [-s FILE]: True if FILE exists and has a size greater than zero.

Tuesday 12 June 2012

Ruby: regex

The Ruby operator =~ matches a string against a pattern. It returns character offset into the string at which the match occurred, or returns nil if match fails. Your can put the regex first or the string first. Either way is ok. Because nit is equivalent to false in a boolean context, you can use the result as a condition in if or while statements.

Regular expression also defines === as a simple pattern match:
case line
when /title=(.*)/
  puts "Title is #$1"
when /track=(.*)/
puts "Track is #$1"
when /artist=(.*)/
puts "Artist is #$1"
end

Regular expression options

  • i Case insensitive.
  • o Substitute once. Any #{...} substitutions in a particular regular expression literal will be performed just once, the first time it is evaluated. Otherwise, the substitutions will be performed every time the literal generates a Regex object.
  • m Multiline mode. Normally, "." matches any character except a newline. With the /m option, "." matches any character.
  • x Extended mode. Complex regular expression can be difficult to read. The x option allows you to insert spaces and newlines in the pattern to make it more readable. You can also use # to introduce comments.
Reference: Programming in Ruby 1.9: The Pragmatic Programmer's Guide

Monday 11 June 2012

Shortcuts

Ubuntu

  • Ctr+Alt+Del Brings up the logout dialog window.

Unity
  • Alt+Space Brings up window menu with with 'Always on Top' and 'Minimise' and 'Maximise' and above commands.

Sunday 10 June 2012

少食多餐有助减肥的理论依据


Saw a very nice article about dieting and weight loss recently. It talks about the importance of self-control and how successful weight-loss reflects strong character. It also mentions the term ego-depletion which is very interesting. Ego is one of the three parts (id, ego and super-ego) of the psychic apparatus defined by Sigmund Freud. The id is the set of uncoordinated instinctual trends; the ego is the organized, realistic part; and the super-ego plays the critical and moralizing role. The id acts according to the "pleasure principle", seeking to avoid pain or displeasure aroused by increases in instinctual tension. The super-ego works in contradiction to the id. It strives to act in a socially appropriate manner, whereas the id just wants instant self-gratification. The ego seeks to please the id's drive in realistic ways. It serves three severe masters...the external world (reality), the super-ego and the id, trying to bring harmony among the three. In doing so,  the ego (self-control or willpower) can be exhausted because the super-ego's demands often oppose the id's, so the ego sometimes has a hard time in reconciling the two. Dieting is an example of this conflict. Our super-ego demands us to refrain from eating to have nice body, while our id wants to quench the hunger. Low blood sugar level can cause ego-depletion and this is why we often find ourselves eating a lot after a period of dieting, i.e. when the sugar level goes down when you are hungry. So maintaining a constant sugar level, not letting it to go dow to low is important to control your appetite and your willpower. 
Here are some of the highlights.
漫漫减肥路,决定成败的关键因素是什么?是意志力,是自我控制的能力。控制自己对食物和美味的本能需求,拒绝香喷喷的高热量食物,减少进食量;控制自己在懒得抽筋儿的时候,翻身而起,滚去健身房一路狂奔。
自我消耗理论对减肥有何指导意义呢?减肥需要毅力,毅力和血糖密切相关。那么,保证血糖水平不处在过低的状态,就可以有效防止意志力崩溃,从而理智的控制进食量。不仅如此,血糖水平稳定,还有利于我们在完成其他工作的时候意志力增强,决策正确率提高哦。
综上,节食的最好方法就是让体内葡萄糖水平始终稳定在较正常的状态,不要过低,也就是说,不能过度饥饿。不挨饿,面对食物时就会做出更明智的选择,不会出现无理智的暴饮暴食现象。
笔者最近每日5餐,除3餐外,在每天上午10点和下午3点各加一顿,内容可以是点心或是坚果,当然,量都不能太大哈。正餐吃到八成饱就可以了,加餐热量控制在100200卡以内。这样,可以保证全天不饿,血糖水平始终稳定,自控能力较强,从而能够减少正餐、加餐进食量,且学习、工作效率也很ok

My resolution for the summer:

  • Leave the apartment around 7:20am to catch the 7:30am bus. Start work latest at 10am in order to finish 4 pomodoros in the morning.
  • Use a small plate for food and only get food from one stall. Only get vegetarian food plus fish and shrimp (with green or orange labels).
  • Can have chicken (orange label) at most twice a week and red meat (red label) at most once a week if they look good.
  • Only eat until 80% full. Chew more and eat slowly will make you feel more full. Savor the taste of food. (Or full for breakfast, 70% full for lunch, and 50% full for dinner)
  • Drink a cup of water before the meal
  • Eat some fruit at 10am and a pack of almonds at 4pm. 
  • Eat only green or orange label snacks. One green and one orange per day.
  • Have balanced meals: starch (whole grain or whole wheat food), protein (tofu, diary, fish, shrimp, crab)

Saturday 9 June 2012

C++ pointers

#include<stdlib.h>
#include<iostream>

using namespace std;

int * foo (int a) {
int i;
int* p;

i = a
*p = i;
return p;
}

int main(void) {
  int* q;
  int b = 10;  
  q = foo(&b);
  return 0;
}
The problem with this code is that the pointer p is not initialized before it is dereferenced. This will cause a segmentation fault. So if we change *p = i to p = &i, the segmentation fault will be gone. A pointer should always be initialized with an address first.

However, there are other problems with the code, depending on the purpose of the function. If the intended outcome is that the returned pointer points to the same value as the input parameter, the code won't work either. After eliminating the segmentation fault, the code is like this:
int * foo (int a) {
int i;
int* p;

i = a;
p = &i;
return p;
}
The returned pointer points to the local variable i which will be out of the scope once the function returns. Even if we set p = &a, it won't work, because a is also a local variable in the scope of function foo only. So in main, q will not point to b because when we call foo(b), the value of b is copied to the local variable a which has a different address than b.

To get the intended behavior, we need to have something like this:

#include<stdlib.h>
#include<iostream>

using namespace std;

int * foo (int* a) {
int* p;
cout << "p = " << p << endl;
p = a;
cout << "p = " << p << endl; 
return p;
}

int main(void) {
  int* q;it should work
  int b = 10;  
  q = foo(&b);
  cout << "&b = " << &b << endl;
  cout << "q = " << q << endl;
  cout << "b = " << b << endl;
  cout << "*q = " << *q << endl;
  return 0;
}

Thursday 24 May 2012

HCI, computer vision and AI conferences

Conferences related to my research:

AI

  • IJCAI: '13 Beijing
  • ICPR: '14 Stockholm, deadline: 12/20/2013
HCI
  • CHI: '13 Paris, deadline: 9/19/2013

Ruby vs Python: threads

Prior to Ruby 1.9, threads were implemented at green threads - threads were switched within the interpreter. In Ruby 1.9, threading is now performed by the operating system. This means that threads can now take advantage of multiple processors. However, there's major catch. Many Ruby extension libraries are not thread safe, so Ruby compromises: it uses native operating system threads but operates only a single thread at a time. You'll never see two threads in the same application running Ruby code truly concurrently. (You will, however, see threads busy doing, say I/O while another threads executes Ruby code. That's part of the point.)

This is also similar in Python. Due to the Global Interpreter Lock, in CPython only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). To make better use of the computational resources of multi-core machines, it is advised to use multiprocessing. However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.

Reference: Programming Ruby 1.9: The Pragmatic Programmers' Guide (Facets of Ruby)

Tuesday 22 May 2012

Runtime exceptions

In Java, RuntimeException is not checked. Runtime exceptions represent problems that are result of a programming problem, and as such, the API client code cannot reasonably be expected to recover from them or to handle them in anyway. Such problem include arithmetic exceptions, such as dividing by zero; pointer exceptions, such as trying to access an object through a null reference; and illegal arguments exceptions. It is common practice to throw RuntimeException when the user calls a method incorrectly. For example, a method can check if one of its arguments is incorrectly null. If it is, the method might throw a NullPointerException, which is an unchecked exception. For other kinds of incorrect arguments, the method can throw IllegalArgumentException.

The bottom line guideline is: if a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.

Any Exception (checked) that can be thrown by a method is part of the method's public programming interface. Those who call a method must know about the exceptions that a method can throw so that they can decide what to do about them.

Reference: http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html

Monday 21 May 2012

Visual Studio Shortcuts

Close document tab: Ctrl + F4
Navigate through highlighted references: Ctrl + Shift + up arrow or down arrow
Go to method bar: Ctrl + F2, then Tab
Open a file quickly: Ctrl + ;, type filename

Visual Studio productivity power tools for VS 2012

Wednesday 16 May 2012

Paper review

Paper: Real-time hand tracking and gesture recognition for human-computer interaction
Authors: Cristina Manresa et al.
Year: 2000

  • I came across this paper when I searched for previous work on using convexity defects for hand tracking. They didn't use convexity defects for tracking fingertips though. Instead, they use it for gesture recognition. As convexity defects can characterize the state of the hand, I'm also thinking of using the convexity defects as one of the features for gesture recognition.
  • Hand tracking
    • Finding correspondence between between the detected blobs and the tracked hands is an important and necessary step.
    • What they did is a bit similar to Kalman filter, but less rigorous and formalized.
  • The gesture recognition method they describe is very application specific, and involves a lot of threshold values. 
    • I think what PrimeSense does in their NITE library for gesture recognition is also similar to this.
    • Basically you define some gestures you want to recognize and observe their characteristics.
    • Extract and compute features that describe those characteristics and compare with threshold values.
    • This is more accurate probably we are actually incorporating more human intelligence in it.
  • Although it may not scale to other gestures, in this restricted domain, it can perform well.



Monday 14 May 2012

Camera Clinic - Travel Photography by Randall Warniers


  • Carry a camera with you wherever you go
  • Four factors for successful photography: Camera + Light + Decisive Moment + Point of View
  • Four fundamental rules
    • Know our equipement thoroughly
    • Notice the light
    • Be prepared to photograph quickly
  • Natural light in the early morning and in the late afternoon when the sun is low in the sky, is best for people photography.
    • People photography in the middle of a sunny day is bad.
    • A bright sunny day is good for architecture.
    • Hazy light, overcast day, cloud over the sun is best for people photography.

Thursday 3 May 2012

Enable Spell Check in TeXlipse


  • Find the dictionary for the language of your choice. You can use Aspell to create the dictionary:
    aspell --encoding=UTF-8 --lang=<lang> dump master > <lang>.dict
    
    where lang is the language code. Some common language codes are:
    • English: en
    • German: de
    • French: fr
    • Spanish: es
    • Finnish: fi
  • Set the Latex Project Properties under project properties
    • Set the two-letter language code
Sources:

Wednesday 2 May 2012

Common routines after reinstalling Ubuntu

The following routines may be necessary after reinstalling Ubuntu to reconfigure your environment.

  1. Activate additional drivers in "Additional Drivers" for your GPU.
  2. Display
    • For AMD's (formerly ATI) graphics card, you can use AMD Catalyst Control Center (Administrative) to configure for multi-display. However, when I used it today, it didn't work. Using command line works though.
      $ sudo aticonfig --initial # This reinitializes your xorg.conf.
      # Then when you reboot, you should be able to configure multi-display with
      $ sudo gksu amdcccle
      
    • Use ARandR do configure display
  3. Install Chrome dev release.
  4. Install Sun Java 6 and OpenJDK Java SDK
    sudo apt-add-repository ppa:flexiondotorg/java
    sudo apt-get update
    sudo apt-get install sun-java6-jre sun-java6-plugin
    
    sudo apt-get install openjdk-6-jdk
  5. Install git.
  6. Install OpenAFS.
  7. Install Latex.
    $ sudo apt-get install texlive-full
    Update Texlipse's preference in Eclipse by giving the bin directory of Tex distribution: /usr/bin
  8. Install ssh server.
    $sudo apt-get install openssh-server
    

Tuesday 24 April 2012

Painting in AWT and Swing

AWT stands for abstract windowing toolkit. When the original AWT API was developed for JDK 1.0, only heavyweight components existed ("heavyweight" means that the component has its own opaque native window). Lightweight components are introduced in JDK 1.1 (a "lightweight" component is one that reuses the native window of its closest heavyweight ancestor). There are subtle differences in how painting works for heavyweight and lightweight components.

Swing Painting Guidelines

  1. For Swing components, paint() is always invoked as a result of both system-triggered and app-triggered paint requests; update() is never invoked on Swing components.
  2. Programs may trigger a future call to paint() by invoking repaint(), but shouldn't call paint() directly.
  3. On components with complex output, repaint() should be invoked with arguments which define only the rectangle that needs updating, rather than the no-arg version, which causes the entire component to be repainted.
  4. Swing's implementation of paint() factors the call into 3 separate callbacks:
    1. paintComponent()
    2. paintBorder()
    3. paintChildren()
    Extensions of Swing components which wish to implement their own paint code should place this code within the scope of the paintComponent() method (not within paint()).
Reference:

Tuesday 17 April 2012

Some computational geometry terminologies

Convex hull
The convex hull of a set of points X can be visualized as the shape of a rubber band stretched around X. It is the smallest enclosing convex polygon of the set X in the plane.

Getting Started with Kinect for Windows SDK

I have been experimenting with Kinect for Windows SDK and here are the steps to get things started.

1. Download and install the Kinect for Windows SDK. Follow the system requirements and installation instructions on the website. The main software requirements are Visual Studio 2010 Express or other Visual Studio 2010 edition and .NET Framework 4.0.

2. To get started with the development, I find the Quickstart Series are very helpful.

3. Some other details about the API:
  • In the depth map, each pixel is labeled with a number from 1 to 7 to indicate that it is part of user 1, 2, and so on up to 7. If a pixel is not part of a user then it is assigned index of zero. Each pixel is a short value. We can extract the player index and the depth using the following:
    userIndex = s & DepthImageFrame.PlayerIndexBitmask; // The mask is 0x07.
    depth = ((ushort) s) >> DepthImageFrame.PlayerIndexBitmaskWidth; // The width is 3.
    
  • Depth values are in mm.
  • There are 20 joints in the skeleton tracking.

Monday 12 March 2012

CoffeeScript

== vs ===
Because the == operator frequently causes undesirable coersion, is intransitive, CoffeeScript compiles == into ===, and != into !==. In addition, is compiles into ===, and isnt into !==.

A good explanation of the difference between == and === in JavaScript is here.

=> vs ->
=> is the "bound" function operator". When this/@ variable is used in a function, you need to think carefully about which context you want this variable to be bound to. When -> is used, this/@ will refer to whichever the current context is when the function is called; when => is used, this/@ always refers to the context when the function is defined.

Monday 27 February 2012

Ruby: yield statement

A method can invoke an associated block one or more times using the Ruby yield statement. You can think of yield as being something like a method call that invokes the block associated with the call to the method containing the yield. Whenever yield is executed, it invokes the code in the block. When the block exits, control picks back up immediately after the yield. Here's a trivial example:
def three_times
  yield
  yield
  yield
end
three_times { puts "Hello" }
produces:
Hello
Hello
Hello

Thursday 23 February 2012

Difference between ~> and => in Gemfile

Gemfile
~> is used for pessimistic version constraint. Bundler will increment the last digit in the version provided and use that until it reaches a maximum version. So ~> 0.8.5 is semantically equivalent to:
gem "cucumber", ">= 0.8.5", "< 0.9.0"

This means that you are okay with the last digit incrementing to some arbitrary value, but the ones preceding it in the string cannot be greater than what you provided. You might do this if you think that 0.9 version is going to implement some breaking changes, but you know the entire 0.8.x release series is just bugfixes.

Bundler commands
bundle install installs the dependencies specified in the Gemfile if this is the first time you run it (and a Gemfile.lock does not exist). If a Gemfile.lock does exist, and you have not updated you Gemfile, bundler will fetch all remote sources, but use the dependencies specified in the Gemfile.lock instead of resolving dependencies.

References:
http://stackoverflow.com/questions/4292905/what-is-the-difference-between-and-when-specifying-rubygem-in-gemfile

Saturday 18 February 2012

Ubuntu 11.10 boot freezing at Checking Battery State

My Ubuntu on my laptop was not functioning correctly for a week. After login, the resolution is wrong using Unity and I couldn't change the resolution because all the interaction (mouse clicking) was not working. When I switch to GNOME, the resolution is better (usable) but still not correct. So I changed the resolution using the Nvidia setting tool and saved the configuration file (this is a mistake).

After restarting, it froze during boot. I tried a lot of thing, rebooting, going to recovery mode etc. All didn't work. If I end 'e' at the GRUB menu and the enter Ctl+x, it froze at the line "Checking battery state..." After some searching online, I found a solution.

First enter TTY1 by holding down Ctl+Alt+1 when you see it freezes at "Checking battery state...". Then in the command line, redo the nvidia configuration:
$sudo nvidia-xconfig
The output said there were errors in the xconfig settings and a new file is generated. So the problem is really with the Nvidia settings.

Saturday 4 February 2012

Ruby: calling a method

Collecting hash arguments
Ruby doesn't have keyword arguments. But you can achieve the same effect by using hashes. You can place key => value pairs in an argument list, as long as they follow any normal arguments and precede any splat and block arguments. All these pairs will be collected into a single hash and passed as one argument to the method. No braces are needed. There is also the new hash literal syntax in Ruby 1.9: 
class SongList
  def search(field, params)
    # ...
  end
end 

list.search(:title, genre: 'jazz', duration_less_than: 270)

Friday 3 February 2012

How to speak by Patrick Winston

Today I attended Professor Patrick Winston's popular lecture on How to Speak. The lecture theater was packed and people had to sit on the floor including me, but it is really an awesome lecture. Here's the notes on the lecture.

Success = f(Knowledge, Practice, Talent)

  • How to start
    • Don't start with a joke because people may not have started paying attention yet and it will probably fall flat.
    • Start with a menu (agenda) of what you are going to cover.
    • Even better, start with a promise (what the audience will get by the end of the talk).
  • Big 4 (heuristics of giving a good talk)
    • Cycle: repeat the important point several times, and with more details every time.
    • Fence: fence your idea by showing how it is different from others.
    • Punctuation: use verbal punctuation.
    • Question
  • Tools
    • Time & place
      • 11am is a good time to give a talk. 
      • Become familiar with the place and choose a room that can be comfortably full if you can.
    • Board: 
      • using the board can help you control the speed, and it automatically slows you down.
      • Use the board to draw.
      • Use it as a target to point at.
    • Projections
      • Do not read the slides and use fewer words.
      • Be in the image
      • Use simple image
      • Use > 30pt
      • Laser point is a bad idea
    • Props
  • Special cases
    • Oral exams
      • Don't apologize if you don't know something. 
      • Confess instead
      • People who fail usually because they fail to situate in time, space and field.
      • Show your hand: situate your research by showing its relevance and importance.
      • Practice with vicious colleagues
    • Job talk
      • Show vision and steps to achieve it in 5 minutes. For example, you can say "here are 4 steps to achieve the vision. Step 1 & 2 have been done, and I'm going  to focus on step 3, and continue with step 4 in the future."
      • How to end
        • Thank you!
        • Acknowledgement
        • Conclusions
        • Contributions
  • The Star
    • Symbol
    • Slogan
    • Surprise
    • Salient: idea that sticks out
    • Story
  • Stopping
    • Joke is ok
    • Thanks
    • Questions
    • Recite contributions
    • Salute

Tuesday 24 January 2012

How to write the related work section

My advisor's suggestion on how to write the related work section:

  • It's not a literature review. So don't go into to too much details. Describe the work in enough details to show that you understand it.
  • Show how the previous work is related to your work.
    • You can build on the previous work.
    • You can show how you are doing differently.

Friday 6 January 2012

Monday 2 January 2012

CSS dimensions

Relative units

  • % - percentage of some other size (usually the same size in the parent element).
  • em - the font-size of the parent element.

CSS layout: the box model


  • Each element is a box.
  • Default width: maximum that fits into the parent element.
  • Default height: minimum that fits in all the children elements.
    • %: Defines the height in percent of the containing block.


  • Inline elements can share a line. Examples: <em>, <strong>, <input>, <select>, <img>. They have no margins or paddings.