Using WYMEditor with Dojo (by including jQuery when needed)

I’ve decided to use Dojo for a project – to test the waters. However I’d like to still use WYMEditor. WYMEditor requires jQuery internally as well as for it’s handy jQuery plugin. Obviously I don’t want to always load jQuery in addition to Dojo for the few pages it’s required on, so here’s the solution I’ve come up with to dynamically load jQuery and any other required files using a DeferredList.

I have this as a function to which I pass a form name; in Dojo I then check whether there are any .richTextEditor elements and begin the initialisation if required.

I guess it would be good to wrap this into a dojo module of some sort.

Versions:

  • Dojo version: 1.7.2
  • jQuery: 1.7.1
  • WYMEditor: 1.0.0a5
require(['dojo/DeferredList', 'dojo/io/script'], function(DeferredList, script) {
	// We don't want to include things twice because it's bad and breaks WYMEditor.
	var requireds = [];
	if (typeof jQuery == "undefined") {
		requireds.push(script.get({ url: '/js/jquery/jquery-1.7.1.min.js', checkString: 'jQuery' }));
	}
	// If you wanted, it would not be a bad idea to check for each plugin individually.
	if (typeof WYMeditor == "undefined") {
		requireds.push(script.get({ url: '/js/jquery/wymeditor/jquery.wymeditor.js', checkString: 'WYMeditor' }));
		requireds.push(script.get({ url: '/js/jquery/wymeditor/plugins/hovertools/jquery.wymeditor.hovertools.js', checkString: 'WYMeditor.editor.prototype.hovertools' }));
	};

	var dl = new DeferredList(requireds);
	dl.then(function(res){
		jQuery(function(){
			// Fill in your options here
			var editorOptions = {};
			jQuery('.richTextEditor').wymeditor(editorOptions);
			// You might also want to add the wymupdate class to your submit button here
		});
	});
});
Tags:
Categories:

Scan Text for Postcodes and Plot Them on a Map

I’ve often been frustrated when sites list addresses (such as store locations) without providing a map to help you visually see the closest one to you, or the best one to stop by on your way somewhere.

So I dreamed up a tool to parse a web page for postcodes and plot them, this afternoon my brother asked me for one so I finally got around to making one.

It is here: http://www.pata.cat/maps/postcode-picker

Comments, ideas and feedback are welcome. The source is also yours on request – it’s a part of a bigger Zend Framework project and a little finickety to share easily.

Category:

Installing PEAR, PHPUnit and Selenium on Windows

I wrote this for use at work, hence some of the wording. I may re-edit it one day, but it should do the trick. Feel free to leave any comments or questions below.

Installing PHPUnit on Windows is done with PEAR.

Installing PEAR

  1. Create the folder c:\program files\PEAR (This is your PEAR path)
  2. Download go-pear.phar from here: http://pear.php.net/go-pear.phar (the one which comes with PHP is usually broken) and save it in your PEAR path.
  3. Open a command prompt and navigate to your new PEAR folder, type php go-pear.phar
  4. Hit Enter to agree to a System install then Enter again to confirm all the settings are good (after checking them, of course).
  5. PEAR is now installed. When we use PEAR to install things, it creates a .bat files in our PEAR directory which can is used to run them. For example by the end of this page PHPUnit.bat will be installed and we can call it from the command line as ‘phpunit’ since windows is clever like that.

To be able to run these commands from outside of the PEAR directory we must add the PEAR directory to our PATH Environment Variable.

  1. Press Windows Key and Pause/Break to load the System screen.
  2. On the left click on Advanced System Settings.
  3. Click on the Advanced tab then “Environment Variables..” button at the bottom.
  4. In the bottom list, “System Variables” find and select the PATH variable and click Edit.
  5. Add a semi colon to the end of the list, and enter the path to your PEAR directory.
  6. Click OK and then OK again.

You will need to open a new CMD window if you already have one open so that you get one with the new environment variables available.

  1. Run “pear upgrade” to test and get the latest version in one handy step.

Installing PHPUnit

Navigate to your PEAR folder and run the following commands

  1. pear config-set auto_discover 1
  2. pear install --alldeps pear.phpunit.de/PHPUnit

PEAR creates a file called PHPUnit.bat, which we can run from anywhere because we put our PEAR directory into our PATH variable in the first step. It’s also created a bunch of other files which PHPUnit.bat uses.

You may wish to add C:\Program Files\PEAR\pear\PHPUnit to your php.ini include_path.

Installing Selenium for Integration Testing

