Category Archive

The following is a list of all entries from the Programming category.

What I’ve been up to?

via


Swap without Temporary Variable

When we’re programming, if we want to swap values of two integer values, the “normal” way we do it would look like:

x = 5
y = 3
 
temp = x
x = y
y = temp

We need a temporary variable as a container to hold a value first then do the swap.
What if in some situation you can’t use [...]


Solution to Lenovo Y410 Sound Problem On Ubuntu 8.04

Update 30/04: This script will only make speaker work, but not headphone. As Sam mentioned, there is another easy way to get sound work without installing anything: Suspend your machine and resume. The drawback is you have to do it every time after you (re)boot.
Well, this is another post about Ubuntu 8.04!
As I mentioned before, [...]


Merry Christmas!

Hey, this is the first christmas for jaux.net, and today is my first boxing day to crash a door. Got nothing but happy holidays :)
Merry Christmas, everyone!


How To Prevent Creating Objects On Heap

Yesterday I saw a C++ interview question that was asking the interviewees to prevent the clients from creating objects on heap. That is, you write a class and your class users can’t use new to create an object.
Here is my solution:

1
2
3
4
5
6
7
8
9
10
11
class Foo
{
public:
Foo(const Foo& f) {}
static Foo getAnInstance()
[...]


Search for next

This is a VIM tip. I saw it before, but I forgot it after a while. I saw it today, I don’t want lose it again, so I write it down.
When you are going though a document in VIM, you find a word and you want to go to the next same word in the [...]


Solving Cyclic Dependencies Is Hard

I am a C/C++ beginner but I’d been already taught that dependency cycles are generally evil since it’s very hard to solve. I haven’t realized how hard the problem is before, because all the works I’ve done are “one file” programs or I can just simply throw all the files into a single gcc/g++ command.
However, [...]


Peter’s Comment on Concurrency

“Concurrent program in a single processor computer will only make it slower than its sequential counterpart, but we are looking into the future, so let’s write concurrent programs.”
– Peter A. Buhr


Autoboxing Makes Java Be 99% Object-Oriented

I remember that back to the early age when I was first beginning to learn the Java programming language, there was a famous quote (in China): Java is a 95% object-oriented programming language..
Why was it? Because Java has primitive types built-in. I have to admit that I both love primitive types and hate them. Loving [...]


Circular Linked List Problem

How to determine a linked list has a cycle without marking any nodes? This is a classical interview question and one of my friend brought it to me.
When I came across the question, I thought that we might count the nodes. If the our counter goes behind the linked list’s size, we could say that [...]