Code snippet

During work today, todays assignment is to test a website which recently went offline, I decided to write a tiny script that helps me answer the question “When do my commute card’s period end?” When I buy the card each month it only says “Purchase date + 30 days”.. So I never really know the exact day, unless I manually count, the card stops working.

So I wrote this lil’ script, and I wonder why I didn’t do this sooner -.-…



Dunno what to call this…

I’ve been searching for a way to get the color between two colours based on only a percentage. I’ve never been great with graphics / colours e.t.c.

But this script below is a modified version of this¬†script, where you can easily create your own gradients. As I didn’t create the original script, all fame go to the author Andrew Pociu.


function PercentColor($Percent, $HexMin = NULL, $HexMax = NULL) {
    $maxPercent = 100;
    $HexMin = $HexMin ? $HexMin : "000000"; // Set own default colour here.
    $HexMax = $HexMax ? $HexMax : "FFFFFF"; // Set own default colour here.

    $FromRGB['r'] = hexdec(substr($HexMin, 0, 2));
    $FromRGB['g'] = hexdec(substr($HexMin, 2, 2));
    $FromRGB['b'] = hexdec(substr($HexMin, 4, 2));

    $ToRGB['r'] = hexdec(substr($HexMax, 0, 2));
    $ToRGB['g'] = hexdec(substr($HexMax, 2, 2));
    $ToRGB['b'] = hexdec(substr($HexMax, 4, 2));

    $StepRGB['r'] = ($FromRGB['r'] - $ToRGB['r']) / ($maxPercent);
    $StepRGB['g'] = ($FromRGB['g'] - $ToRGB['g']) / ($maxPercent);
    $StepRGB['b'] = ($FromRGB['b'] - $ToRGB['b']) / ($maxPercent);

    $RGB['r'] = floor($FromRGB['r'] - ($StepRGB['r'] * $Percent));
    $RGB['g'] = floor($FromRGB['g'] - ($StepRGB['g'] * $Percent));
    $RGB['b'] = floor($FromRGB['b'] - ($StepRGB['b'] * $Percent));

    $HexRGB['r'] = sprintf('%02x', ($RGB['r']));
    $HexRGB['g'] = sprintf('%02x', ($RGB['g']));
    $HexRGB['b'] = sprintf('%02x', ($RGB['b']));

    $GradientColors[] = implode(NULL, $HexRGB);

    return implode(NULL, $HexRGB);

for($i = 0; $i < 100; $i++) {
    echo "<div style=\"background-color: #" . PercentColor($i, "20DD20", "DD2020") . "; width: 100px; height: 10px;\"></div>";

New project

As of yesterday, when I realized how much spare-time I have on my work atm, I decided to start writing my own IRC bot.

I have my own IRC server and I needed some way to administrate the channels automatically. I’ve been waiting a while for a friend to provide me with his python bot, but as I’ve been waiting for that quite a long time now I decided it’s time to develop my own.

Why java?
Simply because it’s portable to almost every device in the world and it’s one of my top 2 languages, when it comes to knowledge and experience.

Now, what functionality would You like in an IRC bot but never seem to find? Leave a comment!