Our Integration Tests use Selenium and involve launching a browser and running through things, they take siginificantly longer to run than Unit Tests and you’ll probably not run them every day. They’re useful when you’re changing the back end but not the UI, and will  need updating if you’re making changes to the UI. They also pick up JavaScript errors.

Selenium is a server to which PHPUnit will connect and issue commands, the server then launches a browser and tells it what to do.

  1. You need Java installed, take the Offline version from here: http://java.com/en/download/manual.jsp
  2. Download Selenium Server here: http://seleniumhq.org/download/ Create a folder and save this in c:\program files\selenium\
  3. Right click on your desktop, go to New > Shortcut. For Location simply type “Java”, hit Next and type Selenium Server as the name.
  4. Right click your new shortcut and click Properties, at the end of the “Target” field add -jar “C:\Program Files (x86)\Selenium\selenium-server-standalone-2.23.1.jar”
  5. Running this shortcut should give you a console screen with happy output.
  6. To install the PHPUnit Selenium extensions (to be able to run the Integration Tests) download this file (or check for a later version of PHPUnit_Selenium from here) and merge the PHPUnit_Selenium-1.2.7\PHPUnit\Extentions folder with it’s sister in your PEAR Directory under pear\PHPUnit

Note that we are using Selenium 2, so you must use the Selenium2 classes.

Running the tests

Running the tests should take a matter of seconds and are run from the command line. From within the Squadify code base cd into the tests folder, type “phpunit” and hit enter, you should see something like:

PHPUnit 3.5.15 by Sebastian Bergmann.
.... Errors Come out here ...
Time: 0 seconds, Memory: 5.25Mb

PHPUnit looks for a file called phpunit.xml from which it learns how you with the tests to run. There are command line options for running only sub sets of the tests specified, controlling the output and other cool things.

Writing or Editing Tests

Tests are seperated into TestCases, each TestCase will test one unit. Examples of units are models, pages and forms. Refer to PHPUnit’s documentation for specific details on how to write tests.

It’s very easy to write useless tests, some pointers to avoid doing so:

  • Before writing tests, write a Doc Comment description before the Test Case explaining why the test exists.
  • Write descriptive names for tests, similar to a Doc Comment these force you to think about what and why you’re testing.
  • You’re supposed to write tests that fail, this means running it so you can see it fail, then fix the code to make it pass. It’s important to remember that you must change the code being tested, not the test itself, for this.

For the sake of maintainability put as much care into reusing your test cases code as any other code, without violating these:

  • TestCases should never be dependant on another Test Case, individual tests can be when it makes lots of sense but it should be avoided. The reason is so that (for speed) you run a subset of the tests (hence the name Unit Test).
  • Factory methods (such as getEmptyUser() or getYoungUser()) should be begin with “get” and placed at the bottom of the class. They’re used to make maintaining easier.

More Information

PHP Unit Docs: http://www.phpunit.de/manual/3.2/en/
Advice on writing tests: http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/

Tags:
Category:

Semuc Champey

Whowzers, what a magical place.

Dozens of diddie water falls falling a few feet down steps 50m wide, and just above? Another step separated by a tranquil pool of crystal clear calm water.

We dove right into the first pool, splashed about, hopped between underwater rocks and threw fruit at each other.

It was blissful, transported to another planet like refugees from stress. Not that Alex or I are much ones to stress, but Steph sure makes up for our lacking!

After a time we climbed up the slippery waterfalls of the first of 7 steps (the last some might say, since we were at the bottom) and dipped into the next pool.

Fish Food

The three of us lazily floated around being nibbled by fish feasting on the breakfast buffet of our dead skin, I wonder which they preferred ‘ the Guatemalan, the USAian or the Brit?

Turns out they probably liked me best, though only because while Alex fetched off for the camera and Steph explored the pool I sat still as a rock waiting for more fish, tempting the larger ones to come and nibble.

I loved it, dozens of them a few cm long swarmed over my legs and back while those a few inches long bided their time – no doubt a trait that helped them get so big.

For the most part it felt like being prodded with a pencil, though every now and then tehy either bit harder or hit a nerve and the pinprick like shock made me jump and the fish in turn all jumped back a foot too.

The best, though, were those feasting on my feet. Tops and toes no worries, but soles had me giggling like a gaggle of girls in jumpsuits.

After, we walked a little.

The Arrival

It was not always so tranquil, however. This brief spell in paradise took an alarming amount of effort, 2 days is not enough to see Semuc from Guatemala City.

Alex is here volunteering in a hostel called El Retiro. Steph and I caught the 7am bus from Guate city to Coban (5.5 hours) then the skull rattling unbelievably slow paced mini bus (2.5 hours) to Lanquin, finally arriving around 3pm.

