Cartoons van journalist verboden, Volkskrant zwijgt
22 Mar 2008 8:09 - (0) comments
http://www.volkskrantblog.nl/bericht/191036
Ordina puzzle in Ruby
08 Dec 2007 19:14 - (0) comments
Ordina is running a campaign to attract Java developers.
Here is my version of the puzzle in Ruby. For a better comparison I've kept some of the Java style code and refrained from some one liners. Still, it's about half as long as the Java version.
My solution to the puzzle uses wikipedia to lookup the acronyms.
ordina.rb
require 'open-uri'
module Nl
module Ordina
class JavaSpecialistdef self.main
js = find_specialist_wanna_be
if js
js.start
else
puts "Geen JavaSpecialist implementatie gevonden"
end
enddef start
report = "Volgens de specialist #{name}\x5c\x6eHebben de volgende termen de betekenis" +
"\x5c\x6e\x55\x4d\x4c #{eval "waarStaat\x55\x4d\x4cVoor" } \x5c\x6e\x52\x55\x50 " +
"#{eval "waarStaat\x52\x55\x50Voor" } \x5c\x6e\x58\x4d\x4c #{eval "waarStaat\x58\x4d\x4cVoor" } " +
"\x5c\x6e\x4d\x56\x43 #{eval "waarStaat\x4d\x56\x43Voor" } \x5c\x6e\x45\x4a\x42 " +
"#{eval "waarStaat\x45\x4a\x42Voor" }\x5c\x6e\x41\x4f\x50 #{eval "waarStaat\x41\x4f\x50Voor" } " +
"\x5c\x6e\x4a\x53\x46 #{eval "waarStaat\x4a\x53\x46Voor" }"
puts report.gsub!('\n', "\n")
puts kijk_bij_ordina
endprivate
def self.find_specialist_wanna_be
dir = Nl::Ordina.name.gsub('::', '/').downcase
Dir.new(dir).each{|i| require("#{dir}/#{i}") unless File.directory?("#{dir}/#{i}") }
Nl::Ordina.constants.each do |i|
unless i == self.name.split('::').last
obj = instance_eval(i).new
return obj if obj.is_a? JavaSpecialist
end
end
enddef kijk_bij_ordina
open("http://jobportal.ordina.nl/jobportal-front/pages/index.jsf").read
rescue
'Kijk op http://jobportal.ordina.nl/'
end
end
end
end
Nl::Ordina::JavaSpecialist.main
nl/ordina/impl.rb
module Nl
module Ordina
class JavaSpecialistImpl < JavaSpecialist
def name
"p8"
enddef method_missing(*args)
afk = args.first.to_s.gsub('waarStaat', '').gsub('Voor', '')
page = open("http://en.wikipedia.org/wiki/#{afk}").read
matchdata = /<title>([^>]*)(<\/title>)/.match(page)
matchdata ? matchdata[1].gsub('- Wikipedia, the free encyclopedia', '') : 'Onbekend'
end
end
end
end
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'
21 Jul 2007 10:20 - (0) comments
OSX crashed yesterday and after restarting I got the following error in some php apps
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'.
This happened once before so I'm documenting the proper solution here for possible later use.
sudo /usr/sbin/apachectl stop
apache2ctl start
Setting the default Browser on OSX with Ruby
06 Jul 2007 22:39 - (0) comments
To combat my ADD I want to seperate my work and private browsing. So having two seperate workspaces sounds like a good idea.
I tried Virtue Desktop (and all the other ones) but they were useless to me, because all the virtual desktops show all running applications when switching application with Command+tab. I only want to see the ones in my current desktop.
Creating another user account isn't an option either because I want to access my mail for both work and private use.
So I need a browser switcher I can run from the commandline so I can schedule it with crontab.
The Objective C part
For the Objecive C part I create a SwitchBrowser directory.
In it I create a file called ~/SwitchBrowser/SwitchBrowser.h:
#import
@interface SwitchBrowser : NSObject
{}
- (CFArrayRef) browsers;
- (void)setDefaultBrowser: (CFStringRef) newDefaultStr;
@end
... and a file called ~/SwitchBrowser/SwitchBrowser.m:
(Copied from Giant Mike's FavBrowse)
#import "SwitchBrowser.h"
@implementation SwitchBrowser
- (CFArrayRef) browsers {
return LSCopyAllHandlersForURLScheme(CFSTR("https"));
}- (void)setDefaultBrowser: (CFStringRef) newDefaultStr
{//Set the launch services settings for https:// and http://
LSSetDefaultHandlerForURLScheme(CFSTR("https"), newDefaultStr);
LSSetDefaultHandlerForURLScheme(CFSTR("http"), newDefaultStr);//Set the launch services setting for web sites discovered via Bonjour
LSSetDefaultRoleHandlerForContentType(CFSTR("public.html"), kLSRolesAll, newDefaultStr);FSRef newDefaultBrowserFSRef;
LSFindApplicationForInfo(kLSUnknownCreator, newDefaultStr, NULL, &newDefaultBrowserFSRef, NULL);
_LSSetWeakBindingForType(kLSUnknownType, kLSUnknownCreator, CFSTR("xhtm"), kLSRolesAll, &newDefaultBrowserFSRef);
}@end
void Init_switch_browser(){}
In the SwitchBrowser directory everything is compiled with the following command:
gcc -o switch_browser.bundle -bundle -framework Foundation -framework ApplicationServices -framework AppKit SwitchBrowser.m
The RubyCocoa Part
I use RubyCocoa for the scripting part.
After installing it, create a file called ~/switch_browser.rb:
#!/usr/bin/env ruby
require 'osx/cocoa'
require File.dirname(__FILE__) + '/SwitchBrowser/switch_browser'new_browser = $*[0]
OSX.ns_import :SwitchBrowser
switcher = OSX::SwitchBrowser.alloc.init
browsers = switcher.browsers.collect{|b| b }unless new_browser
puts "Select browser number:"
browsers.each_with_index{|b,i| puts "#{i} #{b}"}
new_browser = browsers[gets.chomp!.to_i]
endraise "#{new_browser} is not a valid browser." unless browsers.include? new_browser
switcher.setDefaultBrowser(new_browser)
puts "Switched to " + new_browser
Now you can do:
~/switch_browser.rb org.mozilla.firefox
I've added this to my crontab together with quiting my work applications on the end of my workday.
It's been a real improvement!
Learning Erlang: Control Structures
06 Jul 2007 22:08 - (0) comments
So far, we haven’t seen any if statements, or switch statements or for statements, or while statements, and yet this doesn’t seem to matter. Everything is written using pattern-matching and higher order functions. So far we haven’t needed any additional control structures.
If we want additional control structures we have a power ful glue that we can use to make our own control structures....As you become more experienced, you’ll find that being able to create your own control structures can dramatically decrease the size of your programs and sometimes make them a lot clearer. This is because you can create exactly the right control structures that are needed to solve your problem, and you are not restricted by a small and fixed set of control structures that came with your programming language.
