Archive

Archive for February, 2013

Dark corners of C

February 27, 2013 Leave a comment

A Quiz About Integers in C

The C language’s rules for integer operations have some quirks that can make even small programs behave in confusing ways. This post is a review of these rules in the form of a quiz containing 20 questions. I recommend going through the questions in order. If you are a beginning C programmer, you should consult a C book as you go through these questions since there are a lot of little things (such as what “1U” means) that I have not bothered to explain. If you are a serious C programmer, I expect you’ll do well — this quiz is not intended to be extremely difficult. You should assume C99. Also assume that x86 or x86-64 is the target. In other words, please answer each question in the context of a C compiler whose implementation-defined characteristics include two’s complement signed integers, 8-bit chars, 16-bit shorts, and 32-bit ints. The long type is 32 bits on x86, but 64 bits on x86-64 (this is LP64, for those who care about such things). Summary: Assume implementation-defined behaviors that Clang / GCC / Intel CC would make when targeting LP64. Make no assumptions about undefined behaviors.

Categories: c programming language Tags: ,

Resize movies for Android/iOS with ffmpeg

February 26, 2013 Leave a comment

Update (20130227): I made a resizer script. See the end of the post.

Problem
You have an Android/iOS phone and you want to watch movies on it. However, if you transfer a movie to the phone, the media player may stop playing it or it may even freeze. Apparently, the movie is too big for your phone. What to do?

Solution
If the media player has problems playing the movie, then it’s too big, thus you should resize it. Then the phone will be able to play it nicely.

Under Windows there is a nice video converter called AVS Video Converter. But if we are under Linux, what can we do?

Well, ffmpeg can do the job for us. But the question is: how to parameterize ffmpeg? :) Here it is:

ffmpeg -i INPUT -codec:v libx264 -quality good -cpu-used 0 -b:v BITRATE -profile:v baseline -level 30 -y -maxrate 2000k -bufsize 2000k -vf scale=WIDTH:HEIGHT -threads THREADS -codec:a libvo_aacenc -b:a 128k OUTPUT.mp4

Let's see a concrete example. I have a Huawei Ascend Y200 whose resolution is 480x320 pixels. As for the bitrate, 600 kb/s is enough IMO. I want ffmpeg to use 2 cores of the CPU. So:

time ffmpeg -i input.avi -codec:v libx264 -quality good -cpu-used 0 -b:v 600k -profile:v baseline -level 30 -y -maxrate 2000k -bufsize 2000k -vf scale=480:320 -threads 2 -codec:a libvo_aacenc -b:a 128k output.mp4

I like to see how much time the conversion takes, that's why I added the "time" command.

Another advantage of this approach is that you can launch the conversion in batch mode. Say you want to convert all the episodes of your favorite TV show. No problem, just write a little script.

ffmpeg
I use Ubuntu and it comes with an old ffmpeg that fails for instance with the parameters above. So I downloaded a static ffmpeg build from http://ffmpeg.gusari.org/static/. FFmpeg exists under Windows too, so the method presented above should work on Windows (though I didn't try it).

Credits
I've read about this solution in this article. You can find more examples with ffmpeg in this source.

Related Work
If you prefer GUI applications, you can take a look at HandBrake.

Script
I made a script that can process movies in batch mode. Available here.

Categories: ubuntu Tags: , , ,

Nikola: a static site and blog generator

February 21, 2013 Leave a comment

Nikola is a static website and blog generator. The very short explanation is that it takes some texts you wrote, and uses them to create a folder full of HTML files. If you upload that folder to a server, you will have a rather full-featured website, done with little effort.

Links:

similsite: find similar sites

February 17, 2013 Leave a comment

http://similsite.com/

SimilSite is a search engine to find similar websites, and a directory to find interesting information on every website.

FAQ here

Categories: web Tags:

Android got damn slow

February 6, 2013 2 comments

Problem
My Android phone got very slow. It started about a week ago. When I visit Gmail, for instance, I have to wait minutes until my new messages appear. If they appear at all… Often, messages are not updated. I click on “refresh”, I wait 2 minutes, but I still get the old messages. What da hell?

Solution
In this forum thread I found the following tip:

EDIT: I found the solution… Go into the Market and install AdFree. Update the host file and reboot to clear DNS, everything back to normal. Myn’s is preloaded with the Adfree host file and it became outdated.

AdFree requires root privileges. Doing the rooting process and installing AdFree, my phone got much faster :) I need a few more days/weeks to test it but it looks promising.

Categories: android Tags: ,

Is your Android phone rooted?

February 6, 2013 Leave a comment

How to tell if your phone is rooted

In short: install the application ConnectBot from Google Play and type “su" in the console. If it switches to root (in this case the prompt changes to '#'), then your phone is rooted.

Categories: android Tags: , , ,

Rooting your Huawei Ascend Y200

February 6, 2013 Leave a comment

Here are some links that describe how to root your Huawei Ascend Y200 Android phone. If something goes wrong, I take no responsibilty! This is for educational purposes only.

Categories: android Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 70 other followers