Ben vorig jaar vooral met Ruby en Rails bezig geweest, en nu werkzaam als .Net Developer in C#.

Linq extenties bieden vanaf C# 2008 een hoop leuke functies zoals Select, Aggregate, etc.  Eigenlijk alles om het werken met allerlei collecties behoorlijk te vergemakkelijken, vooral in combinatie met lambda expressies.

Maar 1 ding zat me dwars: waarom is er geen alternatieve foreach lus zoals in Ruby.

Voorbeeld:

collection = ["hello", "world"]

collection.each do |item|

puts item

end

Dit doet hetzelfde als deze C# code:

string[] collection = {”Hello”, “World”};

foreach (string item in collection)

{

Console.WriteLine(item);

}

Daarom heb ik uit nieuwsgierigheid dit proberen te bereiken in C# aan de hand van een eigen extensie en het is eigenlijk behoorlijk kort en eenvoudig om tot een erg praktisch resultaat te komen die werkt op alle standaard .NET collecties, arrays, etc…

De .cs-file: EachIteratorExtention

using System;
using System.Collections.Generic;
using System.Linq;

namespace EachExtensionExample
{
    public static class EachIteratorExtension
    {
        public static void Each<TSource>(this IEnumerable<TSource> source, Action<TSource> iterator)
        {
            foreach (TSource item in source) iterator(item);
        }
    }

    internal class Program
    {
        private static void Main()
        {
            string[] collection = { "Hello", "World" };
            collection.Each(item => Console.WriteLine(item));

            Console.WriteLine();

            //of meerdere lijnen
            collection.Each(item =>
            {
                Console.WriteLine(item);
                Console.WriteLine(item.ToUpper());
            });

            Console.WriteLine();

            //maar hetzelfde werkt met zowat alle .NET collecties
            //enige vereiste is dat ze IEnumerable implementeren
            var dates = new List<DateTime>();
            Enumerable.Range(0, 7).Each(day => dates.Add(DateTime.Now.AddDays(day)));
            dates.Each(d => Console.WriteLine(d.DayOfWeek));

            var dates2 = new List<DateTime>() { DateTime.Now };
            var nestedList = new List<List<DateTime>> { dates, dates2 };
            nestedList.Each(list =>
                Console.WriteLine("Dates in list: {0}", list.Count)
                );

            Console.ReadLine();
        }
    }
}

Edit: Kleine update gedaan, het is zelfs niet nodig van een delegate te gebruiken.

Posted in Uncategorized at December 15th, 2008. No Comments.

This week was the first week of the “project weeks”, 3 weeks to go. In a group of 3 students we have to finish the project they give us.

In short, our project is a browser-based meal-application for a school.
They are using a very old DOS application right now and they really need an update.

Everybody works on the same project, using different languages and frameworks. The best implemantion will be used in the school. And I’m lucky: using Ruby On Rails.
After 1 week we already have most of the functionality and a layout finished.

It’s kind of getting used to Rails 2, more things have changed than I though. Also I stopped using Eclipse as my IDE and now just use gEdit and the commandline.
Why? It’s fast and I’m learning a whole lot more without an IDE helping me all the time. So far I haven’t even missed a visual debugger, hope it stays this way…

Posted in Uncategorized at February 15th, 2008. No Comments.

Tweakers.net bied enkel rss-feeds met kort stukje van het artikel in, en als extra af en toe reclame…

Maar sindskort heeft Yahoo Pipes een nieuwe module bij: Fetch Page. Deze maakt het wel erg makkelijk om, aan de hand van de originele feed, de artikels van de site in de feed te plaatsen.

Heb het even gedaan voor het nieuws en de meuktracker:

De preview op yahoo pipes toont niet het volledige artikel, maar in een RSS reader staan ze volledig.

Posted in RSS at January 17th, 2008. 1 Comment.

I have quite a lot of RSS feeds I read as some sort of daily routine. My feed-reader of choice has been Google Reader for some time now.

Today I’ll share all the online comics I’m reading. Other feeds will follow some day :)
Feel free to introduce me to other comics.

Posted in Personal, RSS, comic at December 28th, 2007. 1 Comment.

Kind of hard to concentrate on all these important projects I’m working on right now during the holidays (and my birthday too ;) ), but a man’s gotta do what a man’s gotta do.

What projects am I talking about?

  • a web shop for movies (Java Server Faces, Ajax4JSF, Hibernate and some other libraries)
  • Gamers Initiative, a community site for game developers and gamers (Ruby On Rails)
  • an advertisement site, let users create advertisements and submit them to magazines and/or newspapers . (ASP.NET, C#)
  • creating a little experiment (some kind of poll) for the thesis my girlfriend is writing. I’ve been experimenting with some PHP frameworks, but haven’t decided which one I’ll use. So far Symphony (MVC-framework) and Prado (framework similar to ASP.NET) are fun and fast to use, though they both are very different.

    I also tried Zend Framework and CodeIgniter, but they got me less excited. I don’t like the way database abstraction is done in Zend, and CodeIgniter is too limited in several ways.

A bit late for Christmas, but I’d like to say: a merry Christmas and a happy new year. I wish you all a good health, lots of love, a good web year and everything else you might need.

Posted in MCT, Personal at December 26th, 2007. No Comments.

An big problem with loading content in your page with javascript, is that this content can’t be seen by search-engines.
But this problem can be overcome, see this little code example I wrote.

What can this do?

  • All pages can be used with Javascript disable
  • You can bookmark a page that was loaded with javascript, thanks to RHS
  • The back and forward buttons of the browser are still functional

To write this, I used the jQuery javascript framework and the RHS library

You can test the example online. Or download it.

Read More…

Posted in PHP at December 8th, 2007. 12 Comments.

We Seem To Have Misplaced Our Igloo Yesterday went to see We Seem To Have Misplaced Our Igloo at Den Trap in Kortrijk. A local upcoming indie band that just released there first demo.

This was the second time I saw them perform, and they made a lot of progress in very short time. Yes, I’m a fan already.

Bought the demo for just €5 and it’s definitly worth the money, check them out at there next gig!

Posted in Music at November 26th, 2007. 3 Comments.

I’m reading a lot of daily comics and this one is just too hilarious.

A fast guy

dilbert.com

Posted in comic at November 16th, 2007. No Comments.