• Using PHP to Back Up All of Your MySQL Databases

    If you haven't worked too much with the Linux bash (or command line), the following tasks may seem over-complicated to you:

    • Run a PHP script every day at a specified time (a cron job)
    • Have that PHP script get a list of all databases for a given user on a server
    • Back up all of those databases

    So in the interest of helping you out, I gift thee a guide...

    First let's get that PHP script. You can find it on GitHub in the file backup.php or by clicking the following link: https://github.com/janhartigan/phpMySQLAutoBackup. Create a directory somewhere on your server (outside of your web root) called scripts and place backup.php in that directory.

    Now that the script is on your server, let's go over it and see what it does.

    <?php

    // Creates a mysqldump and emails the resulting dump file
    $dbhost
    = "localhost";

    // Edit the following values
    $dbuser
    = "mysql_user"; //the mysql user
    $dbpass
    = "mysql_pass"; //the mysql password
    $path
    = "/home/admin/backups/mysql/"; //the directory path to where you want to store your backups

    Here you must define the following items:

    • $dbhost: This is normally localhost, unless your mysql driver is hosted on a foreign server
    • $dbuser: The mysql user that will connect to the database
    • $dbpass: The password for $dbuser
    • $path: The directory path where you want to store your backups. On my server, I store them in /home/admin/backups/mysql, but you can store them anywhere you like
    Read the whole article...
  • The Purpose of Life is to Hydrogenate Carbon Dioxide

    I was just reading through Scientific American and I came across this article:

    http://blogs.scientificamerican.com/observations/2011/09/23/how-life-arose-on-earth-and-how-a-singularity-might-bring-it-down/

    In it, George Musser writes about a recent talk given by Caltech cosmologist Sean Carroll. Carroll touched on some interesting themes like the origin of life, similarities among all life forms at the cellular level, and what the approaching (presumably) singularity may mean for life on Earth.

    Read the whole article...
  • An Extension to the Knockout JS Mapping Plugin

    I've written a useful extension to a popular plugin for the Knockout JS library. For those too lazy/bored to go on, the code and a simple description are here. For the rest of you, a bit of exposition...

    Thanks to the helpful prodding of a friend, I've finally started using Knockout, a JavaScript library that abstracts away the most painful part of writing JavaScript: DOM manipulation. Of course it goes without saying that the advent of jQuery made DOM manipulation much simpler than it used to be, but regardless, there was still the issue of mixing code (JS) and structure (HTML). Doing this can get very sloppy and verbose, even if you manage your code intelligently. If this doesn't make sense to you, think about it like a photographer moving from an analog to a digital camera: now he can worry more about the art of photography than the task of turning negatives into photos.

    The difference between Knockout and normal JavaScript is that you don't store or manipulate data in HTML. Instead, you declare properties of an object to be "observable" and then mark down in the HTML where you expect those values to show up for the user. This way, if you change the value of one of these properties, Knockout takes care of where it should go in the HTML. But this isn't a one-way operation: a declared observable also reads from the HTML when a user makes changes to, for example, a text input. As you might be able to imagine, this makes forms stupid simple to code.

    Read the whole article...
  • Tailgating Ventures is Now Live

    TV logo

    It's been a little while coming, but tailgatingventures.com is now live! This was a fun project to work on as it was my first experience with the world of serious tailgating, despite having gone to school at Wake Forest.

    When Tailgating Ventures initially contacted me, they wanted to get rid of their old corporate site and replace it with a WordPress-based CMS. Working together with an design associate of mine, we took their vision of a specific WordPress template and customized it to fit their needs. Some of the prominent features include a full blogging system, several unique custom pages, a product of the month and picture of the month admin control, and a JavaScript-based RSS reader that gets the Tailgating Ventures blog network on demand.

    You should check out their site and maybe you'll be as surprised as I was to find out that there are entire organizational structures that surround the world of tailgating.

    Read the whole article...
  • Creating a JavaScript Complex Number Class

    This is the second in a series of articles on fractal geometry. In this one I'll be explaining how to make a complex number class using the JavaScript programming language. If you don't understand complex numbers, be sure to check out my article called Understanding Fractal Geometry.

    A complex number is any number that contains both a real and an imaginary part. For example:

    Where i is defined as the square root of -1. (note: As Kaji Ryouji points out in the comments, the technically correct definition is: i2 = -1.)

    Because complex numbers contain a part that cannot be further broken down (the i part), doing math operations on fractals works essentially like those in algebra. For example, when adding two complex numbers together, you only add the parts together that have similar factors. So (2a + 1) + (3a + 4b) becomes (5a + 4b + 1). Similarly, given two complex numbers (5 + 2i) and (3 + 5i), adding them together results in (8 + 7i) because 5 + 3 is 8 and 2i + 5i is 7i.

    Multiplication of complex numbers also works like algebraic multiplication, except we have to keep in mind that multiplying i by itself, by definition, gives us -1.

    Read the whole article...