Original Music June 19, 2010 No Comments
I know this is coming a bit late, but if you haven’t already please check out the music from my Composition Distinguished Major Recital here. The event occurred on April 25th, 2010. Thanks!
A Simple PHP Captcha Script: Captcha_lite May 11, 2010 No Comments
Last night I created a simple captcha script that is more than secure enough for most applications. It consists of three scripts: index.php, which contains a sample form, process.php, which validates the form, and captcha_lite.php, which creates the captcha.
Demo | Download scripts and images
Features:
- Lightweight, well-commented scripts
- No need for a MySQL database
- You can use your own images
- You can choose how many digits appear in the captcha
For your convenience, here are the scripts in .txt format. To get the images you’ll still have to download the .zip archive.
index.php | process.php | captcha_lite.php
I hope this is helpful for you. Please give me some feedback!
New site: “Why I’m Great” May 4, 2010 No Comments
A pet project of mine over spring break and the past few days has been a site called Why I’m Great, a forum similar to fmylife.com where, instead of complaining about how their lives suck, visitors can brag about how awesome they are, all under the cloak of web anonymity. My friend Sean came up with the idea for the site, and now that it’s up and running we have the task of making it popular. We’ve created a few posters (controversy-intended), pictured below:
There are some nasty display bugs with IE, which I’ll get around to fixing after my exam on Thursday. It can wait, just like Microsoft’s plans to fix their broken web browser.
So you want to trigger a cron job with PHP? April 29, 2010 No Comments
As a few of my friends know, I’ve been working on a special programming project lately. I developed most of it during Spring Break but had to take a break since my Distinguished Major Project took over my life until now. I still have some school work to do, but I couldn’t stop myself from tackling this problem today. One small part of my project involves creating a mailing list that will send emails to subscribers periodically (for example, let’s say every day). In order for that to happen, the mailing list script needs to run once every day. This is relatively easy to set up with a cron job, a time-based job scheduler in Unix systems.
The problem, however, is that I plan to distribute my project, complete with a custom content management system, to several clients. Needless to say, I don’t want them to have to figure out what the hell a cron job is, much less how to set one up. So I scoured the internet looking for a way to create a cron job with PHP. That should be simple, right? Maybe even use PHP to call a shell script which will in turn set up a cron job? After searching for a while I couldn’t find a satisfactory answer, and, well, I still don’t have one. But I do feel like I have a satisfactory alternative.
My script, which I call Pseudocron, has three components. (1) An administrator interface that includes text inputs for (a) the script to be executed periodically, and (b) the time delay (in seconds) between executions. This data is submitted to a MySQL table. (2) The actual pseudocron.php file, which checks to see if the time interval has been exceeded. If so, it runs the script and updates the time interval (now + interval) to prepare for the next execution of the script. (3) The script that is to be executed periodically. All three files are displayed below with thorough comments.
Yes – the nature of this script means that your web site will need visitors for it to run efficiently. If you want a script to execute every 5 minutes but you only get 1 hit per day, well, you’re out of luck.
Download (2kb)
1. create-pseudocron.php
/*
CREATE-PSEUDOCRON.PHP
v. 1.0
April 29 2010
By Benjamin Yobp [http://www.benjaminyobp.com/]
– Creates a pseudocron job
*/
include “pseudocron.php”;
?>
<html>
<head>
<title>Create a PseudoCron Job</title>
</head>
<body>
<form action=”create-pseudocron.php” method=”post” name=”add”>
<input type=”text” value=”.php file to execute” name=”file”>
<input type=”text” value=”Time in seconds between executions” name=”delay”>
<input type=”submit” value=”Submit”>
</form>
<?php
// Only run this if the form has been submitted
if($_SERVER['REQUEST_METHOD'] == “POST”) {
$file = $_POST['file'];
$delay = $_POST['delay'];
addPseudoCron($file, $delay);
print “<br><strong>Success!</strong>”;
}
?>
</body>
</html>
2. pseudocron.php
/*
PSEUDOCRON.PHP
v. 1.0
April 29 2010
By Benjamin Yobp [http://www.benjaminyobp.com/]
– Schedules a .php file to be run regularly at a given time interval
– Every time pseudocron.php is loaded in the browser it will check
to see if the specified time interval has passed.
Case 0: pseudocron.php waits patiently…
Case 1: the .php file you specified will be executed
– IMPORTANT: Create this MySQL table:
CREATE TABLE `YOUR DATABASE NAME HERE`.`pseudocron` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`script` VARCHAR( 20 ) NOT NULL ,
`interval` INT( 15 ) NOT NULL ,
`schedule` INT( 15 ) NOT NULL
) ENGINE = MYISAM ;
*/
// Connect to the SQL database
$dbhost = ‘localhost’;
$dbname = ‘DATABASE NAME’;
$dbuser = ‘DATABASE USERNAME’;
$dbpass = ‘DATABASE PASSWORD’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(‘<font color=”#cd0000″><strong>Pseudocron error: could not connect to the database!</strong></font>’);
mysql_select_db($dbname);
// Call this function to create a pseudocron job
function addPseudoCron($script, $interval) {
$now = time();
$query = “INSERT INTO pseudocron VALUES (”,’$script’,'$interval’,'$now’)”;
mysql_query($query) or die(‘<font color=”#cd0000″><strong>Database error: could not create pseudocron job!</strong></font>’);
}
$query = “SELECT * FROM pseudocron”;
$result = mysql_query($query) or die(‘<font color=”#cd0000″><strong>Database error: could not select the pseudocron table!</strong></font>’);
while($row = mysql_fetch_array($result)) {
$now = time();
$thisRow = $row['id'];
$nextPseudoCron = $now + $row['interval']; // Sets the time for the next execution of the pseudocron job
$timeTillPseudoCron = $row['interval'] + $row['schedule']; // This variable is the time that pseudocron.php will check.
// It = the time interval + the time it was when the pseudocron job was last executed
if ($now >= $timeTillPseudoCron) { // “If the pseudocron job is due to be executed, then execute it!”
include $row['script']; // Run the desired .php script
$setSchedule = “UPDATE pseudocron SET schedule=$nextPseudoCron WHERE id=$thisRow “; // Update the schedule so that the pseudocron job can be executed next time!
mysql_query($setSchedule) or die(‘<font color=”#cd0000″><strong>Database error: could not update the pseudocron schedule!</strong></font>’);
}
else {
print “Sorry, not time yet!”;
}
}
?>
3. example.php
print “Hello world!”;
?>
There you go. I hope this was helpful! Sorry for the poor formatting in the above code boxes. If you download the .zip archive, the files will be tabbed and pretty looking.
Need a string quartet in Charlottesville? March 26, 2010 No Comments

Check out the Virginia Orpheus Musicians, a group of local performers affiliated with the University of Virginia. They’ve had years of experience playing for weddings and other events and they would certainly add that “something special” to your event.
I designed the web site, uploaded it a few days ago — it’s the second string quartet web site I’ve made in the past year and a half, the other one being for the Amadeus Musicians in New York. The Amadeus Musicians site was the first web site I’d designed in about 7 years, so it isn’t that great. When I coded it I was operating in a 2001 mindset (resuming where I’d left off), as you can tell by looking at the design! I plan to overhaul it this summer and make the site as professional-looking as it needs to be.
But anyways, the interesting new thing I did with the Virginia Orpheus Musicians’ web site was to integrate it with WordPress, a popular blogging platform. This way the owner can update the site as easily as one would update a blog, a Facebook status, or a YouTube account, and I don’t have to be summoned every three days to fix grammatical errors, change links, and add images, etc. Not only does this take a load of mundane work off of my shoulders, but it also empowers the owner of the site. They can get “behind the scenes” and understand how their web site works in a more intimate way. They have more control over the content — they can update it whenever they feel, without worrying about whether or not they’re bothering me. With this new system, I only have to be summoned when a major update is needed or something goes seriously wrong (which never happens). Another benefit is the plethora of plugins floating around the WordPress universe — easy systems for managing photo galleries, contact forms, traffic statistics, polls, you name it. It’s a win-win situation.
Needless to say, a traditional web site integrated with WordPress is only ten minutes of tweaking away from having a fully-functional blog attached to it.
Chopin’s Birthday: How Will Bayreuth Respond? March 2, 2010 No Comments

The bicentennial of Chopin’s birthday lasted from February 22nd until March 1st of this year. Over that span of time — the first date being the D.O.B. on Chopin’s baptism certificate and the second being the D.O.B. that he and his family celebrated — 171 hours of Chopin’s music was performed across Poland, his country of birth. You can read this article for additional information about that, because there is a more important matter at hand.
When my friend Ji Nin told me about Chopin’s big celebration, she said, “It’s even longer than Der Ring!” and that got me to thinking… When May 22nd of 2013 rolls around, it will be Wagner’s bicentennial, and there’s no way that Wagnerites are going to let that sissy boy Chopin outdo them. Wagner’s birthday will be celebrated with Wagnerian grandeur.
It is my estimation that come 2013, Wagner’s music will be performed for two hundred years straight, until his quadricentennial (which itself will have a celebration that outdoes his bicentennial). That’s 1,753,162.55 hours of constant music, which handily trumps Chopin’s mere 171.
This amounts to staging two of Wagner’s operas per year.
Wikipedia’s Incentive Structure March 1, 2010 2 Comments

Ahh, Wikipedia. The online encyclopedia, which according to United States Secretary of State Hillary Rodham Clinton, “everybody knows is never wrong,”[1] has become the number one source for most high school research papers, as one study shows.[2] Although other prominent figures, most notably the members of the Buena Vista Social Club[3], have disputed the accuracy of its claims and the veracity of its writers, the general feeling is that Wikipedia represents the collective intelligence of all of its users, and is thus infallible, much in the same way that George W. Bush is.[4]
But anyone who has tried to fix a Wikipedia article for minor (often careless) errors has without a doubt run into problems. Case in point: in 2007, Frank Huang attempted to fix the Wikipedia entry for “cheating” by appending “or what Marion Jones did” to the sentence, “Cheating is an act of lying, deception, fraud, trickery, imposture, or imposition.” Within an hour, some wily editor had found Frank’s upgrade and removed it.[5]
Here’s another story. When asked how he felt about Wikipedia, one of my professors recounted the story of how he was unable to successfully edit an article in his area of expertise. As soon as he corrected some information that was blatantly false, a swarm of editors deleted his additions and reverted the Wikipedia entry to its flawed state.[6]
Why is the response to alterations so fast and brutal? It’s the incentive structure. There are two types of editors on Wikipedia: “editors” and “administrators,” the latter being higher in rank — administrators supervise editors. And who do editors supervise? Us.
Okay, okay, that sounds fine. But how does one become an editor? You need a journalism degree before Wikipedia will allow you onto their payroll, right? Not really — you have the wrong idea. You see, editors are volunteers and there are no prerequisites to becoming one, aside from maybe an insatiable thirst for power and a few “your writing lacks intelligence” marks on your term papers.[7]
I mentioned before that administrators are one step above editors. To become an administrator, an editor must do a lot of work to improve Wikipedia, be it through composing new articles, making corrections, citing sources, etc. Obviously, it is easier to destroy than to create.[8] At this moment please take a break from my blog in order to read this other blog entry.
I especially like his “how to fix Wikipedia” section, which I will quote here for those who didn’t actually follow the link:
- Dump WP:N (notability). Worry about verifiability and accuracy, but forget notability. It is too subjective, and the result of it is a loss of interesting, valuable information.
- Make all adminships temporary. You get 1 year as an admin, and then you spend at least 1 year as a regular editor.
- Stop deleting obscure or niche topics.
- Hire a lot more paid staff to be your “real administrators.” These people need to be under constant review to prevent abuse, and their main job should be to patrol the volunteer administrators for inappropriate behavior. There should be a very low tolerance for suspicious behavior. Wikipedia has a huge pool of potential administrators. They can fire with impunity for questionable actions.
- Call editors “users.” Call administrators “editors.” For both groups, it will take their egos down a notch.
- Narrow it down to *1* way to report someone for bad behavior.
And I think I’ll leave it at that. So, what are your thoughts?
References
- ^ My memory. Accessed 1 March 2010.
- ^ Urban Dictionary. San Francisco, 1999-2010. Def.’n #2. Accessed 1 March 2010.
- ^ Wikipedia entry on the Buena Vista Social Club. Accessed 1 March 2010.
- ^ This blog post. Charlottesville, Virginia, 2010. Accessed 1 March 2010.
- ^ Edit History on Wikipedia’s Cheating entry. You find it.
- ^ My notebook from a class on Wagner’s Ring cycle. Accessed some time last semester.
- ^ Narcissistic Personality Disorder. Rochester, Minnesota, Mayo Clinic. Updated 23 June 2009. Accessed 1 March 2010.
- ^ Star Trek II: The Wrath of Khan. Nicholas Meyer. 1982.
Josie February 27, 2010 No Comments

Shortly after I woke up I got a phone call from my excited girlfriend, Jenna. She had seen online that her dream dog — a dog that was adopted by somebody else from the Charlottesville SPCA two days ago — was returned to the shelter. I got ready and we drove over, eager to play with Josie.
We walked it around for quite a bit, ran into Paul [my good friend/old roommate] and his girlfriend, and had a lot of fun. Josie is a great dog. She’s calm and dignified and peaceful and she’s on Prozac. No kidding.
Apparently everyone loves Josie. As Jenna was filling out her adoption paperwork, a couple came in with the intent of buying the dog. It’s a good thing we got there when we did.
I posted some pictures below. Sorry about the poor quality, I took these with my 10 kilopixel cell phone camera.
EDIT at 11:12 AM, 2/27: Since I’ve been itching to add a poll to an entry, here’s one:
Nokia Ringtone Waltz (Hamelin) February 26, 2010 2 Comments

A couple weeks ago I transcribed Marc-AndrĂ© Hamelin’s version of Nokia’s infamous ringtone (see the YouTube video below). Feel free to download it, print it, play it, share it, take credit for it, whatever. PDF format:
P.S. – the last 7 notes of the piece are meant to sound like dial tones.
Lottery Number Generator February 25, 2010 2 Comments

Link: Lottery Number Generator
A couple weeks ago I was asked to program a web application that picks numbers for the Mega Millions lottery. The commissioner, my girlfriend, asked me to write some algorithms that chose numbers at random with a slight weight towards numbers that have been drawn recently, since she believes that certain numbers pop up more frequently within X range of time than others, for whatever reason, be it that some balls weigh slightly more than others or that something funky might be going on with the machine.
Is that good math? No. But was it fun to program? Yes. One of the neatest things that I stumbled upon was this handy little idiom for generating random numbers within a certain range without repeats:
$numbers = range(1, 56);
shuffle ($numbers);
For the purposes of choosing 5 lottery numbers, I then made an array of the first five shuffled values from $numbers and then ordered them from lowest to highest:
for ($i=0; $i<=4; $i++) {
$random_nums[] = $numbers[i];
}
sort ($random_nums);
One problem that I came across later in the application was this: how to take care (i.e. eliminate) duplicate numbers in weighted algorithms, where the more important numbers appear in the master array more than once (for example, an array of two items, 1 and 2, with a 66% weight on 2 would be [1,2,2]). On a lottery ticket duplicate numbers are a no-no. I solved the problem with this iterative function, which I ran a few times in a row after coming up with 5 numbers to ensure (almost) that there are no repeats. It's not so elegant. Following is the function and then an instance where the function is called:
// Prevents duplicate numbers in weighted algorithms
function five_way_switch($i, $ii, $iii, $iv, $v, $x) {
switch ($i)
{
case $ii :
shuffle($x);
break;
case $iii :
shuffle($x);
break;
case $iv :
shuffle($x);
break;
case $v :
shuffle($x);
break;
}
switch ($ii)
{
case $i :
shuffle($x);
break;
case $iii :
shuffle($x);
break;
case $iv :
shuffle($x);
break;
case $v :
shuffle($x);
break;
}
switch ($iii)
{
case $ii :
shuffle($x);
break;
case $i :
shuffle($x);
break;
case $iv :
shuffle($x);
break;
case $v :
shuffle($x);
break;
}
switch ($iv)
{
case $ii :
shuffle($x);
break;
case $iii :
shuffle($x);
break;
case $i :
shuffle($x);
break;
case $v :
shuffle($x);
break;
}
switch ($v)
{
case $ii :
shuffle($x);
break;
case $iii :
shuffle($x);
break;
case $iv :
shuffle($x);
break;
case $i :
shuffle($x);
break;
}
}
$numset = array_merge($nums,$x);
shuffle ($numset);
five_way_switch($numset[0], $numset[1], $numset[2], $numset[3], $numset[4], $numset);
five_way_switch($numset[0], $numset[1], $numset[2], $numset[3], $numset[4], $numset);
five_way_switch($numset[0], $numset[1], $numset[2], $numset[3], $numset[4], $numset);
five_way_switch($numset[0], $numset[1], $numset[2], $numset[3], $numset[4], $numset);
five_way_switch($numset[0], $numset[1], $numset[2], $numset[3], $numset[4], $numset);
If you can think of a better way to do that, please let me know.
One last thing: While I won't guarantee that this number picker will give you that 100 million dollar ticket, I'd appreciate it if you donated a small portion of your winnings to the humble programmer who generated your numbers.