Category: Technology

Cartoon: The Cloud has a silver lining


Noise to Signal Cartoon

{lang: 'en-GB'}

Freecell version 2.2

Anyone who tried out my version of Freecell for the Blackberry Playbook will have realised that it was very basic. In order to get it submitted in time for the promotion I had to leave it at the bare minimum. During a few hardware upgrades I managed to delete the source code, so I decided to completely re-write it for a version 2.0 release. Over the past two weeks I have released another 2 updates, bringing the version count to 2.2. Hopefully this version addresses many of the deficiencies in the original release.

Version 2.0:

  • Complete re-write.
  • Added ability to move groups of cards.
  • Added kingOnly option.
  • Added card remaining count and game timer.
  • Added sound effects for card move and game completion.

Version 2.1:

  • Minor bug fixes.
  • Added double-click logic to send card to home cells or free cells.

Version 2.2:

  • Added safe and aggressive auto play logic. Safe auto play mirrors the moves made by Microsoft Freecell and Freecell Pro. Aggressive auto play mirrors the moves made by NetCell.

You can find the app in Blackberry AppWorld here:

http://appworld.blackberry.com/webstore/content/35083?lang=en

Or by scanning the QR code below:

 

{lang: 'en-GB'}

Freecell for Blackberry Playbook

As part of RIM’s recent Playbook promotion, I wrote and submitted a free Freecell app for the tablet. If you’re lucky enough to already have a Playbook (mainly the USA at the moment) please feel free to download the app and leave me feedback.

You can find the app in Blackberry AppWorld here:

http://appworld.blackberry.com/webstore/content/35083?lang=en

Or by scanning the QR code below:

 

{lang: 'en-GB'}

Onswipe

Kudos to Mashable for alerting me to Onswipe:

http://mashable.com/2011/03/23/18-million-wordpress-websites-now-available-in-ipad-format/

If you’re lucky enough to have an iPad (or iPad 2), you can now view WordPress blogs in a true iPad app style interface. Even self-hosted blogs (like this one) can join in by installing the Onswipe plugin.

Now all I need is an iPad 2 to try it out. :)

{lang: 'en-GB'}

Clickable, Transparent Sprite in AS 3

For the past few days I have had a problem. In ActionScript I wanted to do the following:

	public class TableauPile extends Sprite
	{
		public function TableauPile()
		{
			setImage();
		}
		private function setImage():void
		{
			width = 74;
			height = 98;
			graphics.clear();
			graphics.lineStyle(2,0xC0C0C0);
			graphics.drawRect(0,0,74,98);
			graphics.endFill();
		}
	}

This draws a nice “empty” box, allowing you to see the background beneath it. Oddly though, it doesn’t respond to mouse down events. Not unless you are lucky enough to accidentally click on the thin border. Attempting to write a FreeCell clone in Actionscript, as I am, it would be useful to receive mouse down events for empty boxes.

After much head scratching, Googling, and experimentation I have discovered that the only way to get the sprite to respond to mouse down events, is to fill it with a solid colour and set the alpha to 0. This can be accomplished by adding the following line before the endFill statement:

	graphics.beginFill(0xFFFFFF,0.0);
{lang: 'en-GB'}

Thinkup on Amazon EC2

For the last couple of days I’ve been playing with Thinkup on Amazon EC2. I already have a Thinkup install at www.roaringmoon.com/thinkup, so I thought I’d try it on EC2 just out of curosity. There is an excellent guide to the process of setting it up here: https://github.com/ginatrapani/ThinkUp/wiki/Installing-ThinkUp-on-Amazon-EC2

Sadly my email host doesn’t seem to like emails originating from EC2, so I had to manually activate Thinkup by editing the tu_owners table.

There seem to be workarounds that can be used to enable EC2 originated emails to be received, but it’s not really worth it if you’re just experimenting. Details can be found here: http://shlomoswidler.com/2009/07/sending-email-from-ec2.html

The original Tweet from Gina that brought the tutorial to my attention is here: http://twitter.com/thinkupapp/status/22795648973676545

{lang: 'en-GB'}

Required Fields on Symfony Forms

For the past three days I have been tearing my hair out. The problem was trying to show the required fields on a Symfony form. Kris Wallsmith has a nice method for achieving this here: http://kriswallsmith.net/post/144021872/symfony-denote-required-form-fields

Unfortunately every single field in the form was showing as required. Having created the database schema, and set the validators, I knew for certain that every field on the form was not “required” and should not show as such. Ah, but how to fix it?

After much head scratching and pulling out of hair, the answer finally struck me. Here it is in case you stumble upon the same problem.

If you’ve read the Practical Symfony book, or worked your way through the Jobeet tutorial, you will have read the phrase “It is almost always better to add the new validator to the existing ones by using the special sfValidatorAnd validator”. This is true, unless the existing validator is setting the field as required and the new validator is not. This is what was happening in my case. I was using:

  $this->validatorSchema['email'] = new sfValidatorAnd(array(
    $this->validatorSchema['email'],
    new sfValidatorEmail(),
  ));

when, to get the desired effect I needed:

  $this->validatorSchema['email'] =
    new sfValidatorEmail();

