I've not been a Twitter user until now, so I'm curious what impact this will have.
Follow Profoss at http://twitter.com/profoss
History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com
Thursday, 23 October 2008
Saturday, 11 October 2008
Ruby flexibility to the rescue
In the development of UploadForMe, I had a chain of methods called, each of which possibly returning nil. I really didn't want to check at each step if the returned value was nil, as I would have ended up with something like
I quickly created a class which would help me get around this problem, and I think (I haven't checked further, honnestly) this goes in the direction of monads, which are well known in Haskell.
The solution is to have a class of which an instance is returned in place of nil. This instance responds to all methods by returning an instance of the same class, in turn responding to all methods. However such an instance responds to the method #nil? with true.
And I'm using this class as return value in a class derived from Hash. method_missing returns either the value in the hash for which the key is the method name just called, or an instance of the class above:
That way, we can chain calls as we want:
You have to be cautious in naming your keys to avoid clashes, but in my case this is an acceptable trade-off.
There might also be better and more advanced solutions out there. Don't hesitate to mention them in the comments.
if (o!=nil and o.first_call!=nil and o.first_call.second_call!=nil)
I quickly created a class which would help me get around this problem, and I think (I haven't checked further, honnestly) this goes in the direction of monads, which are well known in Haskell.
The solution is to have a class of which an instance is returned in place of nil. This instance responds to all methods by returning an instance of the same class, in turn responding to all methods. However such an instance responds to the method #nil? with true.
class SimpleMonad
def initialize(h={:is_nil => true})
@is_nil = h[:is_nil]
end
def method_missing(m, *args)
return SimpleMonad.new
end
def nil?
@is_nil
end
end
And I'm using this class as return value in a class derived from Hash. method_missing returns either the value in the hash for which the key is the method name just called, or an instance of the class above:
class ServicesKeys < Hash
def method_missing(m, *args)
if keys.include?(m)
return self[m]
else
return SimpleMonad.new
end
end
end
That way, we can chain calls as we want:
#define the object we will work on
h = ServicesKeys[ :uploadforme => ServicesKeys[:login => 'rb', :username => 'rb']]
#we can easily access the values in there:
h.uploadforme.login
=> "rb"
#if we try to access values for an undefined service, we don't get in trouble:
h.myowndb.login.nil?
=> true
You have to be cautious in naming your keys to avoid clashes, but in my case this is an acceptable trade-off.
There might also be better and more advanced solutions out there. Don't hesitate to mention them in the comments.
Sunday, 5 October 2008
Why use Chrome when you have Arora?
When Google's Chrome came out, I was rather surprised by the move, and was eager to try it. But when I saw it was Windows only, I andandoned the idea even if I could have tried with Wine: I couldn't see any good reason to use a non-native browser. Reading Kris's blog post about his test of Chrome on wine only confirmed my opinion.
I was interested to test a browser with the Webkit engine though, and was surprised there wasn't an open source browser based on Webkit available on my platform of choice (GNU/Linux). The Epiphany developers had announced a switch to webkit some time ago, but it still isn't effective it seems.
A search on the internet returned Midori, build with GTK2. I'm not a fan of GTK, and I was surprised there was no Qt based browser, as Webkit is now integrated to Qt (from Qt4.4). Finally, this week I discovered Arora, which was originally a demo browser integrated to Qt4.4.
Installing Arora was easy once I had installed Qt4.4 from sources. I had originally tried with a Qt4.5 snapshot through git, but it wouldn't compile. Compiling Arora itself was so fast I thought I had forgotten to do something.
And Arora is fast too. Using it is also a good experience (eg I'm writing this blog post with Arora).
I don't think it will replace Firefox as my primary browser just yet, but it will take an important place on my desktop as I expect it to become the fast browser without any plugins or extensions I'll keep running in the corner to access the web-based tools I run continuously. And yes, MyOwnDB runs great in Arora!
I was interested to test a browser with the Webkit engine though, and was surprised there wasn't an open source browser based on Webkit available on my platform of choice (GNU/Linux). The Epiphany developers had announced a switch to webkit some time ago, but it still isn't effective it seems.
A search on the internet returned Midori, build with GTK2. I'm not a fan of GTK, and I was surprised there was no Qt based browser, as Webkit is now integrated to Qt (from Qt4.4). Finally, this week I discovered Arora, which was originally a demo browser integrated to Qt4.4.
Installing Arora was easy once I had installed Qt4.4 from sources. I had originally tried with a Qt4.5 snapshot through git, but it wouldn't compile. Compiling Arora itself was so fast I thought I had forgotten to do something.
And Arora is fast too. Using it is also a good experience (eg I'm writing this blog post with Arora).
I don't think it will replace Firefox as my primary browser just yet, but it will take an important place on my desktop as I expect it to become the fast browser without any plugins or extensions I'll keep running in the corner to access the web-based tools I run continuously. And yes, MyOwnDB runs great in Arora!
Thursday, 18 September 2008
LuckyAs.Me siteof the day: learn german history
Wednesday, 17 September 2008
AntWeb: LuckyAs.Me site of the day
As a result for a search for Belgium on LuckyAs.Me, I got redirected to a website dedicated to ants: AntWeb.
There I learned that we have (had) 86 species of ant in Belgium (of which 9 haven't been spotted the last 50 years).
There I learned that we have (had) 86 species of ant in Belgium (of which 9 haven't been spotted the last 50 years).
Tuesday, 16 September 2008
Using search for fun
Why always be limited to the 10 first matches? www.luckyas.me is built on YAHOO boss and redirects you to a random site that is in the first 100 results returned by YAHOO for your search.
Maybe not useful, but can be fun when you have some time to change your mind. I discovered there's a Bauduin Preschool, a police inpector whose family name is Boulette, there's a restaurant called La Frite in the US, but also a mention of the Profoss OpenOffice event on BoycottNovell.
Have fun and let me know what you think of it.
Maybe not useful, but can be fun when you have some time to change your mind. I discovered there's a Bauduin Preschool, a police inpector whose family name is Boulette, there's a restaurant called La Frite in the US, but also a mention of the Profoss OpenOffice event on BoycottNovell.
Have fun and let me know what you think of it.
Friday, 12 September 2008
When you're clueless... (2)
you should really shut up.
Sometimes I think of those talented artists who don't get their record published, while totally untalented people get selected in a reality show to have an album published, only to flop because they're so bad.
Now I think of those talented bloggers, who try to live from that activity, and who see such crap published on CNet, who paid its author.
As a reminder, here's the first post in what has just become a serie.
Sometimes I think of those talented artists who don't get their record published, while totally untalented people get selected in a reality show to have an album published, only to flop because they're so bad.
Now I think of those talented bloggers, who try to live from that activity, and who see such crap published on CNet, who paid its author.
As a reminder, here's the first post in what has just become a serie.
Subscribe to:
Posts (Atom)