Fix UltiSnips Snippets Load Problem

2015-01-08

To better use YouCompleteMe in Vim, I switched from SnipMate to UltiSnips, because UltiSnips can be integrated into YCM. I also installed snippets since UltiSnips offers an engine only.

Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'

But after I installed it with Vundle, it didn’t work correctly. It only load ‘all’ filetype snippets. You can check this by typing

:UltiSnipsEdit

in Vim. If only ‘all.snippets’ appears, then here is the problem.

Read full article..


Cracking the Coding Interview: Q 3.4 Hanoi Tower Problem

2014-12-30

Although the Hanoi Tower problem very basic, by studying it, we learn thinking in recursive way. Generally we should analysis the base cases and reorganize the problem into subproblems. The different thing from 4th edition is that, in 5th edition, it’s required to use stack to simulate the tower.

Question

In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower.The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one).

You have the following constraints:

(1) Only one disk can be moved at a time.

(2) A disk is slid off the top of one tower onto the next tower.

(3) A disk can only be placed on top of a larger disk.

Write a program to move the disks from the first tower to the last using stacks.

Read full article..


Cracking the Coding Interview: Q 2.6 Circular Linked List Problem

2014-12-26

Recently I’m working on “Cracking the Coding Interview 5th Edition”. All my solutions are public on Github. For this typical question about circular linked list in chapter 2, the way to solve it is a bit tricky.

Question

Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.

DEFINITION

Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list.

EXAMPLE

Input: A -> B -> C -> D -> E -> C [the same C as earlier]

Output: C

Read full article..


Writing Proxy Lab for CSAPP

2014-12-02

In contrast with previous malloc lab, proxy lab is not that hard in CSAPP. But proxy lab could be more complicated if you intend to make it robust. I met many weird problems when writing this lab. As a rookie to network programming, I cannot explain everything well, but I am able to offer some measures to solve problems.

Generally, writing a proxy at proxy lab level is relatively simple in algorithm. You proxy should act as a server when connecting to a client and act as a client when connecting to remote web servers. You may get some inspiration by reading source code of Tiny Proxy, which is included in proxy lab handout.

Like my previous articles about CSAPP, I will talk about some gists only.

Read full article..


Debugging Malloc Lab for CSAPP

2014-11-13

These days I’m working on malloc lab for course csapp. No doubt that it’s the hardest lab in this course. Everyone feels desprate when facing endless segmentfault. Typically, you just added a few lines and then your malloc became full of segment faults.

segfault

I spent over 40 hours on this lab and 70% of my time is on debugging. I also implemented many optimizations to improve my malloc’s performance. But finally my score is stuck at 97. Only 1 guy in this class got 100. I have no idea how he made this. It is said that he removed header and footer of block. If you don’t want to spend too much time on this lab, writing a malloc with explicit list is enough to get 90+ score. This is definitely possible and has been proved by my friend and TA.

Read full article..