Replacing the validators insteading of adding new ones to the old ones solved the problem.

{lang: 'en-GB'}

Astro Soichi

Astro Soichi, or Soichi Noguchi 野口 聡一, took part in a long duration space flight from Dec/2009 to Jun/2010 on the International Space Station. During his stay aboard the ISS, he tweeted and twitpiced images of the earth. His twitter address is @astro_soichi, and his photos can still be seen on Twitpic here: http://twitpic.com/photos/Astro_Soichi.

I wanted to store a local copy of his images to look at later, so I wrote a simple python script to download them from twitpic. To use the script, you also need to install BeautifulSoup and workerpool.

Note that this script is provided “as is” and without warranty. If running it turns your PC into a cardboard box, that is entirely your own fault. :)

#!/usr/bin/env python
"""
   Copyright 2010 RoaringMoon.com
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from BeautifulSoup import BeautifulSoup
import re
import urllib
import os
import sys
import time
import string
import workerpool
valid_chars = "-_.,() %s%s" % (string.ascii_letters, string.digits)
url_pattern = re.compile("(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\.(?:jpg))(?:\?([^#]*))?(?:#(.*))?")
working_dir = os.getcwd()
username = "Astro_Soichi"
class DownloadJob(workerpool.Job):
    "Job for downloading a given URL."
    def __init__(self, url, save_to):
        self.url = url # The url we'll need to download when the job runs
	self.save_to = save_to
    def run(self):
        urllib.urlretrieve(self.url, self.save_to)
def get_next_page(div_soup = BeautifulSoup('')):
    nav_links = div_soup.findAll('a',attrs={'class':"nav-link"})
    for nlink in nav_links:
        if nlink.text == u'More photos >':
            return nlink.get('href')
    return False
def main():
    # Initialize a pool, 5 threads in this case
    pool = workerpool.WorkerPool(size=5)
    opener = urllib.FancyURLopener({})
    f = opener.open("http://twitpic.com/photos/%s" % username)
    s = f.read()
    f.close()
    div_soup = BeautifulSoup(''.join(s))
    next_page = True
    div_collection = div_soup.findAll('div',attrs={'class':"profile-photo-img"})
    while next_page:
	for item in div_collection:
	    f = opener.open("http://twitpic.com%s" % item.a.get('href'))
	    s = f.read()
	    f.close()
	    soup = BeautifulSoup(''.join(s))
	    img_name = soup.html.head.title.text
	    img_name = img_name[:len(img_name) - 10]
	    photo_info = soup.findAll('div',attrs={'id':"photo-info"})
	    try:
		photo_date = photo_info[0].find('div')
	    except IndexError:
		soup.decompose()
		continue
	    img_name = "%s %s" % (img_name, photo_date.text)
	    soup.decompose()
	    f = opener.open("http://twitpic.com%s/full" % item.a.get('href'))
	    s = f.read()
	    f.close()
	    soup = BeautifulSoup(''.join(s))
	    s = soup.findAll('img')
	    for val in s:
		m = url_pattern.match(val.get('src'))
		if m:
		    full_image = m.group(0)
	    if full_image:
		local_filename = "%s\\%s - %s.jpg" % (working_dir, username, ''.join(c for c in img_name if c in valid_chars))
		job = DownloadJob(full_image, local_filename)
		pool.put(job)
	    soup.decompose()
	next_page = get_next_page(div_soup)
	if next_page:
	    f = opener.open("http://twitpic.com%s" % next_page)
	    s = f.read()
	    f.close()
	    div_soup.decompose()
	    div_soup = BeautifulSoup(''.join(s))
	    div_collection = div_soup.findAll('div',attrs={'class':"profile-photo-img"})
	else:
	    div_soup.decompose()
    pool.shutdown()
    pool.wait()
if __name__ == '__main__':
      main()

By changing the username, the script can be used to create a local backup of your own twitpic collection. Be aware that the method for ensuring that the filename can be handled by NTFS is very crude. The full script can be downloaded here.

{lang: 'en-GB'}

Windows 7 God Mode

Windows 7 includes a neat feature called God Mode. Although the name is a bit of overkill, the feature is handy because it offers an easy way to access all Windows settings from a single folder.

To use God Mode:

  1. Create a new folder with the following name: GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}. You can change the name “God Mode.” However, the period and numbers must remain as is.
  2. Once you rename the folder, the folder icon will change to resemble a Control Panel.
  3. Double click the folder. A window will appear, which looks similar to the Control Panel, with dozens of options.

From: http://www.lockergnome.com/windows/2010/06/02/windows-7s-god-mode/

{lang: 'en-GB'}

Microsoft Money with the Nationwide Bulding Society

As a Microsoft Money user, I’ve recently discovered the need to convert CSV files into OFX files. My bank, the Nationwide Building Society, ended support for Microsoft Money online services in October 2009. You can still download your statements as CSV files, but Microsoft Money is not able to import them. After a spot of Googling, I stumbled across MT2OFX. So far, it seems to have been able to convert my statements without any trouble, although I have only been using it for a short time.

You can find it at the following website:

http://www.xs4all.nl/~csmale/mt2ofx/en/

{lang: 'en-GB'}

WordPress Themes