More Numbers

We now learned that the 11km to Semuc takes about an hour, we had to catch the 1730 bus from Coban the next afternoon, which meant leaving Lanquin at 1330 and so Semuc at 1230. The earliest shuttle from Lanquin to Semuc Champey arrives there at 1000 giving us a mere 2.5 hours!

We opted to stay in El Portal, a hostel right by the park entrance where the electricity stops at 10pm but the bar is well stocked and we can enter the park at 8am.

Home Time

In the end we left at 12:30, didn’t get the 2pm bus because it didn’t exist, got the 3pm one which left at 3:20 and missed the last bus from Coban to Guate.

Steph stressed out in her own delightful way, I did consider dragging out for for my personal enjoyment but instead raided a cash machine (for which my banked blocked my card as suspected fraud) and haggled with a taxi driver and got her back to Guate by midnight before either turned into a pumpkin and her mum went mad with crazy.

Good ‘n’ Proper Virus Removal

Last Updated: November 2020

People get viruses all the time, I’ve no idea how but they seem to manage it. I spent lots of my time cleaning people’s computers, if you don’t wish to pay someone else to do it you can usually do it yourself using these directions (or get in touch if you’d like me to do it for you). You may get some hard to clean viruses which need research and persistence to remove – in this blog post I can’t help you with those.

Some Tips:

  • You might need to do them one at a time if you find they’re going very slow.
  • Don’t forget to back up your files. Always: virus or no virus. Don’t forget to scan your backup for viruses too (or delete and rebuild it if it’s a read-only one).
  • Each scan here could take between 1 and 8 hours to finish, depending on how much stuff you have on your computer.
  • They are all free, don’t pay for anything! Look for the “Free Version” or “Free Edition”. If you find the programs useful, however, most of them have the option to buy or donate to support them.
  • Where you get the option, ask for a Full Scan. You may need to click an “Advanced” button first.
  • Some will not clean “low-threat” items such as Cookies. Don’t worry about them, but clean anything else they let you.
  • No Anti-Virus picks up everything, that’s why you need to run several to have a really good scrub.
  • If you have an anti virus installed, run a full scan with that first. Then disable it so it doesn’t scan files every time one of the other scans does.

Run these from your browser (or a download file which doesn’t install):

You need to download and install these ones. Remember to uninstall them after to free up your disk space:

Also make sure your current anti virus is up to date and not complaining about anything. If you don’t have one then install:

You may also want to:
  • Run CCleaner – to clean up your caches, registry, broken links and suchlike
  • Defrag with MyDefrag – to tidy up your files so they load faster. Skip this is you have a Solid State Drive (SSD)
  • Use GlaryUtilities to clean up and speed up

If you know any other free online anti viruses, which actually clean up for you at the end, post them in the comments!

Tags:
Categories:

Tikal

Sat here as Alex fertilised the forest gives me a short break from both our footsteps and our nattering.

I read my Lonely Planet a little before scolding at myself and just listening. Slowly at first, much like your eyes adjusting to the brilliance of the stars the volume slowly increases until the buzzing of bugs is only interrupted by birds chirping and trees rustling – and the odd fool with his MP3 player going, I politely reminded him I’d go to a disco if I wanted music. Turns out he works there, but what does that matter? That’s even more reason he should follow the “No Music” sign – which also forbids a small dictionary’s worth of other things.

Three weeks later, I finished writing this

Tikal is an awesome place, I’d love to have been the first person to write about it because it’s such a cliché. Walking down jungle paths between pyramids, climbing up them to peek at the tops of others poking out the trees.

Yada yada, I loved it but we had a different mission.

Yavin IV

Tikal, you see, was the set for the rebel base in Star Wars IV.  A fact pointed out by Steph (or Paola, or both perhaps) a few weeks earlier during our Star Wars Marathon.

So here we are on a mission to find X-Wings and support the rebel cause. hmm perhaps not sensible words to be using in these politically unstable countries!

Temple IV is the one used, though the noise of the X-Wings must have rustled the feathers of the much animal life (including Toucans!) we saw later that evening as we waited for the sun set.

Heading out as the light rapidly faded every leaf became a terrifying spider. We ducked into a bat cave (not knowing it was one until we reached the end) and finally got back to our hotel – El Jaguar- where we had rented a tent in their garden, and whiled the evening away drinking Micheladas and eating expensive pasta.

Flores

