‘eregi’ is deprecated errors

The other weekend I was setting up Plogger for my daughter to share her photos. She’s been really getting in to photography and I think she’s really getting good at it. If you’re interested (and she starts uploading stuff and takes down the pics I posted) you can check it out here: lexie.fourthwoods.com

Anyway, apparently I’m running a newer PHP than Plogger was originally written for because I got a bunch of errors along the lines of:

Deprecated: Function eregi() is deprecated in blah....

It seems the whole class of functions have been deprecated in PHP 5.3.0. Fortunately there is an easy fix. For instance:

eregi("NIKON", $make)

should be changed to:


Note the regular expression is wrapped in ‘/’ characters which denote the pattern to search. after the last ‘/’ is the ‘i’ modifier flag which indicates case insensitive which is what eregi does.

Other functions that can be replaced similarly are:

ereg()          // replace with preg_match()

ereg_replace()  // replace with preg_replace()

eregi()         // replace with preg_match() with the 'i'
                // modifier

eregi_replace() // replace with preg_replace() with the
                // 'i' modifier

Posted in PHP, Programming

Sudoku Forever

I’ve taken the Sudoku JavaScript game I created and ported it to an app for Android. Sudoku Forever is based on the same Sudoku solver described in my JavaScript article but with a few more improvements and optimizations. It is very fast consistently generating a new board between 200 and 500 milliseconds.

Here’s a screenshot:
Sudoku Forever Screenshot

Sudoku Forever also features the ability to save the current game state whenever you close the app as well as Save Game slots so you can save the current game and come back to it later.

Here’s the Home Page for Sudoku Forever.

And of course the link to it on Google Play.

QR Code for Google Play link

Let me know what you think and be sure to leave a rating and feedback on Google Play!

Posted in Android, Java

Poor-man’s promo check for Android apps.

When I first created Baby’s First Game for Android I gave away a free promotional version. This promotional version was basically to get feedback from people before the real release. I wanted the app to only work for a limited time after which it would disable itself. I suppose I could have just released the full version without any limitations but I didn’t know how well (or poorly as it turns out) my app would do or how a free version floating around would affect it. Plus I wanted to see how one might create a time limited app anyway.

