Posts Tagged ‘php’

Getting Paid to Write AI

Posted June 4th, 2010 at 20:01 CST in php | Tags: , , | Leave a Comment »

One of the best parts of my previous job—and also the part that kept me going for so long—is that I had the chance to work on a variety of projects, in many cases for completely different business ventures. One week I had been privileged with the task of writing a small program which ended up being semi-intelligent (of course artificially, thus AI). As it so happens I also seemed to have stretched PHP to its limits.

When originally typing up this post, I kept the details to a minimum, but now that I’ve moved on I can freely discuss it. This program—code-named “twitterbot”—was tasked with searching Twitter for tweets with certain keywords within a radius of a location, like for tweets containing “hungry” within 30 miles of Minneapolis, and @reply to that person within an hour of their tweet about … a website I probably shouldn’t name. However this becomes tricky since Twitter is really good at detecting spam, and a lot of Twitter users really hate spam (like me). To get around it, I made a bunch of twitter accounts using anonymous email addresses, created bios, set profile pictures, and set color schemes, all to make them look like real people.

However, just because a Twitter account has a profile picture, it does not mean it will be treated like a human: the account has to have realistic-looking posts. No problem. First I set a limit to the number of posts an account can make per day, make sure all the posts are within normal waking hours (like 6am to 10pm), have 30-50% of the tweets be the spamming tweets, and the rest be copies of tweets from a different search that none of the accounts will be replying to. Then since the spam tweets themselves are also randomized, the sum of it all equals twitter accounts that even people are sometimes not able to recognize that the account is a bot.

For the technical, I wrote this program in PHP both because we had thousands and thousands of lines of legacy code in other programs that we didn’t want to touch, and second because it is extremely simple and quick to code and deploy. With a semi-AI bot though, the scene changes and suddenly both opportunities and concerns that weren’t there before suddenly are. Example opportunity: pcntl-fork becomes available. Example concern: the PHP program will probably be running as a daemon on a server, use up all your RAM and explode.

In the end, the bot ran strong for about 2 weeks before management changed their minds and had it shut down—spamming people does not make for good press. I felt terrible having to write such a program; I really don’t like spam, let alone being the one doing the spamming. But since then I’ve moved on to a position at a different company and write ethical code now.

Conversation About PHP

Posted December 28th, 2009 at 20:57 CST in Thoughts | Tags: , | 3 Comments »

I wrote down this conversation I had with a co-worker the other day. I just found it, and thought I would share it.

me: how do i tell php to be smarter?
co-worker: you have to enable that in your php.ini
me: oh of course
co-worker: but you have to make sure php was compiled with the –smart flag
me: dang

If it’s good enough for Google

Posted April 16th, 2009 at 10:49 CST in Uncategorized | Tags: , , | Leave a Comment »

A few weeks ago, I realized that in order to expand my possibilities in the programming world, I need to master another language—one not built only for the web. PHP is a good language for the specific task of web programming, but its usefulness ends there. I do know that there are projects that aim to expand what PHP is capable of: PHP-GTK, PEAR, PELC. But these can only do so much. I need a language that I can do cross-platform programming of desktop applications, yet be flexible and is already extensively used (so that it’s worth my time to learn it).

After assessing my options, I’ve concluded Python is the language I need to master. On top of fulfilling all my requirements, Google uses it, and if it’s good enough for Google to use for applications that millions of people rely on every day, then it’s good enough for me. Besides that, it makes a great calculator in Windows.

I’ve looked at Python before, and it didn’t look too amazing. But now that I live in a different world and have a new perspective, Python is awesome. Some people frown on the forced indentation, lack of end-line symbols, and non-dollar-sign-prepended variables. After writing a few “hello world” programs, I believe these are not failures but perks. If you are among a team of people writing a massive application, these qualities might keep you on this side of sanity. However, the “batteries-included” philosophy of Python and its hyper-extendability really push it over the top.

Learning about garbage

Posted April 2nd, 2009 at 10:57 CST in Uncategorized | Tags: , | Leave a Comment »

After switching careers to being a full-time programmer, I have started to see and realize aspects of programming that truly amaze me. Before starting this job, I worked on PHP and Java what I though was a considerable amount. I was wrong, I only scratched the surface with what these languages can do and I had no idea of their limits.

The real-life example from this week is memory management in PHP. That’s right, I have a html page generated by—what I (and confirmed by my project leader) think is—efficient PHP code which I had to write in memory management code for. I was confused out of my mind for a while, since PHP has built-in garbage collection. After looking at my code further and analyzing what was going on, I started to understand what garbage collection is and what its limits are. Of course though, just because I understand what is going on doesn’t mean that I actually coding memory management is easy. Calling unset() at the right time is key.