Green

About This

You've arrived at the homepage of Stephen Stewart. The archive is available here for those who want it. This site is happily hosted by Dreamhost. Click for more?

More!? OK then, but I can't help feeling that this will be a disappointment to you.
I work as a web designer in Belfast, and I live by the sea in a shoe. You can see me here, doing my livejournal pose as idoru called it. If you need to you can email me at carisenda -at- gmail -dot- com.

My hCard

Stephen Stewart
Donaghadee , County Down Northern Ireland

Recent Comments


Recommended Viewing

  • 300rating
    Does exactly what it says on the (comic book) tin. Loved it.
  • Little Miss Sunshinerating
    Very funny, disturbing (the beauty pageant) and completely messed up -- but in a good way.
  • Laputa: Castle in the Skyrating
    Story great, characterization a little on the weak side -- though the big robots are cool.
  • Porco Rossorating
    Stylish, funny, exciting.
  • Grave of the Firefliesrating
    Very sad, which was a little unexpected since I didn't know much about it before watching it. Can be a little too slow in places though, otherwise it's very good.
  • Nausicaä of the Valley of the Windrating
    The story can get a little dense at times what with the various factions, but still really enjoyable, inventive and engaging.
  • X-Men: The Last Standrating
    Opportunity, talent, money - all blown. Over 3 films X-Men has hinted of something great that could have been, this last one says "No, sorry - not going to happen". Bah.

flickr.com

Replacing strings in files

There are many and varied ways of searching for and replacing strings in files, here are three.

find . -name *.html -type f -exec sed -i \
-e 's/string1/string2/' {} \;

This will use find to locate all files with the html extension in the directory it’s run in and any descendent directories, once it finds a file it runs sed to replace inline any occurrences of string1 with string2. Combining find and sed probably gives you the greatest flexibility and power in searching and replacing without having to know a great deal about programming.

perl -pi -e 's/string1\.$/string2\./' *.html

Perl inline search and replace, you’ll find a full explanation of this and more complex variations on this in the Debian Administration article Search and replace across many files with a perl one-liner, the above is the simple case from the article.
It’s good, but to get any real value from the knowledge you really need to learn perl.

If you want to do the same thing in Ruby you might try:

ruby -p -i.bak -e 'gsub("string1", "string2")' \
*.html

Again, that won’t help you do much else unless you learn at least a little Ruby.

rpl -R -xhtml string1 string2 *

RPL: the really easy way. It’s a package on Debian stable you may have to apt-get but from my point of view it’s perfect for people who aren’t that confident with things like find or perl, not everyone has the inclination to go learn such things and the whole team needs to be effective.
The RPL man page is pretty straight forward, the above line will search recursively for all files with an extension html (-x option) and replace string1 with string2.

0 CommentsApril 26, 2006

Rename lots of files in a directory

So, you get handed a CD full of files that need to be made available to the InterWeb, you look inside and they’re all called things like:

...2006-04-25 17:02 What I Did For Summer 2005.pdf

So you want to rename these fifteen thousand PDFs to something a_little_more_url_friendly. Why not try rename with a little regular expression?

rename 's/ /_/' *.pdf

Try man rename for a few more ideas, the version of gentoo I tried it on didn’t have a very nice example of rename but Debian Sarge’s version is shiny.

0 CommentsApril 25, 2006

SSH Keys, SSH-Agent and Keychain

This is just another version of a host of other HowTo’s on this subject. It’s just this one is specific to me, so I’m really posting it for me. I posted the original version of this on the work wiki, so that might explain why it reads like it does. A bit. Maybe.

First create a DSA key on your primary development machine, in this case mars, 5 or more random words strung together, alphanumeric, you know the drill, (just to emphasise, this is a passphrase, not a password, it’s meant to be longer) :

ssh-keygen -t dsa

Then copy the generated public key to the machine you’re logging onto, in this case earth:

scp .ssh/id_dsa.pub USERNAME@earth:

SSH to earth:

ssh stephen@earth

On earth, add the public key to the list of authorized keys:

cat id_dsa.pub >> .ssh/authorized_keys

Exit earth, return to mars.

In your home dir on /mars/ edit ~/.bash_profile


# on this next line, we start keychain and point
# it to the private keys that we'd like it to
# cache

/usr/bin/keychain --clear id_dsa
. ~/.keychain/$HOSTNAME-sh

Exit mars and log in again. Now Keychain should start an ssh-agent session which, once you’ve typed in the passphrase, will cache your DSA keys meaning for the duration of this session you don’t have to enter a password/passphrase when connecting to earth. You can do the same thing for all of the machines you connect to as well, which is groovy, as someone might say.

0 CommentsApril 25, 2006

SGML-Spell-Checker

SGML-spell-checker is a tool that you can use to automatically spell-check your SGML documents.

Running it on the index page of this site:

onsgmls index.html | sgml-spell-checker \ 
  > spelling_mistakes.txt

Produces:


0: onload
0: Dreamhost
0: livejournal
0: weblog
0: Weblog
0: StrayToaster
0: offsetHeight

...

Cool. But quite a lot of those words are spelt correctly, it’s just the default aspell dictionary doesn’t know about them. So:

onsgmls index.html | sgml-spell-checker \
  | awk '{ print $2 }' | sort | uniq \
  > mywordlist.txt

Then edit mywordlist.txt, weeding out all the actual spelling mistakes. Once you’re sure you have a list of correctly spelt but not in the default aspell dictionary words, create a custom aspell dictionary:

aspell --language-tag=en create master \
  ./my_custom_dictionary.aspell \
  < mywordlist.txt

Then run the spell checker again, this time with an additional dictionary including words like ‘Kottke’, ‘weblog’ and ‘StrayToaster’:

onsgmls index.html | sgml-spell-checker \
  --dictionary=carisenda-green.aspell \
  | awk '{ print $2 }' | sort | uniq \
  > spelling_mistakes.txt

Finally, run the above as a cron and check your results against some test cases:

  • charecter
  • tenderhooks

(If you’re wondering about onsgmls (or nsgmls) it’s an sgml validator, it help SGML-Spell-Check decide what’s English and what’s SGML (XHTML in this case). I’ll tell you more about it when I understand more about it myself.)

0 CommentsApril 22, 2006

the Police (Northern Ireland) Act 2000 (c. 32): section 46 (discrimination in appointments)

I wonder if you can guess who spoke these words:

Ulster stands at a crossroads. The time has come when the people of Ulster should have the opportunity to have full civil and religious liberty for all men—all men equal under the law, all men equally subject to the law. The sooner we achieve that, the better for us all. We surely should be able to unite on that subject.

They were spoken during a debate on ending the 50/50 recruitment ruling in Police recruitment in Northern Ireland. The Police Service of Northern Ireland must by law recruit an equal amount of Protestants as roman Catholics, a consequence of which is that otherwise perfectly qualified individuals are rejected purely on the basis of what religion they were born into.

It’s a pretty nasty piece of legislation. It has directly affected the lives of my friends, some of which are now applying for the 4th or 5th time, each time getting all the way to the end (a process which takes nearly a year), each time being rejected because they are Protestant. (That last line will make it nice and easy for the Trolls.)

It was Ian Paisley who said the above. I’ve never voted DUP before, in Northern Ireland terms I’m too liberal, but that one statement in and of itself is something I could sign up for.

3 CommentsApril 22, 2006


Main Atom Feed, Photoblog Atom Feed, Linkblog Atom Feed, Technorati Profile
Powered by Movable Type 3.34. Design © Stephen Stewart. Happily hosted by Dreamhost.