Wednesday, June 19, 2013

Find Square root without using standard library funtion

Hi guys,

Here I have a program which is used to find out the square root of a number without using standard library function. This method is known as Babylonian method. You can understand the algo part with this link. The only difference which I included is about the first guess. I am taking first guess as the lowest number which have ’0' as half of the original number’s length. I think I may have confused you. so here is the example if you want to find out the root of 1600, so I will start with 10. you will have better idea once you will go through the code.


#include
int calculateStarter(int n);
 
main()
{
    int number;
    int answer, guess, temp;
    printf("Enter the number for square root\n");
    scanf("%d",&number);
    printf("here start the processing\n");
    guess = calculateStarter(number);
    while(1)
    {
        answer = number/guess;
         
        temp = (answer + guess)/2;
        printf("number = %d and guess = %d and temp = %d\n",number,guess,temp);
        if(guess - answer < 1)
            break;
        guess = temp;
    }
    printf("so the answer is %d\n",temp);
}
 
int calculateStarter(int n)
{
     
    int temp =1;
    int count=0;
    printf("In the calculate method\n");
    while (n /10 != 0)
    {
        count++;
        n = n/10;
    }
    //if(count%2 == 0)
    count = count/2 + 1;
     
    while(count >0)
    {
        temp = temp*10;
        count--;
    }
    printf("so the guess is %d\n",temp);
    return temp;
}
   

Vim Editor : Some very common and useful shortcuts

As a programmer I think we use some tools to make our work easier. Most of the time it will be some hi-fi IDE, but I saw many good programmer using Vim Editor very efficiently.  And I must say it has equal capability if you use it properly.

So here I will try to cover few basic shortcuts which could make your life easier.

Shortcut                   Use

yy                        copy the current line in the buffer.

3yy                      copy multiple line (here 3) in the buffer.

p                          paste the buffer content after cursor position line.

P                          paste the buffer content before cursor position line.

D                         delete line at cursor position.

dd                        delete current line.

3dd                      delete multiple line(here 3).

/text                     search “text” in the current file.

:number                go to this line number

u                          undo the last change.

dw                       delete entire word

:%s/fff/rrrrr/g        find all instance of “fff” and replace it with “rrrrr”


And for more tutorial, refer following tutorial.
Hope it will help.

Sancheoneo Ice Festival, Hwacheon, Korea

This weekend I was able to go to any ice festival, Sancheoneo Ice festival and as per CNN it is world’s 4th largest Ice festival.

So here I will give you all the details in my style :

When It is held : probably month of January everywhere.

Where : It is situated in a city called Hwacheon, Korea.

How to reach there : It depends on from where you want to start.  I was staying in Suwon. So from there I took a express bus to Chuncheon, if you are staying in Seoul also, you have to do the same. you can also use Subway, but I will suggest use bus, that way you don’t need to change many metro to reach there.  Then from Chuncheon, there is very frequent bus service to Hwacheon( every 15-20 mins). Ice festival venue is some half a kilometer away from bus terminal, so you can walk down the road.

Activities you can try : Mostly it is popular for Ice fishing. So you can dig a hole in the frozen river and enjoy fishing, there is also bar hand fishing available if you want to try. Worth to mention, there is a foreigner help desk where you can purchase all the fishing equipment and they speak English so you can get any help if you want. To use the Ice Fishing ring you have to purchase ticket of 8000 won, out of which you will get some 3000-5000 won back as food coupon.

Apart from that you can try other things too, like Ice Sliding for that also you have to purchase 5000 won ticket, but I must say it was fun. There are a lot of activities, but I think others are for Children only, the other activities are :  Go Karting on Ice( or I say Go Icing  ), Ice Bicycle, small bungee jumping, Fake Para gliding through the crane(:P).

We were lucky that, it was Special Winter Olympics held in South Korea, so there was a team of Figure Skating, who performed on the very famous “Gangnam Style” song. And I must say, it was awesome performance and must watch too.

Also you can make your snow man there as lots of ice, and volunteer will help you to form shape.  And always watch your step, as it is very slippery. But overall it was good experience.

Food : You will find many food stalls. As for non-vegetarian you will have lots of option with traditional korean food items, but for vegetarian can also survive. In veg food, you will have Tofu(soya-paneer), some indian utppam kinda stuff(tasty though) and some fruits.

