Calendar
Recent posts
Post categories
Syndication
Search
Dreamfall nominated for MTV Video Music Award
Normally anything involving MTV is about as interesting to me as watching paint dry, but on occasion they do show some glimmer of hope that they might know what good music is.
This time, they have nominated the soundtrack of Dreamfall, the best adventure game in recent years, for an award, as game designer and writer Ragnar Tornquist writes. A worthy choice, as the soundtrack of Dreamfall is indeed very good. See, they can get it right, on occasion.
So please, go and vote for Dreamfall now! Vote, or the owl will eat you!
Category: Personal
Posted on 2006-08-01 13:27:50 UTC. Show Comments (1)
Can your programming language do this? C# can!
Joel on Software talks about the Swedish Chef and the advantages of anonymous functions and functional style programming with an example of map and reduce in Javascript.
He notes how terrible this is to implement in C with function pointers, or even worse in Java with functors. Thankfully, C# 2.0, with anonymous delegates and generics, offers a clean, type-safe way to do this, which doesn't require much more code than his javascript version. The only real additions are the declarations of the delegates used, and of course some necessary type specifications, because C# is still a strongly typed language.
So what does this code look like? The answer can be found below, with some more discussion on this Channel9 post made by me.
public delegate T MapDelegate<T>(T input); public delegate TAggregate ReduceDelegate<TAggregate, TInput>(TAggregate aggregate, TInput input); public static void Map<T>(IList<T> list, MapDelegate<T> function) { for( int x = 0; x < list.Count; ++x ) list[x] = function(list[x]); } public static TAggregate Reduce<TAggregate, TInput>(IEnumerable<TInput> list, TAggregate initial, ReduceDelegate<TAggregate, TInput> function) { TAggregate aggregate = initial; foreach( TInput item in list ) aggregate = function(aggregate, item); return aggregate; } public static void Foo() { List<int> list = new List<int>(new int[] { 1, 2, 3 }); // Multiply each element by 2. Map(list, delegate(int x) { return x * 2; }); // Sum values: result with be 12 int sum = Reduce(list, 0, delegate(int aggregate, int input) { return aggregate + input; }); // Concatenate values using a StringBuilder, result will be "246" string concat = Reduce(list, new StringBuilder(), delegate(StringBuilder aggregate, int input) { return aggregate.Append(input.ToString()); }).ToString(); }
EDIT 2006-08-04: Added code.
Category: Programming
Posted on 2006-08-02 21:00:59 UTC. Show Comments (4)
The joys of overflow:auto and cross-browser development
Some of you may have wondered why I initially didn't post the code for my Map/Reduce example on my blog, but only linked to the Channel9 post, and why I added it now. The answer is, because figuring out a good way to add code samples to my blog was still on the TODO list.
"But," I hear you say, "that's simple isn't it? A <pre>,
maybe some fancy colouring, end of story, right?"
Right. Except, no. You may have noticed that the content on this
is in a container that has a width relative to the page (70%, to
be precise). So what would happen if I put a <pre> in there,
and that contains a line that wouldn't fit. In Internet Explorer 7,
Firefox, Opera and other browsers with a proper overflow model,
the line would run out of the box. In IE6, it grows the box to fit
the line, destroying the entire page layout. Neither is very
desirable.
So there are two solutions. One is to have the lines wrap. The
simple way to do that would be to use white-space: pre-wrap;,
but alas, no browser that I know of actually supports that. The
other way would be to manually format it, inserting
and <br /> elements where needed. I don't much
like doing that, and I don't actually like having lines of code
wrap at arbitrary points either, so this solution is out the window.
Thus we end up with the solution I eventually used as you can see in the previous post. I used scrollbars.
The mechanism to create scrollbars, namely overflow:auto
has its own problems. You see, CSS 2 does not tell browsers where
these scrollbars should go, and as a result everybody does it
differently. CSS 2.1 rectified this oversight by saying the scrollbars
belong on the inside of the box with the overflow
style, i.e. the box does not grow to accomodate the scrollbars.
Perhaps surprisingly, the only browser that does this is IE. All
the others place the scrollbar outside the box. This means that in IE
if overflow:auto mandates a horizontal scrollbar, this scrollbar
now obscures part of the content, so a vertical scrollbar is also
needed. So setting overflow:auto will cause the code
sample to always have two scrollbars in IE, and only one in Firefox et al.
Not strictly a problem, especially since I wanted to add a max-height
so a vertical scrollbar is needed anyway.
There is, for those interested, a way to avoid the vertical scrollbar
even in IE. First, IE will behave differently if the element being
scrolled is a table. Second, you can force the scrollbar to the outside
using the CSS 3 properties overflow-x:scroll;overflow-y:visible.
Unfortunately, that is not a legal combination according to CSS 3, but
it works in IE. Firefox, Opera etc. do not support overflow-x/y at all.
The drawback is that it only works with overflow-x:scroll,
not overflow-x:auto so now the element gets a scrollbar
even if it doesn't need one!
IE6 adds additional difficulty. Because of the broken overflow model
(thankfully fixed in IE7), it never thinks the <pre>
needs a scrollbar unless you give it a specific width. Unfortunately,
that prevents IE7, Firefox, et al from automatically adjusting the width
if the element is next to the sidebar or not. Even worse, in Firefox,
an explicit width that's wider than the space next to the sidebar causes
the element to overlap the sidebar (why Firefox doesn't move it below
the float like IE does in this case I don't know). So that's out.
So in the end, we have overflow:auto, with the knowledge of the vertical scrollbar that will cause in IE (which is right according to spec), and some extra rules for IE6 (using the "* html" hack so other browsers (including IE7) ignore them). And then I could add the code.
Ah, the joys of cross-browser development...
Category: Programming
Posted on 2006-08-04 14:26:43 UTC. Show Comments (7)
A day at the Japanese Embassy
Last Thursday I had to go to the Japanese Embassy. Why would I go there, you ask? Because I'm trying to get a scholarship. The Japanese Government (Monbukagakusho) Scholarship for research students to be exact. Monbukagakusho is the Ministry of Education, Culture, Sports, Science, and Technology, commonly abbreviated as MEXT. This scholarship is for going to Japan for two years as a research student, and is for pretty much any field, not just computer science. At most three scholarships are awarded each year in the Netherlands.
So last Thursday I had to go to the Japanese Embassy for the preliminary selection process. I had to be there at 9:00, so I had to get up at 6:30 - which is really early, for me anyway. I got up, had a quick breakfast, put on my best (and only) suit, and set off for The Hague using public transportation, furiously hoping there wouldn't be any delays, and that it wouldn't rain (since that'd be hell on my suit).
Fortunately, all went exactly as planned, and at 8:45 I arrived at the Embassy, where they told me to wait outside because they weren't open yet. Too bad arriving exactly on time is nearly impossible when using public transportation. I was also first, but soon a few others showed up. In total, there were six applicants, which since there are at most three scholarships meant I had to killoutperform three of them.
At 9:15 sharp we started. First up were exams. Our knowledge of both English and Japanese would be tested in a total of four exams: one English, three Japanese with increasing difficulty. The English exam was easy. The only difficult thing about it was that some of it was really weird English (the most difficult questions were of the type "which of the following four sentences is wrong?" They were all wrong!) but it was still not much of a challenge.
Then came Japanese. Note that it's not actually required to speak Japanese to get this scholarship, so the exams were just to check my current proficiency. The three exams were labelled simply Japanese A, B and C but as far as I gathered they were equivalent of sankyuu, nikyuu and ikkyuu (third, second and first level Japanese, with first being the highest), which are standard Japanese Language Proficiency Tests. The first one went pretty well. The first part was downright easy, although the last text was slightly more difficult. But, I could understand nearly all of it, and didn't have to guess any of the questions.
The second one was a lot more difficult. The number of words and kanji that I didn't know increased drastically, which made answering some of the questions really hard. I think the ratio of knowing to guessing was about 40 to 60. Which may seem bad, but it was along my expectations. After a brief lunch came the third exam, which was extremely difficult. If it really was ikkyuu that's not surprising though. Overall I feel I could have answered this one just as good if they hadn't given me the questions, just the answer sheet. So I guessed pretty much all of it. Again, bad, but as expected. Being thoroughly exhausted by now didn't help either.
Then, the six of us were brought down to the Embassy's library and told to wait until 15:00, and then we'd be called up one by one for an interview which would last 15-20 minutes.
Exactly how they determined the order of interviewing us I didn't know. It wasn't by first name, by last name, by birthdate or any other discernable pattern, so I guess it was random. In any case, I was third to go. I can't recall ever being more nervous in my entire life. The nerves combined with the mental exhaustion from four hours of exams meant that I suddely felt I would have less difficulty competing in the winter olympics than doing this interview. Unfortunately, there weren't any skating rings available, but there was a really big table with a lot of chairs around it, and four people on one side - two from the Embassy, one professor from Leiden (not from the CompSci department of course) who was on the committee, and one from Nuffic (the foundation that coordinates these scholarships in the Netherlands), and me on the other side.
After brief introductions, they started asking questions. You could say the questions fell into two categories: the first bit was about my research proposal, the second about my motivation and my other plans (in Japan and for the future in general). The part about my proposal went really well. They seemed to think my proposal was pretty good (the professor from Leiden called it "enthousiastic") and I could answer their questions without much problems. I do, after all, know what I'm talking about (although the American style of job interviews where you have to have an air of "I'm the best person for this job that exists" doesn't work in Japan, a degree of modesty is better, or so I'm told). The other part went, well, less good. I had anticipated the sort of questions they would ask, and had prepared answers. Unfortunately, I couldn't remember any of them. So I winged it, best as I could. I can't remember half of what I said, it must have made some sense though (see below).
After what felt like 30 seconds but what was more like 20 minutes I went back to the library. I could leave at this point if I wanted, but we had decided we would wait for each other. Finally, around 17:00, all of us had been interviewed, after which we left.
All in all, I was reasonably satisfied. Sure, there's a ton of things I could've said but didn't, but no point in worrying about that now. Whether it would be good enough, I had no idea whatsoever. I didn't know how the rest had done on the interviews, and I didn't know what their criteria would be. In any case, I was exhausted, and spent the evening doing exactly nothing and slept better than I have in a long time.
Although final approval for the scholarship depends on a number of things (such as admission to the University in Japan, in my case Tokyo University) and wouldn't be known until around January, we would be told if we had been tentatively selected the next week. Tentative selection means we passed the interview and exam portion, and would be able to apply for admission and the rest.
Naturally, next week last Thursday is this week, and I just received a call. I made it through! So now comes the real work, getting admission etc. (not to mention, graduating :P ). It's not final (I'm not even sure if we're already narrowed down to three candidates or if that comes later, since we said we'd keep in touch I suppose I'll find out), but it's a big step in the right direction.
So yeah, I'm pretty pleased right now. :)
Category: Japan
Posted on 2006-08-21 14:31:51 UTC. Show Comments (0)
New download: Find As You Type
I'm proud to announce a brand new download on ookii.org: Find As You Type for Internet Explorer.
Find As You Type provides "interactive search" capabilities similar to Firefox and Emacs, but for Internet Explorer. It works on Internet Explorer 5 and higher (including IE7, of course). It'll work on x86 and x64 versions of Windows.
This has been my first venture into creating an IE add-on, and also the first big unmanaged C++ Win32 project I've done in a long while. Although MS is keen to emphasise that IE, like Firefox, can indeed be extended (and not just for spyware either!), but it's difficult, very difficult.
Over the next few days I intend to make a few blog posts documenting some of the pitfalls I've encountered. In particular I'll cover those issues that are not only under-documented on MSDN, but whose answer can't be easily found using a Google search.
The following is a list of these articles. I will add links as more articles become available.
- Making your add-on use visual styles (aka themes)
- Handling toolbar messages
- Handling keyboard input
- Globally capturing keyboard input
- Capturing keyboard input outside tabs
- Communicating with tabs across threads
Category: Software
Posted on 2006-08-30 20:36:38 UTC. Show Comments (3)
IE add-on development: help, my toolbar looks ugly!
As promised, this is the first in what will be a few articles about some of the pitfalls involved in writing IE add-ons, based on my own experience in writing Find As You Type for Internet Explorer. This isn't meant to be a tutorial or a definitive guide to writing add-ons; it's assumed you have at least some knowledge on how to do this. For a review of the basics, you can check this article on MSDN.
A list of the articles in this series is available here.
The first item I will cover is visual styles. Suppose you were to write you own add-on based on the guide at the link above, or even if you just compile the samples from MSDN or CodeProject or similar, and then run them. You will soon notice that your toolbar or explorer bar doesn't use the Windows XP theme (or the Vista theme on Vista), or visual style. Instead it will use the Windows Classic look. Here's what the Find As You Type toolbar looks like without visual styles:
As you can see, this looks quite out of place, because the rest of Internet Explorer is using the proper theme.
So how to go about fixing this. Unfortunately, the answer to that is quite hard to find. Some casual googling will not reveal it (although it can be found that way, but it's quite buried). Of course it's my hope that if you googled this problem, you ended up on this page. :)
Fortunately, once you know the answer, it's quite simple to actually do it. The answer is described in Microsoft Knowledge Base article 830033, which, although it says it's about Office add-ons, it also applies to Internet Explorer add-ons.
As it turns out, you must add a special manifest resource to your application. This is quite similar to how you'd make any application support visual styles. The difference is that, instead of the normal CREATEPROCESS_MANIFEST_RESOURCE_ID, you must use the ISOLATIONAWARE_MANIFEST_RESOURCE_ID.
Note that if you are using Visual Studio 2005, you don't actually need to create (or modify) a resource file like it specifies in the article. You can simply add the manifest file to your Visual C++ Win32 DLL project, and it will be embedded automatically. For DLL projects, Visual Studio 2005 automatically uses the ISOLATIONAWARE_MANIFEST_RESOURCE_ID to do this. After this is done, Find As You Type looks like this.
And that, of course, looks much nicer. There remains one problem that I do not yet know how to solve. If you open any windows from your add-on, for instance using the Win32 MessageBox or DialogBox function, they will still not have visual styles. Considering that even Microsoft's own Internet Explorer Developer Toolbar suffers from this problem, I don't know if there even is a solution for that. But if anyone knows how, I'd appreciate it if they'd let me know.
That concludes my first IE add-on article. Next time, we'll look at how to handle messages if you're writing a toolbar.
Category: Programming
Posted on 2006-08-31 21:35:13 UTC. Show Comments (6)