Monthly Archives: December 2011

[Linux Cook]How to concatenate movie files in Linux

Once upon a time, when Windows was the only and the unique boot choice in my boost-up screen, I tried to find out a way to concatenate movie files ….. damn ,this gonna be loooong post, but I don’t want it at all. Let’s make it short :

In linux ( I use Ubuntu, and the other are the same ), if you want to concat many file, just you command cat.

And here is example ( I’m always in love with examples 🙂  ) :

Assume I have some files needed to be concatenated, and our  stars were : asdf.mkv.oo1 ; asdf.mkv.002; asdf.mkv.oo3.

So what would I do ?

>> cat asdf.mkv.* > asdf.mkv

Ok, check it out, you got your movie now 🙂

Oh, by the way, I use asterisk (*) as a wild-card symbol, you can list them manually, split by commas.

This is the reason why linux does NOT need hjsplit or some thing like this.

Enjoy!

P/s : bonus   http://www.thienvanvietnam.org/index.php?option=com_content&view=article&id=326:bbc-is-everything-we-know-about-the-universe-wrong&catid=47:anh-phim&Itemid=128  ==> pirate

Advertisements

Play with fibonacci function

Tonight, I write some code in LISP for my homework. One of these was working with function definition, and fibonacci function was chosen as my example on this stuff.

In LISP, I wrote something like :

(defun fibo ( N )
( if ( or ( = 0 N ) ( = 1 N)) 1
(+ (fibo ( 1- N)) (fibo (1- ( 1- N)))
)))

Wow, with n = 5000, my laptop  was freezing LOL.

So, I find some smarter way to solve this problem.

This time, I choose Python (my favourite ) as my ‘weapon’.

Let’s dig into this problem:

Fibonacci problem is defined on a non-negative integer number N:

if n is equal to 1 or 0 :

return 1

else

return fibonacci(N -1 ) + fibonacci( N-2)

I’m gonna make this clearer with  following  expanding:

if N = 0 or N = 1 : reuturn 1 ( clear, nothing to say)

if N = 2 : return f(0 )  + f(1)

if N = 3 : return  f(2 ) + f(1) = [f(0 ) + f(1)] + f(1)

if N =4 : return f(3) + f(2) = {[f(0 ) + f(1)] + f(1)} + [f(0) + f(1)]

……… etc..

OK, that’s enough expanding, from this point , we are able to form a line ( or a pattern ) of this kind of recursive rule.

For computing the n-th fibonacci number, we don’t have to make any recursive call. Instead, we could sum up a series of numbers – each of them was computed by adding cumulatively numbers – until we meet the basic cases ( o and 1).

And each call in this series need to know 2 previous values ( f(N-1 ) and f(N-2)) , so we save these 2 values for present call.

That’s the idea, and here is the code (in Python – I’m sure it’s very clear, very ‘natural’ to your mind):


# fibo problem in a smart way
def fibo (n):
fn1 = 1 # f(n-1 )
fn2 = 1 # f(n-2 )
S = 0
count = 2;
if n == 0 or n ==1 :
return 1;
else:
while(count < n +1): # count = 2
S = fn1 + fn2
fn1 = fn2
fn2 = S
count = count + 1
return S

And there it is ! See ya !


Some funny quotes about programming and CS stuffs.

Glory sunday, wake up early and enjoy some tea, see the sun rising, and sing my favourite song 🙂

Accidentally , I find out these ROFL-quotes 🙂

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.

C.A.R. Hoare, The 1980 ACM Turing Award Lecture

——————

The computing scientist’s main challenge is not to get confused by the complexities of his own making.

— E. W. Dijkstra

——————

One of my most productive days was throwing away 1000 lines of code.

Ken Thompson

——————

When in doubt, use brute force.    >>>>>> I love this idea, and in fact , I use it many time 🙂  LOL

Ken Thompson

——————

Deleted code is debugged code.  >>>>>>>>>>> yes , sure !

— Jeff Sickel

———————-

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.

————————-

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

Brian W. Kernighan, in the paper Unix for Beginners (1979)

————————

Controlling complexity is the essence of computer programming.

— Brian Kernigan

————————-

A data structure is just a stupid programming language.

— R. Wm. Gosper

————————-

Life is too short to run proprietary software.

— Bdale Garbee

————————-

You can find out more here : http://quotes.cat-v.org/programming/


Some interesting questions known as Google interview questions

These are really wierd-est question I have ever met. Then I found some pieces of information about the reason why Google suggested  these questions. They really don’t care much about the truth or falsity from your answer, but rather about the way you reason to have that answer.

No more talk, let jump in some of them.

The first question, suppose you are shrunk to the height of a nickel , your mass is proportionally reduced so as to mantain the original density.You are then thrown into an empty glass  blender. The blades will start moving in 60s . What do you do ? 

So, in this case there’s no way out, and to save my ass is the most important thing to do now, I’ll jump right on the shaft of the blades, this postion will have least motion and you can avoid the blades . That’s it.

The second question, You need to check that your friend, Bob, has your correct phone number , but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number? 

This is really an easy question ( at least I can do it ) , in term  of a programmer, I’ll use some hash function to compute the value of my number, in this way, I can check if Bob has the right number. So I’ll write some kind of hash function on card, then give Eve to take the card to Bob, then Bob will use this function to compute the value of the number he has , give that value back to me. I’ll check that and I can determine if he has got my right number. As easy as pie.

Haha, I don’t know if my answer satisfy Google employers  LOL