Etc: If you are planning to stay in the night, then I will suggest you visit the market as they have really nice Lightning in the night.

I hope it will help you plan your trip to Sancheoneo Ice Festival.

Korean Folk Village

Finally I came out of Dan pretty much after one and half month of no trip at all. So it was refreshing to have a feel of chilly korean weather.

Let me share the experience of Korean Folk Village Trip in my usual way:

Where it is : Yongin-si, Gyeonggi-do( Near to Suwon)

How to reach there : I will suggest you to use subway to reach Suwon Station. As from there you will find 2 buses (37 and 10-5). But I prefer 37, as it is better frequency. Also Tourism department provides free shuttle from Suwon station, but it has limited frequency, although I didn’t use it(may be my timing didn’t match).

What it is : It basically gives you the glimpse of the traditional korean village. you can say it is a musuem of an Korean Folk Village. You will find everything, like traditional home, their village council, items they used to use, shops etc.

What to do : Apart from vising all the places mentioned above. Management has made sure you dont get bored easily. As they have managed to have some 2 hours performance. First the traditional marriage ceremony, Folk music performance (awesome), rope performance (not that interesting) and performance by horse riders. It starts around 10:30 and they will repeat all performances from 2 PM.

After covering all these performance you can proceed to food court where you will find traditional korean folk food(veggies take your foods with you, no good option for you). Then you can go for the museum about korean culture.

Next is Amusement park, which covers haunted house, 4D movie Theater, many rides for children as well as adults.

Further, they have sculpture garden(good for you if you are art fan).

Finally there are few more museums related to other countries culture, you can check it out if you want.

how much it costs : Fee for adult is 15000 won(Admission ticket) and 20000 won(Admission + Amusement Ticket). I will suggest go for second option, as if you pay for rides individually it will cost you more.

Hope it helps you to plan.

Android SurfaceFlinger : Few useful links

Hi All,

If you guys are interested in understanding the flow of Android SurfaceFlinger, here are few links. I must say these are quite detailed and nicely written, although it is in Chinese. So Here are the links
1. http://www.360doc.com/content/10/0221/08/155970_16303293.shtml
2. http://www.360doc.com/content/10/1120/11/3700464_70888667.shtml
4. http://blog.csdn.net/luoshengyang/article/details/7747932
5. http://blog.csdn.net/sure00/article/category/781178

If you will go through it, I can assure you, it would be more than enough to know about Surfaceflinger.

How To Enable debugfs in kernel dynamically.

Kernel developer has provided a functionality known as “debugfs” to debug the kernel, enabling the log at the run time. It is very useful for the modules which have a lots of logs, and enabling the log statically will make the system very slow. So Kernel developers came up with this idea to enabling the logs only for the time when user wants to check a particular scenario.
So here is the process to enable it :
Step 1. Enable the debugfs, which can be done by following command :
mount -o rw,remount -t debugfs none /sys/kernel/debug
Step 2. Now if you want to see what are the logs defined you can do the same using following command :
cat /sys/kernel/debug/dynamic_debug/control [Here /sys/kernel/debug/ is the directory we mounted in previous command,                    u can change it if you want]
Step 3. Now enable the debug log for the files or paricular function you want to see in the logs:
echo ‘file mdp.c +p’ > /sys/kernel/debug/dynamic_debug/control [It will enable all debugfs logs in mdp.c]
echo ’file mdp.c line 2921 +p’ > /sys/kernel/debug/dynamic_debug/control [It will only enabled the log at 2921 line in mdp.c file]
# (
> echo ’file svcsock.c line 1603 +p’ ;\
> echo ’file svcsock.c line 1563 +p’ ;\
> ) > /sys/kernel/debug/dynamic_debug/control [for enabling to multiple debug logs]
Step 4. Now you can check the logs in demsg or cat /proc/kmsg.
Here I want to mention the logs which used under pr_debug()/dev_dbg() method will be enabled by this feature.So whatever logs you want to enable put those using pr_debug or dev_dbg().
you can find more details for pattern to enable logs @ https://www.kernel.org/doc/ols/2009/ols2009-pages-39-46.pdf