New blog - blogging like a geek
April 7, 2009
Now I am blogging like a geek - with the article content residing in text files managed by git revision control software and HTML generation powered by a ruby software. My new blog is movabletype free.
jekyll was originally written by Tom Preston-Werner, a founder of github.com. I did some adjustments to the markdown handling so it better suites my DRY attitude. I think, I’ll further expand the software and probably merge it with git-wiki so it eventually leeds to a bliki.
Web design of the new site is currently more a kind of scientific style - without any bells and whistles, but I am going to change this soon.
The new blog is available at http://blog.geekq.net/
The old one is still available at http://www.innoq.com/blog/vd/
Things to do:
- copy the posts from the old blog
- enable comments
acts_as_state_machine successor 'workflow'
February 24, 2009 | Comments (0) | TrackBack (0)
While acts_as_state_machine was not maintained for some years, a couple of successor libraries sprang up. My favourite was workflow by Ryan Allen.
Unfortunately, after we had adopted it in our current project, we've found some undeterministic behaviour in the ActiveRecord integration area. So I've streamlined the integration code by:
- strictly separating the implementation between the state machine/workflow specification (states, transitions) and the model entity state
- putting all the model enhancements into modules and initiating the admixing the state machine functionality in the
self.included
method. The modules are::- WorkflowClassMethods
- WorkflowInstanceMethods
- ActiveRecordInstanceMethods
But you do not need to know all that implementation details to be able to use the workflow library. Just grab my version from github.
Rails internationalization - locale-selector released
January 2, 2009
Just released the first public version of the locale_selector
.
locale_selector is an internationalization library and provides a wrapper around the ruby-gettext gem.
You can install it simply by
gem install locale_selector
or see the complete installation instructions
Features:
- Offers a convinient way to specify the list of locales supported by your application.
- Provides a html UI control for locale selection.
- Maintains the user preference in a cookie and provides callback for saving the preference e.g. in a database.
- Offers rake tasks for maintaining the translations. The suggested translation maintenance workflow is really enterprise proven. E.g. updating single po-files according to the real world responsibility distribution.
Provides some fixes and improvements for the ruby-gettext library:
- better parsing for ActiveRecord models in some edge cases:
- namespaced classes
- multiple model classes per file
- and most important - fix for models, that are loaded in environment.rb due to e.g. referencing by a observer
- html escaping built into the underscore
_()
method - better customization for ActiveRecord validation methods - you can now avoid including the field name if you wish
The fixes will be eventually merged into and released with the next releases of ruby-gettext. But for the impatient - just install the locale_selector with the monkey patches.
You can also browse the source code.
Ruby: String vs. UTF-8
December 16, 2008
While debugging and fixing the hessian library I was reminded one more time about Ruby’s string support weakness.
The specification for hessian states:
… string encoded in UTF-8. Strings are encoded in chunks. ‘S’ represents the final chunk and ‘s’ represents any initial chunk. Each chunk has a 16-bit length value.
The length is the number of characters, which may be different than the number of bytes.
It is very easy to implement in most programming languages on most platforms. Why it is so hard and error prone in Ruby?
The originial implementation did not work:
[ 'S', val.length ].pack('an') << val.unpack('C*').pack('U*')
I’ve fixed this with the following:
length = val.unpack('U*').length
[ 'S', length ].pack('an') << val
It works but is not absolutely reliable (assumes the input is utf-8 encoded, but can not check this assumption) and is ugly. If the string is longer than 64K, then the implementation would be even more complex. There is no easy string slicing possibility in Ruby. And converting a long string to an array where each element is an object representing one letter will eat all your RAM!
Now how it should work:
('S', len(val), val.encode) # python
And for slicing use
val[ : :65000] # slice from the beginning to the end with step 65000
Can not we learn from Python? Has everybody to do his own mistakes? After 1.8 screw it up again in 1.9 and repair in Ruby 3000?
Python 3.0 released
December 6, 2008
Some are talking about a big break, but some of the mentioned things are simply a polishing for the implementation of known python principles.
Strings
Python has had a perfect way to represent chunks of written human language for ages.
In Python 2.6, 2.5, 2.4 the class was called 'Unicode'. The class for representing a byte sequence was called 'String'. Syntax for (unicode) string literals was also not very intuitive: u'hello'
.
In Python 3 names were changed and are perfect now:
str
for representing (unicode) strings- an apostrophe for (unicode) string literals
bytes
for an immutable sequence of bytesbytearray
for a mutable sequence
There should be only one, obvious way to do things
The obsolete ways, marked as such some point-versions ago, are removed in the current version. So if you strive to memorize the syntax of a programming language and the standard library, you've just gained some spare space in your brain and can have a look at the details.
Git-Wiki
September 24, 2008
I have finally found the wiki system of my dreams: git-wiki, originally written by Simon Rozet.
It is based on a git repository, that holds all the wiki content in text files (default - markdown syntax). So you can install it on a server in the internet, clone the repository to your notebook and change content either online or offline during the travel and then merge the content with normal git aids.
And you can use your favorite editor to edit the content.
It is implemented in Ruby with the light Sinatra web framework.
The code base of git-wiki consists of one file with about 300 lines - perfect starting point for your own implementation/fork. And thanks to git and github you can start hacking anytime. And I have already fixed the first bug that I found.
I am going to use two branches:
1.for conservative development where probably more people will pull my changes:
- bug fixes
- make the urls more restfull
2.for bigger extentions, that make more sence for me:
- support for the deeper folder structure so there is no restraint to put the text files in the root folder of the git repo
- referencing non-text files, e.g. images, binary files for download
- support for multiple instances
Browse Ruby documentation with improved gem server
July 21, 2008 | Comments (0)
I am currently using Netbeans as my Ruby IDE. The autocompletion feature provides some RDoc snippets but does not always work.
The second option is to use some web resources like http://ruby-doc.org/ or directly use google. But this obviously does not work offline and possibly provides the wrong version of the documentation for those living on the bleading edge. For example, I use the "nightly" RSpec version installing it directly from the git hub.
So I stuck to the local gem server. Unfortunately it's start page is not so convenient, so I've patched the rubygems/server.rb. You can append following near the end of file:
Continue reading "Browse Ruby documentation with improved gem server"
Cutting corners with xmpp4r-simple
July 3, 2008 | Comments (0) | TrackBack (0)
xmpp4r-simple aims to provide a wrapper around the powerful and well maintained xmpp4r library, "making it dead-simple to send and receive Jabber messages".
Unfortunately, the abstraction and simplification provided by xmpp4r-simple is leaky, missing the principles of jabber protocol. The result - the naive implementation (from the tutorial) did not work for me:
# Send a message to a friend, asking for authorization if necessary:
im = Jabber::Simple.new("[email protected]", "password")
im.deliver("[email protected]", "Hey there friend!")
Yes, I did replace the example.com
with the name of my server. ;-)
Result - response 406 "Not Acceptable"
Continue reading "Cutting corners with xmpp4r-simple"
JRuby ActiveRecord performance
June 11, 2008
In our current project we are loading pretty big amount of xml data into the database. The xml parsing is very fast because we are using the streaming flavor of REXML like this:
source = File.new(fp)
REXML::Document.parse_stream(source, ImportListener.new)
class ImportListener
def tag_start(name, attrs)
@tags.unshift name
@langs.unshift attrs['xml:lang']
@origin = extract_id(attrs['rdf:about']) if attrs['rdf:about']
relation_name = nil
case name
when 'rdf:Description' # Concept
@pref_label = ''
@definition = ''
...
def current_language
@langs.detect do |l|
!l.nil? && !l.empty?
end
end
def text(t)
case current_tag
when 'rdfs:label'
@label += t.strip
...
So the most time is consumed by ActiveRecord with stuff like find_or_create_by_xxx
. The whole import took 20 minutes / 14 minutes / 52 seconds (real / user /sys) with mysql running on the same machine. Hoped it would go faster with jruby time jruby -S rake xxxx:reimport
. I'm using jruby1.1.2 build from source (rev 6586) with jdbcmysql adapter. With jruby it takes 24 minutes / 18 minutes / 0:44 seconds - about 20% slower.
Rails-Konferenz
June 7, 2008
I am speaking at the German Rails conference on 10th of June 2008 about using Ruby on Rails for enterprise software. I will try to guide folks through the bleeding edge technologies like JRuby, REST and SOAP.
But wait a minute, REST is an exception, it is not bleeding edge, it is based on principles, protocols, libraries and products that work for decades now. Or am I revealing too much?..
Multiple Rails applications with mod_rails on Ubuntu
April 30, 2008
It works as advertised!
The installer provides exhaustive built-in documentation, describes every step and suggests solution for every unmet requirement like “please install Apache headers with apt-get install apache2-prefork-dev
”. Other guys and we all can learn a lot
from mod_rails about how a perfect installer looks like.
At the end of the installation process it asks to put three configuration lines into apache configuration file although it does not tell how. According to online documentation the requirement is that these lines should be only executed once.
So my solution (in Debian way) is to
- create new passenger.load file in /etc/apache2/mods-available
- create a symbolic link to it
a2enmod passenger
Continue reading "Multiple Rails applications with mod_rails on Ubuntu"
Create the most scalable HelloWorld application in the world with Google App Engine
April 16, 2008
If you have the luck to use the programming language and technology that Google uses, then you can use Google App Engine to host your web application and scale almost indefinitely.
Google App Engine is very different to Amazons’s approach.
- it serves code, so no virtual machines
- for web applications only (based on WSGI). WSGI is the de facto standard interface between a web server and a web application or framework in the Python world
- App Engine includes Python runtime (version 2.5.2)
- pure Python, no C extensions allowed
- includes non-relational data-store. Something that feels like tuple spaces?
- plus usual administration stuff
You can start the most scalable HelloWorld application in the world with the following lines:
from google.appengine.ext import webapp
class MyHandler(webapp.RequestHandler)
There will be nothing Google specific in the web part of your application. It is WSGI-based so you can host it at Google or within your own Apache HTTPD through mod_wsgi.
The bigger concern is this special data store, for which no open source replacement exist.
So you can not use a relational database with such distributed system like App Engine, but if you use this Google Datastore then you trapped into a dependency, that can not be removed easily. And introducing an additional abstraction layer for data access is not the way to success with a dynamic programming language, fast development and being happy.
Appearance matters
April 4, 2008 | Comments (0) | TrackBack (0)
No, I am not talking about preparation for a date or for an interview. I am still talking about a prototype I am working on. Even if you told that there is no need for special styling and a professional web designer will prepare something two weeks later, and the application should simply work, so it is possible to play around a bit with it.
And because you love the semantical nature of the html you start with a pure html with this scientifical styling. That means no styling at all. But even if you are not a professional designer, exactly like me, you should take one or two hours to create some basic stylesheet to make the user interface pretty less ugly.
- create a rails layout and a partial for the navigation
- put all the items into the menu (even if you are going only to implement one use case / function in your prototype), it will give the page some structure
- use the color schema of the customer Powerpoint presentation for your CSS
- adjust the
display
attribute for relevant elements
For example, if you want the main navigation to be shown in one row at the top of the screen and you have implemented the menu as unordered list <ul>
then put something like
ul.main_menu li {
display: inline;
background-color: orange;
padding: 4px;
font-weight: bold;
}
into your CSS file.
Rapid Prototyping with Rails
April 2, 2008 | Comments (0)
I am currently in Zürich and working on an extemely hot startup project there. The customer heard that with Rails you can prototype pretty fast…
I am working with two experienced Java- and J2EE- developer there, however they did not have any Ruby- or Rails- experience. So my task for this week is to create a prototype and at the same time to spread some Ruby but especially Rails knowledge among developers.
So after tree days:
- we have discussed the requiremnts and the problem domain with the project owner
- everybody has his devenv, mysql running
- new developers are confident in the usage of
rake
, scaffolding andscript/generate
in common, named routes and routing debugging - every developer created (and commited) his part of the model, along with rudimentary (adjusted scaffold-generated) user interface
- we have put some lookup-data into db data migrations
- we had an internal show and decided to make some changes on the workflow and the user interface
It is unbelievable, how much you can achive with learning/teaching Rails provided:
- people are open to the new concepts
- the motivation is high and there is a practical problem at hand
Wrong tradeoffs and hardware design
March 28, 2008 | Comments (0)
Some people know how to build parts of a computer together, know what makes up a good computer and what computer users really need. Some others do not. It is a pity, that responsible engineers at a major computer manufacturer belong to the latter category.
Lets have a look at my two and a half year old Thinkpad T43.
Continue reading "Wrong tradeoffs and hardware design"
From Ubuntu to Mac OS X and back in less than one week!
March 27, 2008 | Comments (0)
I have been using Ubuntu Linux as my primary OS for about one year now. The advantages are:
- on the desktop you use day for day the same tools you need on the server as
soon as you deploy your application
- tomcat, rails and glassfish are installed exactly the same way you will install it on the server later
- you get no culture shock if you have to use ssh, bash and vi on the server
- the system is highly customizable: you can completely redefine your keyboard including CapsLock and other modifier keys or do less important but funny things like making your keyboard light flashing when a new email arrives
- extremely easy installation of desktop, office or server applications, you are
always only one
sudo apt-get install program-name
away. Compare it to any Windows based 8 step installation wizard
However, there are some disadvantages regarding hardware support,
Continue reading "From Ubuntu to Mac OS X and back in less than one week!"
The weather
March 25, 2008
It has snowed for 5 days in a row. Pretty untypical for the end of march in the Lower Rhine area.
So the official season start at the local wind surfing club in two weeks has obviously to be postponed… I have a cold anyway :-(
Google Groups vs. HTTP as Application protocol
December 22, 2007
While advising customers regarding the use of RESTful Web Services I notice over and over again how powerful the HTTP protocol is and how rich the communication patterns described therein are. For example, if you wish to protect some resource with a user name and password you can simply use basic or digest authentication (as described in RFC 2616) If somebody or something (a user via a web browser or a feed aggregator or a different application in a B2B scenario) tries to access the resource without providing the credentials, he/it will receive '401 Unauthorized'. That means, that the request requires user authentication and the response contains a WWW-Authenticate header field containing a challenge applicable to the requested resource, so the client knows which authentication schema it has to use.
Now to the actual problem. At our company we have started using Google Groups for internal (not customer related) technical discussions. It is possible to setup a private discussion group at Google, that is only accessible to users, that are explicitly listed. And Google Groups provides an Atom feed containing recent group messages. So far so good. Unfortunately I was able to access the feed neither from my favorite web aggregator, nor from my Mozilla Thunderbird Feed Agent. After some debugging I've found why.
Continue reading "Google Groups vs. HTTP as Application protocol"
10 Reasons not to use Google Apps
September 16, 2007
Microsoft provided a list of 10 reasons not to use Google Apps.
Can not agree to most of them, even for enterprise. But I have my very personal list of problems with Google Apps, although I think all of them are solvable:
If you use a google apps account you can not use most of the google services, like web history or my places on google maps. It works, if you create a new google account with your google apps id as secondary email address. The concept of gmail account vs. google account is pretty tricky, so it took 4 posts for a google employee Steve to explain the point ;-).No IMAP access to mails. IMAP is the standard for accessing emails stored on the server. Standards are great for accessing stuff in, you know, the standard (uniform) way. I know, gmail web interface with its incredible full search capability and usability is really great. But for some special cases you really wish the standards:
- checking for the mails on your mobile phone even in sleep mode
- some sort of automatic processing of emails
- using non browser mail client uniformly for multiple accounts
Google apps uses completely different URL structure than gmail. So all the great gadgets and widgets, that make the integration with mail so pleasant, are not aware of it and do not work:
- Gmail for mobile application does not work
- the gmail widget of netvibes aggregator shows recent mails but the links do not work
- mail notifier in the google toolbar does not work
Besides that I am a big fan of google apps and looking forward for google to fix the problems. Eventually google apps should leave the beta phase.
The adoption for the enterprise in Europe could primary fail on google conspiracy considerations but it is another story…
Software release is like body building
June 29, 2007
If your are trying to make muscle gains, you eat more and do heavy lifting. But during this phase you are gaining fat as well. When bodybuilders prepare for the competition, they try to lose body fat to achieve better muscle definition. This “cutting” phase starts 3-4 months before competition. More tips and tricks from the guy I meet in the office daily (in German).
In a software project you have the requirement to develop new features while keeping the holy green build. This requirements are often contradictory in a bigger project (with 200 developers for example, like one I am currently working for).