The next day we headed to Flores, I’d made a careful list of all the great sounding coffee shops, drinking establishments and food places I wanted to visit and Alex had agreed to a crawl of the lot of them. Unfortunately a truck ran into a power line and the whole of El Petén was out of power, so most places closed down. We whiled away the evening in our hostel, Hostel Las Amigos, and I had the chance to visit the well-worth-the-wait Cool Beans in the morning for breakfast. After breakfast I bought an excellent new book which kept me entertained during the 7 hour bus journey back home.

Todos Santos and Zaculeu

Relaxing on this cool concrete step at the side of Todos Santos’ square I overlook the village go by. Immediately to in front of me two Maya decedents discuss what appears to be an unhappy tale in Mam, their local language, as they chat the lady on the right tries to fix her bag handle. On the balcony to my left two menu dressed in traditional red and white trousers, large collared shirts and hats with a blue and white striped belt have been quietly discussing since before I got here.

The trouble I have here with approaching people is making the assumption they speak Spanish. Though it may be a fair assumption to make, it feels a little like rubbing salt into the wound of disparity between the Spanish descendants and the indigenous. In a similar way to visiting any other country and presuming someone speaks English – do you ask and risk patronising them or do you start out in English and hope it doesn’t make them feel bad for not understanding. Fact is, most of the indigenous do speak Spanish and are far too friendly to actually get offended by a tourist who wants to chat.

None the less, we had a brief chat, they had a jolly laugh at my Mam pronunciation and I never managed to understand her answer to my request for a photo. Some of those attached here, are from Claire.

Mam 101

Mam is one of the many languages of the Maya, it’s spoken by a little under half a million people – more than the population of The Borough of Barnet. There are three main dialects, however due to massive suppression by the Spanish of the written language huge differences evolved between neighbouring villages. It’s cool stuff, here’s a couple of words I learned from the lady with the broken bag and her friend:

  • Hiete – Hello
  • Cochonte – Thank you
  • Ba’am Peh – How are you?
  • Cuch-nah –  Bye!

I’ve not made many doors this week

I’ve only been here for a few hours, it’s nothing like the Lonely Planet’s description of “Mud streets and tortillas everywhere” but it’s wonderfully tranquil, the air is fresh and the scenery stunning. As if that wasn’t enough, the people are friendly, I’m greeted by smiles and waves and just spent 20 minutes in the carpentery workshop of Juan Carlos and Jovani talking about how business is slow and the state of English Football!

I had planned to enquire in HispanoMaya about their weaving class and film on local culture, but they don’t seem to be opening today. I shall try them again and, failing that, head to the ruins of Zaculeu.

Maya Fashion

Now it would appear at first, that here everyone wears the same thing, and I can almost hear mum saying “But where’s their sense of self expressive fashion?!”. But fear not, with a little eyeballing you soon notice that while all the guys have the same hat, the belt on it has different sequins or colours between the blue stripes. Many, too, have ditched their traditional shirt (which varies in the pattern, especially on the colour) or our European [[T-Shirts]].

