How to Make an HTML Element on Your Website Disappear after 10 Days

October 13th, 2007

After October 15th, 2007 this message will disappear forever.

The text above is an example of auto-expiring HTML. (Don’t see it? If it’s after October 15, 2007, then it’s working ;-) Perhaps try viewing the source of this page to see it.)

Do you have any of these problems? If so then auto-expiring HTML may help you:

  1. You put a “new” images around new content on your website, but then forget to ever remove them thus embarrassing yourself and your community.
  2. You put a deadline for your project on a website, but if you miss the deadline, wouldn’t it be nice if the deadline conveniently disapeared from the page automatically? ;-)
  3. Your brilliant blog post made it to the front page of Reddit. You want to put a message welcoming them, but since they’ll only be around for a day, you want the message to disappear automatically by the next day.

(All these examples assume you’re lazy, and care more about convenience than bandwidth.)

Can you think of more uses for auto-expiring HTML? Please leave a comment.

How to Make Auto-Expiring HTML

screenshot164.png

I’ve made this handy utility to automatically create auto-expiring HTML for you. You enter the content you want to expire, set the number of days to expiry, and paste the output into your webpage. Check it out.

How it Works

The utility wraps a div tag around whatever HTML you enter, and puts some javascript under it to hide that div if the current date is greater than your set expiration. There’s more information about its workings in the utility’s writeup.

del.icio.us |  Digg |  FURL |  Yahoo! My Web 2.0 |  Reddit

Machine Learning and Dragons - a Game

October 8th, 2007


Here is a fun little game I wrote using Python and pygame.

The Story:

knight_dragon.png

You’re a knight and your job is to kill as many dragons as you can. The twist is that the dragons use Genetic Programming to learn from every encounter. (You can optionally have them use Reinforcement learning instead too.)

Dragon Fighter Pygame - Machine Learning - Genetic Programming

You can download the source code and all files needed to run the game here (8.6 MB, GPL).

To run it, you just need Python and pygame installed.

Game Play:
Kill as many dragons as fast as you can.
The arrow keys move ye.
The space bar swings your sword.
ctrl+c to quit.

Discussion:

When using Genetic Programming, the dragons basically learn like this. Every dragon gets assigned a randomly created program tree. Here’s an example in LISP like syntax:

ikfm(ifle(20,knightdistance,attack(),mafk()),mtk())

Which means this:

if knight is facing me:
    if 20< =distance to knight:
        Breath Fire
    else:
        move away from knight
else:
   move towards knight

Dragons get points the longer they survive in a level, and they get a whole lot of points for killing the knight. After the end of a level, the dragons’ program trees are mixed up with each other to create new programs. program trees associated with the most points, get chosen more frequently to reproduce.

Sadly this scheme turned out not to work too well, though it does work once in a while. If you play say 20 games (not levels), you’ll probably see an instance of the dragons learning to chase you. But normally they don’t learn much of anything.

Here are some of the reasons I think the learning doesn’t go better:
1. The population is too small for the search space.
2. Even good dragons can get killed, just by standing too close to another dragon. They have no means to learn not to do this.
3. Fitness isn’t fair. If a dragon starts out far away from the knight (placement is random) he will probably live longer than a dragon closer to the knight.

If anyone wants to fix these things, please send me your patches.

I also tried Reinforcement learning for the dragons. This actually made them good at turning around when the knight comes near, and shooting fire at him. But they could never learn how to move.

Please try it out and let me know your feedback. Do you have any ideas on how to scale up this idea and make it into a fun game? Any ideas how to improve the AI?

del.icio.us |  Digg |  FURL |  Yahoo! My Web 2.0 |  Reddit

FedBayes - Models Updated with Latest FOMC Statements

September 23rd, 2007


I created a little Bayesian interest rate predictor in Python a while back.

Today I updated the models with the latest FOMC meeting statements. I also spruced up the code a bit.

Here are the latest code, models, and data:
FedBayes.zip (~140 KB)

Here are the latest predictions for what will happen at the next meeting:

Rate Change / Probability
0% = 0.403
0.25% = 0.330
-0.5% = 0.237
-0.25% = 0.005
0.5% = ~0

Do these predictions sound reasonable to you? I think it’s interesting how the model predicts that the second and third most likely scenarios are an increase in rate, or another drastic cut. It does mirror how I believe the Fed currently sees things i.e., inflation could get bad so we have to raise rates, or the economy could just get really bad (major slowdown).

del.icio.us |  Digg |  FURL |  Yahoo! My Web 2.0 |  Reddit

Tablegen Goes Open Source

September 5th, 2007

I figured I’d go ahead and post the code to one of my first Python web applications.

TableGenerator.png

It’s a web application that lets you generate HTML tables. You can see it in action here.

Anyway, here’s the code. Let me know if you need help figuring it out.

And don’t judge me too harshly, I was young then, I hadn’t heard of the Model-View-Controller pattern for web development, and I certainly had never heard of frameworks.

del.icio.us |  Digg |  FURL |  Yahoo! My Web 2.0 |  Reddit

Are You Spending Too Much Time Getting Images from the Web to Your Website?

August 16th, 2007

What if I told you, any image I come across on the vast internet, that I could get it onto my own server, and get the new URL into my clipboard in 3 clicks?

Well I can (gotcha, puppy!):


See there’s this PHP script I drop onto my server, which makes this bookmarklet. Which when I click the bookmarklet I can click on any image and it sends it over to my server and then loads a page presenting me with the image’s new URL and image tag I can post write in my blog.

Here’s the code.

Here’s what it looks like:
hoster1.png

hoster2.png

Where did it come from?

This bookmarklet/script is the first project I pledged on ($3.00) using a new startup called Micropledge. And it’s certainly a sucess story. PaulButler finished this in a matter of days. The website lets people pledge small amounts of money to get open source software built. It’s pretty neat. Here are all of the projects I’ve thought of so far.

del.icio.us |  Digg |  FURL |  Yahoo! My Web 2.0 |  Reddit