About

You’re visiting the personal website of Joost Schuttelaar.

Take a look

Contact

You can e-mail me at jelephants @ jstsch.com (anti-spam: please remove the mammal with the big snout).

Twitter feed @jstsch

Sorry, feed is gone. API has been killed by Twitter.

PHP: Highlighting words in a string

Monday March 7 2011

Seemingly simple things are often hard. How about a function which takes a text, an array of keywords and a max length, and outputs a highlighted string up to that max length? The highlighted string should be in the middle of the returned segment, of course.

In PHP, it becomes a bit of a mess because of its multibyte Unicode handling. I noticed that most frameworks don’t take care of our fâncy European characters correctly, so I had to roll my own.

The following set of functions handle it, although mb_ereg will probably be deprecated soon. Bonus points for who converts this to use preg (with the /u modifier). Back when I wrote this most PHP installs weren’t precompiled with the correct PCRE lib.

Hope it helps someone!

highlight.php

Simple Indian chickpea and spinach curry

Sunday March 6 2011

Made a very tasty curry last week. Healthy and veggie. Here is the recipe!

Chickpea

Ingredients (serves 2)

  • Whole spices: 1 tbsp. coriander seeds, 1 tbsp. cumin seeds, 1 tbsp. dried (birds-eye) chili peppers, 2 cloves, 6 cardemom seeds, touch of mace (optional), a few curry leaves (optional)
  • Butter (real)
  • Two onions, chopped
  • Tin of chopped tomatoes (400ml)
  • Half a garlic, chopped
  • Tin of chickpeas (400g)
  • 100 ml. of yoghurt
  • 200 grams of washed fresh spinach

Preperation

  1. Gently roast the coriander, cumin and chilies in a skillet on low fire. They are done when they become aromatic – but be sure to not overroast them, you’ll mostly get bitter tones out of them then. Cumin seeds tend to need a shorter time to toast so I add them a bit later. When done, grind them all up finely in a mortar and set aside. Put it through a sieve as needed to remove course bits.
  2. Chop the onions and sauté them gently in a generous amount of (real) butter for about 5-10 minutes. Low heat. I use a cast iron Le Creuset round pot (love it)
  3. Stir in the tomatoes, remaining whole spices and chopped garlic, raise the fire a bit and make it simmer.
  4. Add ground spices, stir, then add chickpeas and simmer for 5 minutes.
  5. Lower the heat and pour in the yoghurt. Bring to a simmer. Add salt to taste.
  6. Stir in spinach leaves. They’ll rapidly turn deep green.

Spinach

Serve with rice and enjoy!

Watch NASA TV using HTML 5 video

Saturday February 26 2011

I quite enjoy having NASA TV on in the background whilst coding on a drowsy Saturday afternoon. Unfortunately, their default player uses WMV9 which is less-than ideal. There is also a Quicktime H.264 Stream, but it’s only 320*240…

Luckily NASA also provides a feed made for iPad & iPhone users. If you encapsulate that in a a HTML5 <video> tag you get a great experience (at least on Safari/Mac). Check it out – and enjoy. Combine with Soma FM’s Mission Control for maximum spaciness!