The female difference is more subtle, in the patterns of their tops (all wear dark blue skirts and the way they tie their hair – often long black plats with coloured ribbon running down and tied at the bottom creating a big loop of hair.

All carry shoulder bags of equally intricate designs.

Ruinas de Zaculeu

HispanoMaya didn’t open but I also had to wait until 2pm hours for the bus which meant it would be too late to go to Zaculeu the same day. Instead, I hung out in a nice cafe with Internet and excellent fried plantains for a bunch of hours, until it got dark and began being dangerous to walk home. What’s the opposite expression of “Every cloud has a silver lining?”.

The next day, I hopped on a bus to Zaculeu. Zaculeu is a really cool place, sieged by the Spanish for several months before the inhabitants died of starvation, the town itself is surrounded on three sides by ravines, making defence easy. Today it’s a very nice sized ruins with reasonably sized pyramids, you can easily see the museum and walk the structures in an hour. Which was very convenient, since I only had an hour until I had to return to catch my bus back to [[Guatemala City]].

Huehuetenango and my Guatemalan Family

For a city with such a cool name (Pronounced way-way-te-nango, or just way-way for short) the Lonely Planet doesn’t have much to say about this place. I’ve come to meet my Guatemalan Family. My mum’s brother’s wife is from here so I have a small collection of aunts and uncles.

My 3 hour chicken bus from Xela to here involved boxed birds, an emergency stop to pickup passengers and a good long chat with the fourth Carlos I’ve met this week. He was interested in life in London, specifically whether it’s easy to get a working visa and whether his English would be beneficial. I spoke in Spanish, I’d like to add Smile

As usual I had few expectations, all I knew is that the first taxi I got will be over priced. 40Qs (£3.30) and 8 minutes later I was meeting Great Aunt and Uncle Marina and Tono for the first time.

Thankfully, my Spanish was more comprehendible face to face than during our previous phone chats (thanks to Paula for all her Spanish during those!) and introductions, welcomes and a glass of water flowed smoothly, I presented my gift of sour dough olive bread from the excellent bakery-café, Artesano, in Xela as Marina called my aunt Brenda and arranged for us to meet in the Central Park shortly.

As I wandered around the Central Park I was met by smiles and greetings. I had a nice chat with Carlos #5, who I unfortunately lost when Brenda arrived with her husband.

Brenda and I posed for some celebratory photos which were quickly sent to Aunt Carolina in the states via WhatsApp. Carolina and I had coordinated several times in the past couple of months, often her confirming details of my broken-Spanish phone conversations with Marina. I also posed by a cool tree with one of the dozen shoe shiners who hang out in the park.

Within moments Brenda had sorted out the plan for my stay. We arranged to meet at her parents for dinner in 2 hours time, at 6pm.

I failed to find Carlos #5 again, so headed towards the most interesting of a fairly dull dull bunch of drinking establishments listed in the Lonely Planet – though perhaps it was just the memory of the places listed for Antigua and those I’d discovered in Xela that made these sound unexciting. That said, not even two blocks later I saw “Musica en Vido” (Live Music) painted next to a door and stumbled into a fantastic little café. Benches, armchairs, books, a little gift store, a motor bike filled patio and really good coffee!

It became a shame that I only have an hour and a half here in Revolution.

I sit here now, sipping my toffee flavoured coffee thinking of all you back in England. In a mere 6 weeks we’ll be sharing Proper Pints ain Proper Pubs. But I’m pushing that to the back of my mind, I’m afraid, because this is the time to be living in there here and now (and next week at a stretch).

Tomorrow is Thursday, I’ll visit Todos Santos – a step even closer to the indigenous roots of Guatemala – and Friday morning to the ruins to the East. Friday afternoon I’ll head for Panajachel for the last night with The Triumvirate.

Categories:

Xela (Quetzaltenango) and the Re-Inspiration of Awe

These last few months I’ve been to many different places and, lets be honest, most places are pretty dull.

That’s not to say they cannot be enjoyed, especially in the right company, but dusty standard issue roads lined with concrete block houses aren’t the most inspiring places to visit.

Before I had quite identified this trend I was becoming a tad concerned that I may have been growing tired of traveling. Perhaps there’s only so many times it’s fun to explore the layout of the market, drink 12 coffees in a day to find the best coffee shop and after a time you wonder if you’re taking a photo because of the admiration for the scene in front of you or just out of habit.

My puzzlement was dispelled yesterday morning, however, as I walked down Xela’s 12th Avenue and felt familiar waves of being the first tourist ever to visit this town.

The walk from the bus stop took around half an hour, I’d picked a first class bus over taking chicken busses because it was only a couple of dozen Q’s more (~£2) but meant I could spend the 4 hour trip working on the laptop kindly let to me by Alejandro after I broke mine for the third and final time.

The feeling climaxed, as it should, as I entered the “Parque Central” – the Town Square – big impressive buildings surround the really nicely designed park/square with not only trees and patches of grass but rows of columns, monuments and steps up and down to things. Watching down over this, and all of Xela are cloud covered mountains reaching into the heavens above even the 220m of altitude we already have.

I spent one wonderful day and two half days reunited with my triumvirate, Claire and I explored the market and failed to find the Soy Milk Lady; Alex and I had a heart to heart in the park as we finished our beers and watched jolly gringos stumble home. I also spent a great amount of time in Artisano, an incredibly Vegan friendly restaurant-café and slept in the very cosy Don Diego Hostel. The next day, I headed to Huehuetenango.

The Best Bridge in the World

I cant tell you why I like this bridge so much. There’s something about the concrete arm reaching across the [[Rio Dulce]] in its plain, unsupported and surprisingly inconspicuous manner.

Perhaps its a product of my upbringing, where bridges are oh so normal and rivers aren’t complete without one poking out of  the bankside trees. Wouldn’t it be awesome to see this nothing too special bridge through the eyes of a peasant three hundred years ago!

Maybe that’s the magic, its my inner peasant overriding the part of me who has had the pleasure of seeing so much cool stuff, and the feeling bubbles up through the sensible layers that say “It’s just a bridge” leaving me with just the pure sense of wonder without the reason.

It would seem, to me at least, that the more you see the less it takes to awe you.

Tags: