CHALLONGE! WordPress Plugin

Download the latest Challonge WordPress Plugin:
http://wordpress.org/plugins/challonge/

Do you like this plugin? Please consider donating to show your support.

Thank you for all the support!

NOTE

Most of the comments on this post are regarding previous revisions of this post.

Upcoming Update Information

This information has been moved to a different page:
http://zavaboy.org/challonge-wordpress-plugin/

Alternative for MySQL UNIX_TIMESTAMP()

In 2038, 32-bit systems and 32-bit code has a problem. It’s well documented online, so if you do not know much about it, check it out on Wikipedia then come back and continue reading here. Even if you are running MySQL on a 64-bit machine, MySQL is not—at least not fully.

Ideally you would want to use the scripting language running your application to do the conversion. For example, place your date string from your result and run it through strtotime() or the DateTime class in PHP. But let’s assume that you are unable to do that for whatever crazy reason and you need to have the date and time as an Unix timestamp in your query results. What do you do?

Assuming we still use MySQL in 2038 and the problem isn’t fixed by then or you are working with future dates that may go into or past 2038 before we get there, there is a way around it. If you use:

TO_SECONDS(`datetime`)-62167219200+TO_SECONDS(UTC_TIMESTAMP())-TO_SECONDS(NOW())

instead of:

UNIX_TIMESTAMP(`datetime`)

in your MySQL queries, you will get exactly the same Unix timestamp, but future ready. It will continue to work in and past 2038.

Just execute this query to see it demonstrated:

SELECT
    `datetime`,
    UNIX_TIMESTAMP(`datetime`) AS `timestamp`,
    TO_SECONDS(`datetime`)-62167219200+TO_SECONDS(UTC_TIMESTAMP())-TO_SECONDS(NOW()) AS `timestamp_alt`
    # NOTE: 62167219200 == TO_SECONDS('1970-01-01 00:00:00')
FROM
    (
        (
            SELECT NOW() AS `datetime`
        )
        UNION ALL
        (
            SELECT DATE_ADD(NOW(), INTERVAL 30 YEAR) AS `datetime`
        )
    ) `datetest`

This works in MySQL 5.5 or later. If you are stuck using a version older than 5.5 or need to be backwards compatible, it’s a little more complicated:

((TO_DAYS(`datetime`)-719528+TO_DAYS(UTC_DATE())-TO_DAYS(CURDATE()))*86400)+TIME_TO_SEC(TIME(`datetime`))+TIME_TO_SEC(UTC_TIME()-CURTIME())
# NOTE: 719528 == TO_DAYS('1970-01-01 00:00:00')
# NOTE: 86400 == seconds in a day

Now, go forth and be ready for the 2038 problem… at least in your MySQL queries. If you find any place for improvement, please feel free to share your thoughts in the comments. Thanks for reading!

Thanks Eren!

This morning, I noticed an influx of followers on my Google+. Last time I had an influx like this was when Eren McKay shared a circle with me in it. This time she shared my blog. Thank you Eren!

Well, since I’m writing, I might as well update on things since my last post.

Work

So I actually lost my job at Team Detroit in early May. I’m not going to get into details but I supposedly lost it because they canceled the project I was almost done with. I enjoyed it there as you may have heard from my last entry.

In late May, I started work at Mango Languages. Mango is language learning that is easy. If you have any interest in learning a new language, you can do it with Mango. You can use Mango free at your library too if they carry it; if they don’t ask them to. Anyway, I know this sounds like a plug for Mango, which I guess it is, but it’s my blog so my thoughts are here.

I Should Talk More

It has been a long time since my last post. I guess I am not a writer. I believe that can change. I haven’t given up and I’m certain I never will. I’m more focused on other things, like work for one. Which brings me to the first thing to talk about…

Work

Since the beginning of this year, I’ve really applied myself more to looking for a job. In February, I eventually found myself cornered by 3 companies showing strong interest. It was one of the more tougher decisions in my life, but it was definitely a good one to have. Mid-month, I went in for an interview with my third choice out of the group. When I left that interview, they were placed as my number one choice with no hesitation.

The next morning, I missed the call from my recruiter. I listened to his voicemail and started going crazy, like every muscle in my body was ecstatic and excited. I found out I was hired. I guess I aced the interview. Got the contract signed and on the last week of February, I started working for this wonderful advertising agency that is unlike any other. They support creativity and passion much they same way I do. This advertising agency is none other than Team Detroit.

Team Detroit’s biggest client is Ford. That is why I am now working with an excellent technology team at Team Detroit who work on the Ford and Lincoln websites. I’m currently a front-end developer there.

“Find a job you love, and you will never have to work a day in your life.” – Confucius

I believe I have found a job I love.

Play

All I really wanted to say here was that I am looking forward to 2 games that are coming out this year.

The first game is the action-packed Borderlands 2. I enjoyed the first one, now the second one has to be mine. I can’t wait to play it!

The second game is an action-packed MMORPG called Firefall. I see this game a mix of Halo, Unreal Tournament, and Borderlands. To top it off, it is free-to-play!

Oh yeah, one more thing. I have a private SMP Minecraft server. If you are interested in joining my Minecraft adventures, just let me know. Server details may be found at 64b.me.

My Logical Mind

My mind is a hyperactive one. My mind can race though seemingly hundreds of different ideas in a matter of minutes. It drives me nuts, especially when I’m trying to sleep or those occasions I really need to keep my focus on the task at hand. Well, because this post is about my mind, it will be a bit random and may not follow any one topic. Don’t worry, it doesn’t always make sense to me either.

I always notice on a movie or TV show when the computer screen is totally fake. The actor may type whatever gibberish on the keyboard and it will still do what it is asked to do. It seems only the shows and movies geared towards geeks actually pay attention to this. The movie the springs to my mind is The Matrix, the commands they used actually existed and the interfaces were believable instead of the overdressed interfaces you would find on CSI.

