Jane's Technical Stuff

Friday, July 04, 2008

Monty Hall problem - PHP


This evening, after returning from an excellent VBUG: Brighton (of which more in a later post), Richard was talking about the Monty Hall problem after listening to a discussion about it on the BBC podcast In Our Time.

For those who don't know the Monty Hall problem it is this:
  • A gameshow set has 3 doors.
  • Behind one of the doors is a prize.
  • Behind the other 2 doors is nothing.
  • The contestant choses a door.
  • The gameshow hosts, knowing where the prize is, and which door the contestant has chosen, opens a door which he knows hasn't got the prize behind it and the contestant hasn't chosen.
  • The contestant is then offered the opportunity to trade their door for the one remaining door.
Should the contestant switch? The answer is yes 2/3rds of the time. See here for the reasons.

Richard and I both set about proving it in the tools we had available, I chose PHP, Richard chose Scala. And we both can successfully demonstrate that by always switching doors the contestant is more likely to win.

My PHP version is available for demo here and downloadable via a zip file (right click, save as) here.

Labels: ,

// posted by Jane @ 12:25 AM   save to del.icio.us

Comments:

Saturday, March 29, 2008

A yahoo pipe, some php and a flickr feed


Over on the JaneandRichard home page, we used to show a random image from our image archive. However, to add an image to the archive we needed to register it, and this we failed to do very often. As time went on I was putting photos less often on the JaneandRichard images page, and more often on flickr. So, I updated the front page to use a flickr badge based on my flickr feed. This wasn't ideal, as it didn't combine our output.

Previous home page

This morning I decided to do a bit of playing, and so produced a yahoo pipe which takes Richard's flickr RSS feed, and my one as an input and returns the most recent image. I then wrote some PHP (well took the Brighton Bloggers aggregated feed PHP actually which in turn was based on the RSS reader produced by Richard Kendall) and wrote out the RSS description within some javascript. This allows me to replace the flickr badge on the home page with an image based on the combined feed.

New home page

In order to make this more useful, I used a parameter feed to allow other images to be produced by the script. So, the code
<script type="text/javascript" src="http://jane.dallaway.com/services/getImageFromFlickrRss.php?feed=http://api.flickr.com/services/feeds/photos_friends.gne%3fuser_id=11369209@N00%26friends=0%26display_all=1%26lang=en-us%26format=rss_200"></script>
returns the most recent image added by any of my contacts. The feed parameter needs to have the flickr RSS URL encoded otherwise the script will truncate the output and nothing will be produced.

So here is the output from that script - the latest photo from my contacts:


Update:
There is some cacheing going on at the yahoo pipes end, and so the RSS feed from the pipe doesn't reflect the changes in real time, or as quickly as if you run the pipe manually.

Labels: , ,

// posted by Jane @ 11:52 AM   save to del.icio.us

Comments:

Thursday, May 31, 2007

Brighton Bloggers aggregated RSS


I've just added a new section to Brighton Bloggers to take the last 30 or so blogs from the aggregated RSS feed and display them on the site. Hopefully, for those who don't want to read all the posts via RSS they can still get a flavour of what is on offer from participants.

It is written in PHP and is a customised version of the PHP RSS Reader originally written by Richard James Kendall. The script was really easy to customise and I'm really pleased with how it looks. I could do with a better word than Aggregated though, so if anyone has any suggestions, please let me know.

Labels: , , , ,

// posted by Jane @ 8:17 PM   save to del.icio.us

Comments:

Tuesday, July 29, 2003

Skill Swap PHP


Last night I attended my first Skillswap event. These are free events where the emphasis is on learning a new skill, and presented by a local expert. It was presented by Matt Zandstra (author of Sams Teach Yourself PHP in 24 Hours) and was all about PHP, Objects and Patterns. Matt also delved into some of the new features that PHP5 will provide when it's released towards the end of this year.


I must admit that Design Patterns are something that have been on the fringe of my knowledge for a long time, but that I've just never got around to learning more about, so it is good to now have a bit more of an idea. There were a couple of book recommendations mentioned during the night - Design patterns : elements of reusable object-oriented software and A Little Java, a Few Patterns which I may have to take a closer look at.

Labels: , , ,

// posted by Jane @ 10:22 PM   save to del.icio.us

Comments:

Brighton Bloggers   This page is powered by Blogger. Isn't yours?   rss Sussex Digital - focusing on the Sussex digital community