Configuring QuickProxy FireFox plugin

16 Jul 2008 19:10 - comments turned off

While trying out Ratproxy I needed to use QuickProxy.
I couldn't find any configuration description, so here is what I did.
Go to: Preferences > Advanced > Network, and set HTTP Proxy to localhost and Port to 8080 for the default Ratproxy settings.
To turn QuickProxy on/off click the 'P' icon in the status bar.

Seam, a second look at JSF

10 Jul 2008 22:04 - (0) comments

I decided to have another look at JSF by reading the Tutorial. The last time I used JSF was 2 years ago (I thought it sucked then). Maybe it has improved with Seam.

Besides almost falling asleep from all the xml I did notice Seam supports Ruby style templating Strings(example 1.2), which is sort of nice.
I'm not sure if you can use simple java oneliners though.

A couple of things that suck:

- Validation of required fields in views (Example 1.7)

Username: <h:inputText value="#{user.username}" required="true"/>

- Session beans require an interface. Let's define everything twice!

- Displaying a simple date requires 120 chars (Example 1.12)

<h:outputText value="#{msg.datetime}"><f:convertDateTime type="both" dateStyle="medium" timeStyle="short"/></h:outputText>

- Configuration in the views and confusing prefixes.

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

- Removing duplication from views sucks because you can't extract methods.

I actually forgot how much JSF sucked (I remember it was hard to test).
The biggest problem is that it's been developed by someone who doesn't use it to write real applications.
It's full of crappy implementations of concepts that seem like a good idea from an ivory tower.

Here is a script that generates the same application in Rails(2.1), it's just a bit longer than just the web.xml from the seam example:

puts `rails seam`
Dir.chdir "seam"
open('config/database.yml', 'w') do |f|
f << %{development:
adapter: mysql
socket: /opt/local/var/run/mysql5/mysqld.sock
database: seam
username: dev
password: dev}
end
puts `rake db:create`

puts `script/generate model user username:string password:string name:string`
open('app/models/user.rb', 'w') do |f|
f << %{class User < ActiveRecord::Base
validates_length_of :password, :in => 5..15
validates_presence_of :name
validates_length_of :username, :in => 5..15
validates_uniqueness_of :username
end}
end

puts `script/generate controller Register`
open('app/controllers/register_controller.rb', 'w') do |f|
f << %{class RegisterController < ApplicationController
def index
@user = User.new(params[:user])
render :action => :registered if params[:user] && @user.save
end
end}
end

open('app/views/register/index.html.erb', 'w') do |f|
f << %{<html>
<head><title>Register New User</title></head>
<body>
<%= error_messages_for 'user' %>
<% form_for @user, :url => {:action => :index} do |f| %>
Username: <%= f.text_field :username %><br />
Real Name: <%= f.text_field :name %><br />
Password: <%= f.text_field :password %><br />
<%= submit_tag "Register" %>
<% end %>
</body></html>}
end

open('app/views/register/registered.html.erb', 'w') do |f|
f << %{<html>
<head><title>Successfully Registered New User</title></head>
<body>Welcome, <%= @user.name %>, you are successfully registered as <%= @user.username %>.</body>
</html>}
end

puts `rake db:migrate`

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 JavaSpecialist

def self.main
js = find_specialist_wanna_be
if js
js.start
else
puts "Geen JavaSpecialist implementatie gevonden"
end
end

def 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
end

private

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
end

def 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"
end

def 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

Admin