Walled off gardens
July 7, 2008 – 10:14 pmI just finished testing a beta version of a VOD (Video-On-Demand) solution of my local Cable TV provider. In my mind an ideal Video-On-Demand solutions is the one where, when you happen to be bored and just want to watch a movie, you go and select something out of catalogue of tens of thousands of movie and then start watching it right away. Preferrably without any ad interruptions. Now, I know that you guys in US have Netflix and other similar services, but we here in Estonia are not that lucky. There aren’t really that many options besides video rental stores (with barely any selection) and of course DVD stores (be it brick-and-mortar store or an online one). So, I had really high hopes for that particular VOD application, but sadly it turned out to be a major disappointment.
Firstly, there is barely any movie selection as of right now. But this really is not that much of a problem, because the whole thing is still in beta stadium and movies can be added very easily later on once the platform is mature enough. It is also slow, but that too is forgivable in a beta version of the app.
In my eyes the major mistake they did was - the UI. You’re expected to browse the catalogue and make selections from your TV using your remote. White at the first glance it does not seem that bad of an idea - it really does not work out. Imagine a catalogue of lets say 50.000 titles, you’re looking for something - the remote control however does not have a full keyboard, so the developers opted for an on-screen keyboard. One where a keyboard is shown on screen and you’re expected to move around with arrow keys and select letters one by one. Of course, it is pretty much the only solution when your input device is a TV remote. But it also is seriously cumbersome. Then combine that kind of UI with navigating back and forth inside search results. And once you make a selection and “rent” the movie you have to start over beginning. But I want to have much more than that. I want to bookmark search results, I want to see recommendations from my friends, I want to see newly added movies in my RSS reader and I really can’t do any of that. By now it should be obvious what I’m aiming at here.
The biggest mistake is that the authors of that particular app built their own walled off garden for themselves. A completely new application, inside a seriously limited environment (TV + remote), an enviroment, that was never designed for jobs like this. All UI and UI elements have to be invented again there are no comfortable ways to control the UI and precisely because of that this thing will never work out well.
They are not the first ones either, there are numerous examples throughout the history. Why, again, do people keep making the same mistake over and over again?
Let me describe the ideal (or at least 100x times better) VOD solution. It would be a web application, the whole catalogue should be browseable online, I could read reviews inside both the catalogue and external sites, create favourites lists, get updates on new titles through an RSS reader and really to all those fun things that are possible inside the web application.
Then, after making the choice of what I want to see, I could pay for it right away. With my credit card or bank transfer (the latter works really well here in Estonia, it’s virtually instant and very secure) and only the last step of the VOD application should be inside my TV - the one where I can see my currently “rented” movies and view them. Everything else should be built as a web application. The web app could also be linked to an online DVD store, so for example if I happen to really like a particular movie or show I could order it on DVD with just a few clicks. The possibilites are endless.
And yet people choose the path of walling themselves off from the world wide web.
links for 2008-06-24
June 25, 2008 – 1:37 amlinks for 2008-06-22
June 23, 2008 – 1:35 amEating habits of developers
June 12, 2008 – 12:37 pmThis one started out as an internal joke, but it has become quite generic
- Java developers always go to eat together, in pairs, hand in hand, well organized (synchronized)
- PHP devs go at random times, some of them run, some walk, some take the elevator. (loose coding style)
- DB devs choose someone, who will then go to kitchen and fetch the food for everyone (also known as proxy)
- Delphi devs get the plate, put it in the center of kitchen, then get a fork and then walk between the food containers and plate, until plate is filled (drag ‘n drop)
- C devs kill their own animals and eat them raw (low-level)
- C++ devs prepare their food from prefabricated components in microwave oven (not that low-level)
- Frontend (HTML) devs decorate their food with cucumbers, tomatoes and generally everything else in the fridge and then play around with it until the food is cold
- Python devs always take the stairs (mandatory stepping) (from Jaagup Irve)
- Perl devs bring their own food to the work and eat it alone in the corner, while everybody else is giving them weird glances (You call THAT food? eewwwww) (syntax)
Scanning files for a specific string
June 11, 2008 – 7:21 pmOver at DevNetwork forums somebody asked for a piece of code, that scans a directory containing thousands of files for a file containg specific string.
Here is the solution I came up with it:
-
< ?php
-
// list file extensions that you care about here
-
$extensions = array('php','inc');
-
-
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.')) as $Item)
-
{
-
if ($Item->isFile() and in_array(pathinfo($Item->getFilename(),PATHINFO_EXTENSION),$extensions))
-
{
-
foreach($Item->openFile() as $linenum => $line)
-
{
-
// add the code to check your pattern here
-
if (stripos($line,'class') !== false) {
-
echo $Item->getPathname(), ':', $linenum, ' ', $line;
-
}
-
}
-
}
-
}
Upside: it scans the directory structure recursively and the code is quite clean, besides maybe the pathinfo call to filter out filenames with specific extension.
Downside: it’s slow. In real life grep or some other tool is used for task like this.
Still, the code shows the power of SPL File- & DirectoryIterators nicely.
Grouping array contents
June 10, 2008 – 4:02 pmSource data:
-
$triples = array();
-
$triples[] = array('VISA','EUR',13);
-
$triples[] = array('VISA','EUR',26);
-
$triples[] = array('VISA','EUR',39);
-
$triples[] = array('VISA','JPY',13);
-
$triples[] = array('PAYPAL','JPY',13);
Desired result
-
array(
-
array('VISA','EUR',78),
-
array('VISA','JPY',13),
-
array('PAYPAL','JPY',13)
-
)
e.g. group data by both payment method and currency.
My solution
-
$triples = array();
-
$triples[] = array('VISA','EUR',13);
-
$triples[] = array('VISA','EUR',26);
-
$triples[] = array('VISA','EUR',39);
-
$triples[] = array('VISA','JPY',13);
-
$triples[] = array('PAYPAL','JPY',13);
-
-
-
$result = array();
-
foreach($triples as $key => $value)
-
{
-
$lookup_key = $value[0] . '-' . $value[1];
-
if (array_key_exists($lookup_key, $result)) {
-
$result[$lookup_key][2] += $value[2];
-
} else {
-
$result[$lookup_key] = $value;
-
}
-
}
-
-
print_r($result);
Downside - data is accessed by numberic key, which is generally not a good thing to do. This however is just a proof of concept, in real life you probably have names for your columns.
Can you write a shorter and more elegant solution?
Searching file contents with Iterators
June 4, 2008 – 11:12 am-
// the following code returns all lines of source.txt that contain the string Aerosmith.
-
// Feel free to extend it for your own uses
-
class FileGrep extends FilterIterator
-
{
-
private $needle;
-
-
public function __construct($file, $needle) {
-
parent::__construct(new SplFileObject($file));
-
$this->needle = $needle;
-
}
-
-
public function accept()
-
{
-
if (strpos($this->current(),$this->needle) !== false) {
-
return true;
-
}
-
}
-
-
}
-
-
foreach(new FileGrep('source.txt','Aerosmith') as $line) {
-
print $line;
-
}
SimpleXMLIterator & FilterIterator combined
June 3, 2008 – 10:55 pm-
< ?php
-
/*
-
Goal:
-
* Take a GPX (which is XML) file
-
* Extract interesting records from it
-
* Calculate the arithmetic average of latitudes and longitutes
-
-
I won't tell you why exactly I needed this, just that it is part of a game
-
called geocaching
-
-
—
-
-
Class is called collector, because I am _collecting_ only the records
-
I'm interested in
-
-
Example record:
-
<wpt lat="59.4658317566" lon="24.8649997711">
-
<name>< ![CDATA[Gtehnokratt]]></name>
-
<url>< ![CDATA[http://www.geopeitus.ee/?p=350&c=2]]></url>
-
-
-
Actually there is more data, but I'm only interested in lat and lon attributes
-
and name and url elements.
-
-
Records do not have any id-s, only the url has the unique identifier at the end.
-
*/
-
-
class Collector extends FilterIterator
-
{
-
/**
-
* I only care about records with id's that are listed here
-
*/
-
private $ids = array(187, 513, 537, 542, 544, 563, 605, 715, 717, 748);
-
-
/**
-
* Set up the FilterIterator by passing our SimpleXMLIterator to it
-
*/
-
public function __construct(Iterator $it) {
-
parent::__construct($it);
-
}
-
-
/**
-
* Part of FilterIterator implementation, called for each record,
-
* responsible for the decision whether the current element is needed
-
* or not
-
*/
-
public function accept() {
-
$id = $this->get_id_from_url($this->current()->url);
-
if (in_array($id,$this->ids)) {
-
return true;
-
}
-
return false;
-
}
-
/**
-
* Extracts record ID from string
-
*/
-
private function get_id_from_url($url)
-
{
-
// http://www.geopeitus.ee/?p=350&c=514
-
preg_match('/&c=(\d+)$/',$url,$matches);
-
return $matches[1];
-
}
-
}
-
-
/*
-
SimpleXMLIterator is one of the standard SPL iterators, which makes it possible
-
to use other standard iterators when parsing XML
-
-
Second argument of simplexml_load_file is a class name and as result the XML
-
in-memory representation becomes instance of that class. Seems awkward, but
-
really useful
-
*/
-
$it = simplexml_load_file('geopeitusee.gpx','SimpleXMLIterator');
-
-
$lat_sum = $lon_sum = $count = 0.0;
-
-
// so, all the data goes in, but only the elements I'm interested in, come out
-
foreach(new Collector($it) as $element) {
-
// access subnodes with $element->name
-
// access attributes with array notation
-
printf("taking %s, lat=%f, lon = %f\n", $element->name,$element['lat'],$element['lon']);
-
-
// typecasting is needed to get correct results from SimpleXML, otherwise you would
-
// get integers
-
$lat_sum += (float)$element['lat'];
-
$lon_sum += (float)$element['lon'];
-
$count++;
-
}
-
-
// finally do the math
-
printf("Average: cnt=%d lat=%s, lon=%s\n", $count, ($lat_sum / $count), $lon_sum / $count);
How to make sure you’re an Estonian
May 29, 2008 – 4:55 pm1. You use the word “normal” if something is ok.
2. When visiting friends abroad you bring along a box of Kalev chocolate.
3. You attended a song festival at least once either as a performer or as a spectator.
4. You know that going to the sauna is 80% about networking and 20% about washing.
5. You are nationalistic about Skype (it is actually an Estonian company).
6. ‘Kohuke’ belongs to your menu.
7. You declare your taxes on the internet like all modern people.
8. You actually believed for a while that Latvians had 6 toes per foot when you heard that as a child.
9. You are convinced that Estonia is very strategically located.
10. You spent at least one midsummer in Saaremaa, Hiiumaa or one of the smaller islands.
11. You can quote films like “Viimne reliikvia” and “Siin me oleme”.
12. You spit three times around your left shoulder for good luck.
13. Words like “veoauto”, “täieõiguslik” or “jää-äär” sound perfectly pronouncable to you.
14. You like bold statements, such as this one?
15. There can never be too much sarcasm.
16. You can at times drink hot tea to hot food.
17. You are disappointed that Jaan Kross never got the Nobel prize in literature.
18. It would not be suprising for English-speakers to find your name naughty (Peep, Tiit, Andres [sounds like undress]) or hippy (Rein, Rain).
19. You have been to Finland.
20. You say ‘Noh’ (sounds like NO) even when you speak English, just to confuse people.
21. You know the lyrics to “Mutionu” and “Rongisõit”.
22. You would never mistaken Kreisiraadio for a radio station.
23. You would agree that wife-carrying is a real sport (at least as long as Estonians are winning).
24. Your best friend’s girlfriend is your English teacher’s daughter and they live next door to your grandparents, who were colleagues with your advisor, who is friends with your?
25. You think that any beverage below 20% is non-alcoholic.
26. You check the thermometer before going out.
27. You look in both directions before crossing the road, even if it’s a one-way street.
28. You grin very mysteriously when people ask about your national food.
29. You teach a non-Estonian speaker the word “Tänan” before “Aitäh”.
30. You put ketchup inside your pasta (french-cooked gourmet faire la finemanger pasta) in order to not to get the ketchup-bowl dirty.
31. You cheated on your husband/wife at least ten times but you still think you’re in a good marriage.
32. When someone asks you “Where is Estonia?” you quickly reply that it’s located in Northern Europe close to Finland?
33. Your grandmother’s “purse” is an old plastic bag that has been reused several times.
34. Sour cream tastes good with everything.
35. A foreigner speaks to you in broken horrible Estonian and you go on and on about how wonderful their Estonian is compared to “the Russians”.
36. You have ever worn or seen anyone wear “karupüksid”.
