Friday, January 9, 2015

Download Foto dari Flicker / Instagram

Tulisan ini tidak bermaksud untuk melanggar hak cipta foto milik orang lain. Hanya untuk pengetahuan. 

Jika kita ingin mendownload foto dari Flicker atau instagram dimana kita tidak bisa mendownloadnya. Anda dapat melakukanya lewat cara berikut.

1. Buka firefox
2. Buka halaman flicker atau instagram yang diinginkan sampai foto tersebut muncul di halaman web
3. Klik Kanan
4. Pilih View Page Info
5. Pilih Tab Media
6. Cari gambar yang Anda inginkan di address.
7. Pilih save as















Selesai.

Semoga membantu!

Friday, January 2, 2015

LINUX Create Executable Binary File

I'm newbie trying to learn about linux, Centos 6.5. Today I learned how to change from #./yourprogram in certain directory to #yourprogram. I want to share it here.

Condition:
I've just downloaded Eclipse for example. In tar.gz.
When I extracted the files in certain folder, I can run the program by calling #./eclipse.

Goals:
What I do want is to run a simple command $eclipse, then I can have my program running.

Answer:
Consider this as your program directory.
/usr/eclipse
it can be any directory.

This is the way.
#touch /usr/bin/eclipse
#chmod 755 /usr/bin/eclipse
#vi /usr/bin/eclipse

then put this inside.

export ECLIPSE_HOME="/usr/eclipse"
$ECLIPSE_HOME/eclipse $*
Finished!





Wednesday, April 30, 2014

Union Find in PHP

Hey there. I've just created Union Find data structure in PHP. If you needed, get it here or check it below. Hopefully it helps you solve problems.

Friday, February 21, 2014

Range Sum Query

Fenwick Tree is a data structure made for getting range sum query from data that is open for updating.


There is data A:
Index 0 1 2 3
Value 2 1 0 4
Update and Get Range Sum quickly!!

First Data Structure

We can get O(1) for updating the value from the certain index in our data.

A[2] = 5;
Index 0 1 2 3
Value 2 1 5 4

But we'll have O(N) for getting the range sum query.
RSQ(1,3) means A[1] + A[2] + A[3]
So, RSQ(1,3) = 1 + 5 + 4 = 10

Second Data Structure

Keep the cumulative frequency in each index.
It means that :
A[0] = A[0];
A[1] = A[0] + A[1];
A[2] = A[0] + A[1] + A[2];
A[3] = A[0] + A[1] + A[2] + A[3];

Index0 1 2 3
Value2 1 5 4
Cumulative2 3 8 12

We can get O(1) for RSQ.

RSQ(1,3) = A[3] - A[0];
or RSQ(a,b) = A[b] - A[a-1];

But we'll have O(N) for updating data.
If we want to update a data A[x], we need to change the value from index x until N-1. Why? Because we are keeping the cumulative frequencies.

Third Data Structure - Fenwick Tree

This data structure keeps the cumulative value in a unique way.
It use Least Significant Bit to define the responsibility of each index. What kind of responsibility?
If we look at the Second Data Structure, each index X has responsibility for index 1 until X.
In Fenwick Tree we are going to cut that responsibility.
So, each index will not take responsibility for index 1 until X but only from it's least significant bit.





Look at the picture.
At index 1 we save the value 3 which is A[0] + A[1].
Why? Because we can get A[1] value by FT[1]-FT[0].

Not clear enough? Let's see on index 3. We save value 12.
How come?
12 is the value taken from FT[1] + FT[2] + A[3]
We can get value A[3] from FT[3] - FT[2] - FT[1].

That's the idea. Get it?

Now, how can we know which one needed to substract the value in FT?
It's using bitmask. Find out in the next post. :)

Wednesday, February 19, 2014

Snake Game HTML 5

Somedays ago my lecturer taught us to use HTML 5 canvas. He gave some code of snake and I updated it a little bit so that the snake won't die as it hit the border.

Check here for better view of the code


Team Queue Uva 540

Problem: Uva 540
I find that this problem is interesting. When we discuss about queue, it's not always strict queue rule that we have in mind. Sometimes people can just cut the line because they know someone in the line.

The idea of solving is using list of queue.
  1. Each time an element comes, check each list member which is a queue.
  2. If the queue.front() 's team is the same with the new element, just push it to the queue
  3. else check other member of the list
  4. if there is no element with the same team, create new queue in the back of the list
Here's my code. 

Tuesday, January 1, 2013

Recursive 4 - Get Gold part 2

previous post

You've learned about making one direction checking. From your current position, you can find out something in one block to the right. If you can't move anymore or you get the gold, you will return. That's what we're talking about in the previous post.

Now, I will continue about making more than one direction checking. How if we have a map that looks like this.

The Dog       Gold
##
Gold##

In this situation, we can get the gold by moving right or down. There are 2 alternatives. How do we make the dog to check both right and down?

 In the previous post you'll find code like this
if(j < 3)   // to check whether the current position is not bigger than the number of column
{
     if(array[j] == 1)  // to check whether the current position has the gold or not
         return 1;
     else 
         find_1(j+1);      // to move to the next position,  (j + 1) means move to the right.
}
We need to check not only the columns, but also the rows. So we need not only j  but also i to check the rows. We can start making the down checking by adding the parameter.

Change this bool find_1(int j){} into bool find_1(int i, int j){}
i for the rows
j for the columns

Then, change the array, from 1 dimension into 2 dimensions. From array[j] into array[i][j]
Wait, don't forget to change the calling of the method find_1. From find_1(j+1) into find(i, j+1)

Now we're getting into the answer of the question. To make the checking for both direction, you can just simply add another if block.

Column check:

if(j < 3)
{
     if(array[i][j] == 1)  
         return 1;
     else 
         find_1(i, j+1);  
}


Row check:

if(i < 3)
{
     if(array[i][j] == 1)  
         return 1;
     else 
         find_1(i+1,j);  
}

But there's a problem. 
1. It would only check the column. Because when the column check fails, it directly return 0 to the main. 
    Solution : use a variable to keep the status whether there is gold or not from the right.

2. If we have add a variable flag to solve the 1st problem, there's another problem. In the row check, there would be a moment when j == 3. This shouldn't happen. 
    Solution: remove the if(j < 3) and if(i < 3). Replace then with this.
    if(j >= 3 || i >=3){return 0}


This is the complete code. Try it. 
source code

Next Post -> Self-playing pacman. Using recursive, we can make a pacman moves and search its food in the  entire area.