Archive

Archive for June, 2007

Searchable Google Reader with Greasemonkey + Gears

June 11th, 2007 No comments
Categories: Firefox, Google, Javascript Tags:

Wiered Map

June 10th, 2007 2 comments
Categories: Google Tags:

Ngeblog Out There

June 9th, 2007 5 comments
Categories: Ngeblog Tags:

Currency Converter

June 8th, 2007 1 comment

Couple days ago, i was asked by a friend to make a small currency exchange script in PHP. With slow internet connection and so short amount of time, the best thing i could think of was grabbing the number from available currency rate site like this. With curl and PCRE function, i finished the script in no time. :p

That’s evil of course.

So, i create the following script as my apology. I use FoxRate currency converter API. Be careful though, you can not run the script too fast, wait for awhile before sending the next request. That’s what happen when you use a free web service. I guess.

Anyway, it’s 2 a.m in the morning here. Gotto go to bed. Night night.

function convertcurrency($from,$to,$amount)
{
  $xml = "
<?xml version='1.0'?>
<methodcall>
  <methodname>foxrate.currencyConvert</methodname>
  <params>
    <param>
      <value>
        <string>$from</string>
      </value>
    </param>
    <param>
      <value>
        <string>$to</string>
      </value>
    </param>
    <param>
      <value>
        <double>$amount</double>
      </value>
    </param>
  </params>
</methodcall>";

  $url = "http://www.foxrate.org";

  $header  = "POST /rpc/ HTTP/1.0 \\r\\n";
  $header .= "Host: foxrate.org \\r\\n";
  $header .= "MIME-Version: 1.0 \\r\\n";
  $header .= "Content-length: ".strlen($xml)." \\r\\n";
  $header .= "Content-transfer-encoding: text \\r\\n";
  $header .= "Document-type: Request \\r\\n";
  $header .= "Connection: close \\r\\n\\r\\n";
  $header .= $xml;

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $xmlresponse = curl_exec($ch);
  curl_close($ch);

  $sxml = new SimpleXMLElement($xmlresponse);
  $xxml = $sxml->xpath("params/param/value/struct/member");

  foreach ( $xxml as $v )
  {
    if ( $v->name == "flerror" )
    {
      $errflag = $v->value->int;
    }

    if ( !$errflag )
    {
      return false;
      break;
    }

    if ( $v->name == "amount" )
    {
      return $v->value->double;
    }
  }
}

Sample usage:

$ret = convertcurrency("JPY","IDR",1);

if ( $ret )
{
  echo "1 JPY = $ret IDR";
}
else
{
  echo "Wrong currency code or you're too fast to fetch, wait for awhile.";
}
Categories: PHP Tags:

Google Reader Goes Offline

June 7th, 2007 No comments
Categories: Google Tags:

Java 6.0 Features – Scripting Language for the Java Platform

June 7th, 2007 2 comments

This is interesting,

Java 6 provides the Common Scripting Language Framework for integrating various Scripting Languages into the Java Platform. Most of the popular Scripting Languages like Java Script, PHP Script, Bean Shell Script and PNuts Script etc., can be seamlessly integrated with the Java Platform. Support for Intercommunication between Scripting Languages and Java Programs is possible now because of this. It means that Scripting Language Code can access the Set of Java Libraries and Java Programs can directly embed Scripting Code. Java Applications can also have options for Compiling and Executing Scripts which will lead to good performance, provided the Scripting Engine supports this feature. Let us have a high-level overview of this JSR before going in detail.

Categories: Java, Javascript, PHP Tags:

Apache Log Analyzer 2 Feed

June 6th, 2007 1 comment

apachelog2feed

If you like to follow everything using your feed reader, you might also want to read your Apache log in feed. Well, you need to try Apache Log Analyzer 2 Feed.

ApacheLogAnalyzer2Feed is an object oriented class, written in PHP 5, for parsing/filtering an Apache log file and convert it into feed.

You can filter out which part of your Apache log you’d like to see. For example, you can generate a feed that shows you when Google Bot visit your blog or when your visitor register, etc. See some sample codes here.

Here’s the sample output from my Apache log,


<rss>
<channel>
<title>Log /usr/local/apache2/logs/access_logs filtered by 1 filters</title>
<description>Array
(
    [0] => Array
        (
            [0] => Request
            [1] => regexp:generator\.php
            [2] => IS
        )

)
</description>
<link>/log.php</link>
<lastbuilddate>Wed, 06 Jun 2007 21:20:08 +0100</lastbuilddate>
<generator>FeedCreator 1.7.2-ppt (info@mypapit.net)</generator>
<item>
<title>192.168.1.99 - GET /generator.php HTTP/1.0</title>
<link>/log.php</link>
<description>Array
(
    [Remote-Host] => 192.168.1.99
    [Remote-Logname] => -
    [Remote-User] => -
    [Time] => [06/Jun/2007:21:17:26 +0700]
    [Request] => GET /generator.php HTTP/1.0
    [Final-Status] => 200
    [Bytes-Sent] => 9274
    [Referer] => -
    [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
)
</description>
<pubdate>Wed, 06 Jun 2007 21:17:26 +0100</pubdate>
<guid>b27435fba04c82a72e084d0404bc442b</guid>
</item>
<item>
<title>192.168.1.99 - GET /generator.php HTTP/1.0</title>
<link>/log.php</link>
<description>Array
(
    [Remote-Host] => 192.168.1.99
    [Remote-Logname] => -
    [Remote-User] => -
    [Time] => [06/Jun/2007:21:20:02 +0700]
    [Request] => GET /generator.php HTTP/1.0
    [Final-Status] => 200
    [Bytes-Sent] => 9274
    [Referer] => -
    [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
)
</description>
<pubdate>Wed, 06 Jun 2007 21:20:02 +0100</pubdate>
<guid>005091851cf9b076180c57ff3c5ea081</guid>
</item>
</channel>
</rss>
Categories: PHP Tags:

PHP Abstract

June 5th, 2007 No comments

php abstract logo small

PHP Abstract is Zend Developer Zone‘s new podcast for PHP developers. It was announced on may 17th 2007, but the first episode was just online today.

PHP Abstract episode 1 talks about PHP security tips by Eli, the author of PHP 5 in Practice. It is a short duration talks, but pretty useful.

Link:

PHP Abstract Feed

Categories: PHP, Zend Tags: