Saturday, April 21, 2012

Hi guys, here is my new site about Euro 2012:



Hi guys, here is my new site about Euro 2012:
Euroinfo.com.ua - All information about Euro2012, cities, teams, results, hotels in ukraine, shops, tickets...

Tuesday, April 10, 2012

Sorting data in files: distribution of the initial series C++



Sorting data in files: distribution of the initial series C++
Somethimes there are so many data in file to sort that PC just can't process, so you need such a algorithm as
this one. I used pyramid sorting (it's logarithm sotring).
#include "stdafx.h" 
#include "iostream" 
#include "stdio.h" 
#include <fstream> 
#include <ctime>

using namespace std;
void sift( int *array, int , int );
void generateRand(int n);
void heapsort( int *array, int );
 void main()
 {
      int i, size = 0;
      int *array;
      cout<<"Input number of elements to generate\n";
      int N;
      cin>>N;
      generateRand(N);
      //if you don't know how many elemets are in text file
      ifstream fin("file_input.txt");
      while(!fin.eof())
      {
         fin>>i;
         ++size;
      }


      fin.close();
      size--;
      cout << "Number of elements: \n ";
      cout << size<<"\n";
      array = new int[size];
      i = 0;
      ifstream fin2("file_input.txt");
      while(!fin2.eof())
      {
           fin2>>array[i];
            i++;
      }
      fin2.close();
      heapsort( array, size );
      cout<<"\nResultes are in file_out.txt\n";
 }


void sift( int *array, int L, int R )
{
   int i, j;
   int item;
   i = L;
   j = 2*L;
   item = array[L];
   if ( j < R && array[j] < array[j + 1] ) j++;
   while ( j <= R && item < array[j] )
   {
     array[i] = array[j];
     i = j;
     j = 2*j;
     if ( j < R && array[j] < array[j + 1] ) j++;
   }
   array[i] = item; 
}


void heapsort( int *array, int size )
{
   ofstream fout2("file_out.txt");
   int sort=0;
   int L, R;
   int item;
   L = size/2;
   R = size - 1;
   while ( L > 0 )
   {
     L--;
     sift( array, L, R );
     ++sort;
   }


   fout2<<array[0]<<" ";
  while ( R > 0 )
  {
     item = array[0];
     array[0] = array[R];
     array[R] = item;
     R--;
     sift( array, L, R );
     fout2<<array[L]<<" ";
     ++sort;
   }
   fout2.close();
   cout<<"\nf: "<<sort;
 }


// generating numbers in file 
void generateRand(int n)
{
   ofstream fout("file_input.txt");
   srand ( time(NULL) );
   int temp;
      for(int i = 0; i<n; i++)
   {
     temp = rand() % 200;
     fout<<temp<<" ";
   }
   fout.close();
   cout<<"Generating completed\n"
}

Monday, April 2, 2012

Showing the weather with PHP and Google Weather API


If you need to show weather in your website, you can use weather widget such as weatherbug. It’s nice and simple, but maybe you need something more integrated with your website. So, take a look at Google Weather API.
http://www.google.com/ig/api?weather=[city name]
Example :
http://www.google.com/ig/api?weather=jakarta
It will give you xml data, and you can parse it easy in PHP. Take a look at sample code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
    <head>
        <title>Google Weather API</title>
    </head>
    <body>
        <h1><?= print $information[0]->city['data']; ?></h1>
        <h2>Today's weather</h2>
        <div class="weather">  
            <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
            <span class="condition">
            <?= $current[0]->temp_f['data'] ?>&deg; F,
            <?= $current[0]->condition['data'] ?>
            </span>
        </div>
        <h2>Forecast</h2>
        <? foreach ($forecast_list as $forecast) : ?>
        <div class="weather">
            <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
            <div><?= $forecast->day_of_week['data']; ?></div>
            <span class="condition">
             <?= $forecast->low['data'] ?>&deg; F - <?= $forecast->high['data'] ?>&deg; F,
             <?= $forecast->condition['data'] ?>
            </span>
        </div> 
        <? endforeach ?>
    </body>
</html>
In real world, you need to take consideration to cache the result, you don’t need to call the google API each time as the weather change daily. That’s it. Happy coding everyone.

You can see the weather at Jakarta.