I created a single method called doPromoCheck() that stores the current install date in the app settings and checks them on every start up. I also added a check to alert the user once a day that the application was a promotional version and would expire in x number of days. This message I wanted shown only once a day as to not annoy the users. Here’s the method with some static class variables for configuration:


   private static final String PROMO_DATE = "promoDate";
   private static final String PROMO_DISPLAYED = "promoDisplayed";
   private static final long DAYS_MILLIS = 24 * 60 * 60 * 1000;
   private static final long PROMO_DURATION = DAYS_MILLIS * 30; // 30 days
   private void doPromoCheck()
      SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = prefs.edit();
      long now = System.currentTimeMillis();
      long exp = prefs.getLong(PROMO_DATE, now + PROMO_DURATION);
      editor.putLong(PROMO_DATE, exp);

      // check if the promo period has ended
      if(now > exp)
         AlertDialog alertDialog;
         String ok = getResources().getString(R.string.label_ok);
         alertDialog = new AlertDialog.Builder(this)
            .setPositiveButton(ok, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                  finish(); // stops the app as soon as the dialog is dismissed.

         String title = "Promo Version";
         String msg = "This promotional version has expired. Please purchase the official version from Google Play.";
         long disp = prefs.getLong(PROMO_DISPLAYED, now);

         // only display the dialog if it's been one day since the last time it was displayed
         if(now >= disp)
            // save the next display time for one day from now.
            editor.putLong(PROMO_DISPLAYED, now + DAYS_MILLIS);
            AlertDialog alertDialog;
            String ok = getResources().getString(R.string.label_ok);
            alertDialog = new AlertDialog.Builder(this)
               .setPositiveButton(ok, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                     // do nothing

            String title = "Promo Version";
            long days = (exp - now) / DAYS_MILLIS;
            String msg = "This promotional version will expire in " + days + " days. Please consider purchasing the official version from Google Play.";

The first time this is run it calculates the expiration date and stores it in the private app settings. Each time it is run after, it pulls the expiration out of the app settings. To use this method in your app, put the call as the first thing in your main Activity onCreate() method:

   protected void onCreate(Bundle savedInstanceState) {


That’s it. Your application will now only last for 30 days and will simply show the promotional period ended dialog after. Of course, the app can be uninstalled and reinstalled to reset the expiration but it’s annoying and probably not worth the hassle to most people.

Posted in Android, Java, Tips and Tricks

undefined reference to IID_IPicture

I was writing a small test application to display some pictures and ran into a linker error complaining about an undefined reference to IID_IPicture. In COM interfaces are identified by a globally unique identifier string. To get the linker to pick them up you need to link to uuid.lib.

Posted in C, Cpp, Programming Tagged , , ,

Replace Non-Alphanumeric Characters in a C++ String

I needed to replace the non-alphanumeric characters in a std::string. While the Java String class has the replace() and replaceAll() methods for doing this, the std::string class has no such utility methods. Instead you can use the std::replace_if function from the Standard Template Library. Here’s some example code:

#include <iostream>
#include <string>
#include <algorithm>

int isNotAlphaNum(char c)
        return !std::isalnum(c);

int main(int argc, char* argv[])
        std::string s1 = "some/string/with*/nonalpha/characters+1";

        std::cout << s1 << " : ";
        std::replace_if(s1.begin(), s1.end(), isNotAlphaNum, ' ');
        std::cout << s1 << std::endl;

        return 0;

The third parameter of the replace_if() function is a pointer to a function that performs the desired check and returns either true or false if the input satisfies the condition. The last parameter is the character to replace the matched character, in this case a space.

This program produces the following:

$ ./replace.exe 
some string with  nonalpha characters 1

Posted in Cpp, Programming, Tips and Tricks Tagged , , , , ,

Convert C++ String to Lower Case (or Upper Case)

I don’t usually need to convert string case in C++ so when the need comes up I’ve usually forgotten how to do it and have to Google.

While the Java String class has toLowerCase() and toUpperCase(), C++ std::string does not have such a utility method. Instead, you need to use the std::transform() function. Here’s some example code:

#include <iostream>
#include <string>
#include <utility>

int main(int argc, char* argv[])
        std::string s1 = "lowertoupper";
        std::string s2 = "UPPERTOLOWER";

        std::cout << s1 << " : ";
        std::transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
        std::cout << s1 << std::endl;

        std::cout << s2 << " : ";
        std::transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
        std::cout << s2 << std::endl;

        return 0;

Produces the following:

$ ./case.exe 
lowertoupper : LOWERTOUPPER
UPPERTOLOWER : uppertolower

Note that while the Java toUpperCase() and toLowerCase() methods do not modify the original string, the std::transform function does.

Posted in Cpp, Programming, Tips and Tricks Tagged , , , , ,

Baby’s First Game

Baby's Fisrt Game I’ve just launched Baby’s First Game for Android on Google Play. This is a game designed specifically for infants, toddlers and preschool age children. They will have fun learning about colors, shapes, numbers and letters. The skill levels are very customizable and can grow with your child. This game was inspired by Baby Smash by Scott Hanselman and watching the games my own kids were interested in.

Three mini-games provide a fun way to get familiar with and learn to identify colors, shapes, numbers and letters. Just for Baby is targeted specifically at infants and young toddlers. It teaches action/reaction while familiarizing baby with colors and shapes. When baby touches the screen, a happy shape appears. Find It! tests your child’s ability to identify colors, shapes, letters and numbers by picking them out of a group. Pop It! is a fun way to work on your child’s hand/eye coordination while “popping” shapes as they fly across the screen.

Baby’s First Game is and always will be Ad free.

Baby’s First Game for Android is available now on Google Play:

Get it on Google Play

Posted in Android, Java Tagged , , , , , , , , , , , , , , ,

Are you infected?

Ever think you could never be a part of a botnet without knowing about it? There are millions of PCs out there infected. Most of the owners do not know about it, many don’t know enough about it to realize they have a problem and some just don’t care. But it is a serious issue.

I found some interesting activity on my website recently that really highlights how alive and well these botnets really are. I have a Wiki set up that I don’t really publicize since it really is only a collection of notes that I find convenient to have accessible online. A few months ago a spammer found it. Now, I am at fault for not initially disabling open registration which means anyone could sign up for an account and add content. Well, over a few weeks using a botnet the spammer posted about 50,000 spam articles before I noticed they were there.

I’ve since cleaned up the mess and disabled open registration. However, the botnet was still chugging away trying to create new accounts and post articles. Trying to ease the traffic I started blocking IP address ranges from the worst offending networks. This helped a lot but they were still chewing up bandwidth. Finally I just blocked everyone but my own IP address to see how long it would take before they gave up.

They are still trying harder and harder.

Monthly Traffic

So, normal traffic to my site was about 30 visitors a month. As soon as I noticed this jumped I knew exactly what happened. After I cleaned up the mess and blocked most of the offending networks my bandwidth dropped back down but I still can’t see normal visitors through the noise. Finally I gave up and just blocked everyone but my own IP address. If you try to access the Wiki now you will get a “403 Forbidden” error.

Daily Traffic

I noticed the traffic dropped significantly when people shut down the machines over the long 4th of July holiday weekend. So, your machines are infected but you don’t know or don’t care enough to figure it out and fix it? Hmmm…

Traffic Source

What did surprise me was the source of the traffic. Apparently most traffic is coming from Canada followed in second by France. USA is 4th… Why would the Canadian and French machines go down over the 4th weekend? I’m at a loss on that one.

Now, even though the entire site is blocked returning a 403 error, instead of giving up and going away they seem to be trying even harder. After I blocked everyone the hits dropped to about 160k in May. However, in June this jumped to 1.2 million! And now about a third of the way into July it’s already passed that at 1.4 million? Geesh! That’s on track for almost 5 million hits this month.

I may put it back online in a few weeks. However, the 15 byte error page takes up a lot less bandwidth than the actual site pages so we’ll see.

Posted in Security Tagged , , ,

Pretty Print Tables

A while ago I wrote a chunk of code to dump data to a console window in a formatted table. Something like you’d see in a SQL console when doing queries. I’ve finally gotten around to open sourcing it so here’s a description of how to use it and where to find it.

To format data into the table structure, a table must first be initialized using table_init(). The data will be output in either CSV format or a pretty printed table depending on the
value of the verbose parameter.

Rows are added to the table with the table_row() function. Each column in the row is specified by a position in the format string. For example the first format specifier is the first column, second column two, etc. The total number of columns for a table is determined by the call to table_row() with the highest number of format specifiers.

The format parameter for table_row() takes a C style format string. The acceptable format specifiers are a (mostly) subset of the printf() format specifiers with the addition of 't' for a timestamp.

Format specifiers:

specifier Output
s or S String of characters
c or C Character
d or i Signed decimal integer
u Unsigned decimal integer
o Unsigned octal integer
t Timestamp specified by a time_t value
x or X Unsigned hexadecimal integer
f, F, g or G Decimal floating point

[width].[precision] are also supported. Note that precision defaults to 0 so with floating point values it must always be specified or the value will be truncated to a whole number.

Finally, when data is done being added to the table, it is printed using the table_commit() function.

int main(int argc, char* argv[])
	struct table_t* table = table_init(stdout, "Test Table", 1);

	table_row(table, "%s%s", "Column 1", "Column 2");


	table_row(table, "%s%s", "String value", "test string");
	table_row(table, "%s%c", "Character value", 'c');
	table_row(table, "%s%d", "Signed integer", -1);
	table_row(table, "%s%u", "Unsigned integer", 42);
	table_row(table, "%s%o", "Octal integer", 511);
	table_row(table, "%s%8x", "Hexadecimal integer", 255);
	table_row(table, "%s%.5f", "Floating point", 3.14159);
	table_row(table, "%s%t", "Timestamp", 0);


	return 0;

Produces the following output:

$ ./table.exe 
| Test Table                                                    |
| Column 1            | Column 2                                |
| String value        | test string                             |
| Character value     | c                                       |
| Signed integer      | -1                                      |
| Unsigned integer    | 42                                      |
| Octal integer       | 0777                                    |
| Hexadecimal integer | 0x000000ff                              |
| Floating point      | 3.14159                                 |
| Timestamp           | Thursday, January 01, 1970, 12:00:00 AM |

The code is free under the MIT license and can be downloaded here.

Posted in C, Programming Tagged , , , , ,

Securing WordPress

In light of the latest attacks on WordPress sites everywhere I thought I should probably step up security a bit here. Not that I thought I had a bad password or anything but I still had the default admin account enabled. This attack is being conducted by a huge botnet of about 90,000 computers trying a large dictionary of passwords against the admin account. I wasn’t too concerned but the fact that it was targeting the admin account and seeing a huge spike in access to wp-login.php I still had an uneasy feeling in my gut.

First, the admin account is now disabled. They can target it all they want!.

Second, no one should need to access wp-login.php from anywhere in the world. So I updated .htaccess to only allow access from my IP address.

<Files "wp-login.php">
Order Deny,Allow
Deny from all
Allow from xxx.xxx.xxx.0/24
ErrorDocument 403 "http://www.google.com"

Third, installed the Limit Login Attempts plugin for WordPress which will automatically block an IP after so many failed login attempts.

Posted in Security, Tips and Tricks Tagged , , , ,