Grails’ withFormat block

Some things are not really different in Rails and Grails world. The pendant to Rails’ respond_to method is Grails withFormat block.

Both are supposed to render a different content type as requested according to the accept header and and the format parameter.

And both fail to some extend with Internet Explorer 5.5 to 7.0. For a longer explanation see my post on respond_to linked above. In short: First visit always gave me the an Excel File, all subsequent visits the intended html page.

I used nearly the exact solution within Grails 1.0.4 as in Rails:

withFormat {
      xls {
        // Same crap with IE 6/7 as with rails, compared to
        // http://info.michael-simons.eu/2007/08/06/rails-respond_to-method/
        if(params.format == 'xls') {
          def df = new SimpleDateFormat("yyyy-MM-dd")
 
          def report = ExcelReport.findById(params.reportId)          
          if(report == null)
            report = ExcelReport.findByBezeichnung('Absatzprognose')          
 
          response.contentType = 'application/vnd.ms-excel'
			    response.setHeader("content-disposition", "attachment;filename=some_filenname.xls")
          excelService.runExcelReport(
            report.bezeichnung,
            "some_parameter",
            response.outputStream
          )
          return
        }
      }
    }

Grails 1.1 seems to have fixed some issues on this case and a default or empty html {} block in front of any other format like so will do the trick:

withFormat {
      html {
        // depending on your needs
      }
      xls {
        // funny excel stuff
      }
    }

| Comments (0) »

23-Mar-09


Wütend

Oh man, ich bin so verdammt wütend, ein Tweet reicht nicht aus.

Es ist so zum kotzen, dass es Programmiersprachen wie PHP den Leuten so leicht machen, hübsche Sachen zu programmieren, die auseinander fallen, wenn man sie mal schief anschaut.

“Hübsche Gui” und “Ich weiß, was ich da gerade in die Datenbank schreibe” sind zwei Paar Schuhe.

Wie kann man eigentlich eine Checksum Routine so implementieren, dass sie auf unterschiedlichen Architekturen unterschiedliche Ergebnisse liefert? Braucht es da mehr als einen mittelmässig begabten Affen, zu erkennen, dass das eine scheiß Idee ist? Und noch spannender ist es natürlich dann, diese Funktion auch zu nutzen.

Boah echt ey.

Leute, lasst die Finger von PHPs crc32() Implementierung oder benutzt sie richtig.

| Comments (0) »

25-Feb-09


Frustration

if you want something done right, do it yourself

If you happen to use the mint tracking tool like me, be careful when migrating from a 32bit to a 64bit server or vice versa. Mint saves ip addresses and a buttload of checksums as signed long values. That bites you right in the ass when the first visitors starts arriving at your site. All from 127.255.255.255, or at last visitors with an ip starting with > 127.

If you read this post before migrating, just add the following to your migration:

ALTER TABLE mint_visit 
  MODIFY COLUMN `ip_long` BIGINT NOT NULL,
  MODIFY COLUMN `referer_checksum` BIGINT NOT NULL,
  MODIFY COLUMN `domain_checksum` BIGINT NOT NULL,
  MODIFY COLUMN `resource_checksum` BIGINT NOT NULL,
  MODIFY COLUMN `session_checksum` BIGINT NOT NULL;
 
ALTER TABLE mint_debugger   
  MODIFY COLUMN `ip_long` BIGINT NOT NULL;
 
ALTER TABLE mint_geo  
  MODIFY COLUMN `ip` BIGINT NOT NULL;
 
ALTER TABLE mint_hostnames  
  MODIFY COLUMN `ip_long` BIGINT NOT NULL;

and you’re done.

If it’s too late, change your tables as well. You then also have to delete your entire mint_visit data, as the records are already corrupted. Great fail.

However, why on earth store an ip address as a long value?!? It’s an ip address and if i want to look at it, the program needs to go the other way round. To me: It’s just stupid fucking with datatypes and problems as that is what you get if you do so. It maybe makes sense for computation of networks, but not for a statistic tool. At least, i don’t see any sense in this.

Actually, the problem is known.

| Comments (1) »

25-Feb-09


Phusion Passenger and memcached / memcache-client

I recently switch from a mod_proxy / thin setup to Phusion Passenger and my application started to do the funniest things and the production.log was full with errors related to memcached.

It seems, that passengers spawn method “smart” isn’t compatible with memcached. Within seconds on a lightly loaded server the cache gets corrupted big time.

I got better results with a newer memcache client (the ruby gem actually), but for that i need to remove the client from the rails vendor lib. Furthermore, under higher load there still where errors.

Only solution is to set the spawn method to conservative like so

RailsSpawnMethod conservative

Problem seems to be known in the Phusion and Rails teams.

| Comments (1) »

23-Feb-09


Comments are evil?

What can cause this snippet to fail:

<% if !@day.user.is_rateable?  # Workaround für Darstellungsfehler mit Tabellen ohne Bodies im Safari  %>
<!-- blah -->
<% end %>

This little snippet fell apart today. I don’t know if it is passenger, a newer ruby version, RubyInline. All i know is that i am so totally pissed of this incredible amount of incompatible versions of just 3 modules that i literally feel like puking. What a hell of a day.

By the way, the thing that broke was the one-line comment right after the if.

| Comments (0) »

23-Feb-09