Archive for the ‘Programming’ Category

Mono 2.0 released!

Tuesday, October 7th, 2008 by Agro Rachmatullah

After a very long wait, finally the cool Mono guys released Mono 2.0! It is the open source implementation of the core .NET platform which of course includes the C# compiler. My litmus test is no other than FractalSharp which uses PropertyGrid and quite some System.Drawing stuffs. (Actually since 2.0 beta FractalSharp can be run without problems)

A C# 3 compiler is included there. Oh LINQ and lambda functions… I haven’t learned any new C# language features since the 2.0 generics.

Kudos to the Mono team (read their blog aggregator here). Now go get it! (I myself won’t rush, limited Internet quota here)

Yumeko BPMFinder - My very own human-assisted BPM analyzer written in JavaScript!

Saturday, August 16th, 2008 by Agro Rachmatullah

Yumeko BPMFinder

On a previous post I discussed about the results of a Windows BPM finder program MixMeister BPM Analyzer. It sometimes produces values that are 2 times or half the seemingly actual value. And then the doubt grew on me, “Is that program even accurate at all?”. So, I was set to program my own BPM finder.

But I don’t know any sound programming stuffs, so I went for the easy path of a human-assisted program in which the algorithm is very intuitive. A human would tap the beats while playing a song and the program will do the simple mathematical calculation (it’s “beats per minute” for a thing, so it’s basically just a division).

(more…)

Yumeko AdManager 0.0.1

Friday, August 8th, 2008 by Agro Rachmatullah

After a day’s worth of PHP hacking coupled with some swearing, I’ve finally finished a rudimentary ad manager! What does it do? Well, basically it rotates through a pool of ads. A life demo can be seen here. Refresh the demo page several times and see the ads magically rotating.

It’s called Yumeko AdManager because… Well, probably because it will be used on my Japanese learning site Yumeko. Because Google AdSense still don’t allow us to use it on Indonesian web sites.

This program is licensed under GPL 2 and you can download it here (there’s a documentation, yay!). I even made a special page for it here in case I’m inclined to update it.

Here are some of its features:

  • Relative appearance rate of ads can be set
  • Tracks appearance count
  • Tracks click count
  • Expiry date for ads can (uhm… must) be set

What’s obviously lacking is an interface to add and manage ads. Yes, you need to play around using tools such as PHPMyAdmin to add the database rows. But anyway it’s all explained in the documentation :).

Other than PHP, I’m also interested in learning more about this black horse JavaScript to make… ah, let’s call it “interactive programs”. But alas, there’s only so much hours in a day…

HTTP redirection using PHP fails when you use UTF-8 encoding

Tuesday, August 5th, 2008 by Agro Rachmatullah

To redirect a page by putting the instruction on the HTTP header, PHP makes it very easy:

<?php
header("Location: http://www.agronesia.net");
?>

The catch to call header successfully is that you must not output anything beforehand. So, no space before the opening PHP tag. Also no calls to print or echo beforehand. Else you will get an error message like this:

Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\htdocs\bla\test2.php:1) in H:\xampp\htdocs\bla\test2.php on line 2

That also means you cannot have a UTF-8 encoded document. That’s because UTF-8 text files output this BOM thing at the start of the file. Oh, and if you use include, the included files also cannot have any funky BOM stuffs.

You guessed it right. I got tripped by this problem. Because I often type Japanese, I set Notepad++ to use UTF-8 as its default encoding. @#^#&%$@*!!!

PHP variable naming sucks

Tuesday, August 5th, 2008 by Agro Rachmatullah

PHP is a language that deserves curse. For variable names, we always have to use the $ sign. The purpose is of course to add one more thing a programmer can forget. And when you do forget, PHP treats the misnamed variable as a string which in my case causes the script to run but wrongly.

Here’s the golden bug on my script:

$mysql_db = "some_db_name";
mysql_select_db(mysql_db);

No wonder my carefully crafted INSERT query didn’t have any effect…

Dean Edward’s packer: A JavaScript compressor

Saturday, June 14th, 2008 by Agro Rachmatullah

Dean Edward\'s packer

If you’re using JavaScript, you might consider using packer before deploying your code. It will compress your JavaScript code and in most cases will make your code smaller. When you use the compressed JavaScript online, it will result in bandwidth savings.

The method is simple, copy your code on the Paste text box, select whether you want to use Base62 encode and Shrink variables option, and click the Pack button. The documentation says that you must terminate statements, including function declarations, with semicolon so you better abide it.

(more…)

Global variable scope in PHP

Wednesday, June 11th, 2008 by Agro Rachmatullah

I need to do some WordPress hacking so I’m actually playing around with PHP at this time. What surprised me recently was that this code doesn’t work as I expected:

$foo = 1;
function bar()
{
   var_dump(isset($foo));
}
bar(); // gives bool(false)

It turns out that in PHP global variables are not automatically available inside functions, to prevent accidental overriding. (I have a C-ish background) To use a global variable inside a function, we need to use the global keyword:

(more…)