First Against the Wall
(Because we’ll be the first against the wall when the revolution comes)

Regular Expressions in Common Scripting Languages

September 5th, 2007 by dare

I felt the need to write this post since I’m forever wishing I had this info to hand. A self-confessed scripting language whore, I’ve lost count of the times I’ve been hacking away in, say, PHP, and suddenly thought, “What’s the preg_replace() syntax in PHP?”, or “What is the best way to do a global regex match in Ruby?”

So I’ve decided to create a repsoitory for all those miscellaneous bits ‘n’ pieces, and here it is.

For now I’ll concentrate on the infrastructure issues, such as syntax, supported functions, etc. Maybe another day I’ll examine the language differences in the regex notation itself.

1. Perl

Perl is the one I never forget, since it’s where I cut my regex teeth. So I’ll recount the basics here.

Basic Match


/pattern/gcimosx
m/pattern/gcimosx
m|pattern|gcimosx
m{pattern}gcimosx

The modifiers are:-

  • g  global match
  • c  continuation on global match 
  • i  ignore case
  • m  allow ^ and $ match adjacent to embedded newline
  • o  compile regex once only - in practice this is not generally necessary since the compiler is smart enough to do this when it knows it’s safe.
  • s  ‘.’ matches newline
  • x  ignore whitespace and allow comment

Note the delimiters can be replaced with any character you like (or pair of characters in the case of brackets). Use this sparingly because it can get hard to read, but it is particularly useful when parsing e.g. pathnames, because otherwise you’ll have to explicitly escape all the slashes.

Replace
s/regex/replacement/[modifier]
s|regex|replacement|[modifier]
s{regex}{replacement}[modifier]

Posted in Uncategorized | No Comments »

RetroNix - the Coolest Clock on the Web?

September 5th, 2007 by dare

Dare Widgets are pleased to announce the the release of RetroNix, a stylish new retro-digital clock.

The clock is based on Nixie tubes - the earliest form of digitial display, used heavily during the Space Race and Cold War eras, and occasionally cropping up in Bond movies and the like. They look superb, glowing amber with  a hint of violet. Dare Widgets have gone out of their way to animate real Nixie tubes to create a realistic, high-quality widget.

RetroNix is Flash-based, and installs on any web page, blog, and many social networking sites, including Piczo. MySpace and facebook support are begin implemented right now.

You can grab it direct from Widgetbox.

Posted in programming, widgets | No Comments »

Dumped: the Story of a Builder’s Underpants

September 3rd, 2007 by dare

Last night I watched a new reality TV programme called Dumped. The scenario: a bunch of unsuspecting fools are taken to a sanitized landfill site and told to live there for three weeks, using only what other people have thrown away. Sadly, fresh food is provided: far better if they’d done a “dump tucker” feature (á la I’m a Celebrity) - that could have proved interesting, if not fatal.

The shelter they built from discarded packing crates, tarpaulins and scaffold tubes - and it was up in no time thanks to one of the contestants being a builder. Said contestant was promising, since he appeared to be tattooed on every part of his body except his face, and from the outset displayed almost fanatical anti-environmental credentials: notably, he claimed to wear his underpants only once before binning them (”I spend maybe £40-£50 a week on underwear”). And being a builder, of course, that would pale when compared to all the unused cement, timber, paints, solvents, plastics, roofing materials and no doubt scaffold tubes that he is likely to skip on a daily basis.

Sadly, once the shelter was up he decided to leave the programme. He said he was unshocked by anything he’d seen on the landfill. I think he was lying. I suspect, if you really put him on the spot, if you pinned him down and asked him, he would admit he was actually shocked at the sheer lack of underwear on the dump: if everyone in Britain was like him, there would be 60 million pairs of Calvin Kleins (and their accompanying heavy plastic packaging) piling up on the nation’s landfills every day: that’s 21.9 billion pairs of kecks a year.

The underwear thing did bother me on another level though. Perhaps I’m misunderstanding the chap. I mean, what does it say about his arse? Quite a lot, I should think, bearing in mind that, unlike us office layabouts, builder’s bums spend large portions of each day being famously ventilated whilst on display to passing pedestrians. Is this ventilation not enough? Perhaps his backside is so rancid that he can’t bear to pollute his washing machine with his own soiled kecks? I think rather than a reality TV show, this poor guy needs an endoscopy.

In his defence, however, he did say he might think about donating his slightly-soiled pants to charity. Hmmm, not sure what I think about that. Surely rather than the undergarments leaving a sweatshop in Vietnam, taking a round trip of 12,000 miles (via a heavily-tattooed builder’s backside) and being repatriated back into Southeast Asia some months later via Clothes Aid, they should have just stayed there in the first place?

Oh well. He doesn’t care: he said he was going to leave the dump, pick up a suitcase full of underpants, head for the airport, and catch a flight to Las Vegas. Presumably he’ll be heading straight for the craps table.

Posted in rants | No Comments »

Welcome to Dare’s Widget Blog

August 21st, 2007 by dare

Welcome to Dare’s Widget Blog. The purpose of this blog is to communicate my experiences developing widgets for the web, the desktop and - hopefully - mobile. I’ve started this fairly early in the day - I have a couple of widgets out in the wild already (notably ScrollFx), but this is still a new venture for me.

Also this Wordpress installation is new territory - never hosted my own blog before this evening - so if I find anything particularly good/bad I’ll make note of it.

Until the next post…

Posted in Uncategorized | No Comments »