Probably due to the fact that I found interest in programming a long time ago, I think logically. I guess I’m kinda like Spock, but with a better sense of humor. My mind enjoys puzzles and certain challenges. That’s probably why I now have a strong interest in Rubik’s Cubes.

If a challenge gets between me and an interest, I do what I can to overcome it. A good example of this is when I wanted to know how wave files were put together. I knew it shouldn’t be so hard since wave files are as raw as you can get for audio. When I managed to make a PHP script generate waveforms in wave format, that was my first real experience working with binary data. Because of that, I’ve learned not only the building blocks of wave files, but I learned a lot about binary data. I later made my own binary file format.

PHP: Improving print_r() with print_pre() Wrapper Function

When you need a simple debugging function and print_r() is just not enough, you need a good wrapper function. You need print_pre().

Most print_pre() functions out there just wrap the print_r() output with the <pre> tag. Useful, but not that useful. This print_pre() function has evolved over the time I have used it. I have used it across multiple jobs. Where it is now is good, anything added to it would be for specialized cases.

This print_pre() function does a bit more than just wrap the print_r() with <pre> tags. Sometimes you may not be able to view any output easily, so it may output to a file if you so desire. It can be used in place of any print_r() as it may be used exactly the same. Another cool feature is word wrapping, which basically does away with the <pre> tag and wraps it in a <p><tt> combo.

function print_pre ($expression, $return = false, $wrap = false)
{
  $css = 'border:1px dashed #06f;background:#69f;padding:1em;text-align:left;';
  if ($wrap) {
    $str = '<p style="' . $css . '"><tt>' . str_replace(
      array('  ', "\n"), array('&nbsp; ', '<br />'),
      htmlspecialchars(print_r($expression, true))
    ) . '</tt></p>';
  } else {
    $str = '<pre style="' . $css . '">'
    . htmlspecialchars(print_r($expression, true)) . '</pre>';
  }
  if ($return) {
    if (is_string($return) && $fh = fopen($return, 'a')) {
      fwrite($fh, $str);
      fclose($fh);
    }
    return $str;
  } else
    echo $str;
}

The print_pre() function has simple usage:

mixed print_pre (mixed $expression [, mixed $return = false [, bool $wrap = false ]] )

The second parameter, return, works just like the return parameter on print_r() except when a non-empty string is passed. If a string is passed to the return parameter, it will be treated as a file path to save the output to and will continue to return the output. The last parameter, wrap, is rather self explanatory; it will allow long lines to break and the text will not be preformatted if set to TRUE.

Everybody likes examples, so here are a few for you:

// Let us assume print_pre() and $obj were defined before this point

print_pre($obj);
// the output is simply printed

$string = print_pre($obj,true);
// $string contains the output

echo print_pre($obj,'debug.htm',true);
// the output allows wrapping, is saved to debug.htm and then printed

And that is the print_pre() function. Ok, my print_pre() function. Enjoy!

Suspended Animation

I just watched this TED Talk from last year where biochemist Mark Roth explained the advancements that were made in the field of suspended animation.

He talked about how suspended animation with the right concentrations and exposure of the toxic gas hydrogen sulfide has helped reduce damage to organs and tissue. Mark also mentioned how much this can help people in trauma.

This has got me thinking about the possibilities this may unlock. If there can be a standard way to suspend a trauma victim and buy them a tremendous amount of time, this could be one of the best advancements in modern medicine. Just think about small town out in the middle of nowhere, where there is no hospital for miles, that has this on hand. If someone in the town has a heart attack and is administered hydrogen sulfide to give them more time, they could be airlifted to the nearest hospital suspended, but still alive, where they can then get all the medical attention they need. This could give proper medical attention to those who may otherwise have no choice but to be treated by someone who is medically untrained and is subject to possibly fatal mistakes.

Much is yet to be learned about suspended animation, but if we can get through it, perfect it, and establish it safely into society, I can’t imagine how many lives it could save.

What are your thoughts on suspended animation? What do you believe the future could be like with suspended animation?

The Adventure

Ok. Well, the first post of my hopefully active blog is this.

I’m really looking forward to getting back in action and start blogging once more. My previous blog over at zavaboy.com has been abandoned, at least for now.

So, what am I planning for this blog? I haven’t planned to be honest. My good friend, Erin Mckay, is an avid blogger and told me that I should just make my first post. Now that I have done that, I must think about what I need to do next. I do have some ideas for future posts, some are just going to be updated versions of posts I made on my old blog.

I’m sure I’m going to have to search deep within myself to get to the good stuff. Going that deep inside myself sounds scary to me. Inside, I have a dark side and a light side just the same way as everyone else. Expressing myself is something I always had a challenge doing, so I think it may take some time to see more personal posts emerging from the cracks.

Another adventure I seek is WordPress itself. Any regular to the internet may recognize that this blog is WordPress. This is my first real use of WordPress and I am looking forward to working a lot with it and maybe even build a plugin or two. My reasoning is simple; I want to learn. Well, that and the fact that WordPress has been touted as the best CMS, or content management system, available. I previously used Drupal, which my previous blog is using. My experience with Drupal has been okay, but not the smoothest of rides as every new major version seems to never fail to break something. As Drupal is a nice CMS, I figured I should give WordPress a shot, probably something I should have done a long, long time ago. Another good reason to learn WordPress is for a job. I have been noticing in my recent job searching that WordPress is mentioned more than any other CMS, so the choice from that alone seems to be obvious.

So, I think I should save all the rest of my rambling for other posts.

I would like to invite you on an adventure. The adventure is here. The adventure is now. The adventure is abnormal. The adventure is me. Welcome and mind your step.