Category Archives: software

getting bundler, unicorn to play nice with a rails 2.3.x-app

We have a situation here:
– a rails 2.3.5 app
– unicorn must be used as deploy solution
– rack gems 1.1.0 AND 1.0.1 installed

unicorn_rails requires rack 1.1.0
after that somewhere in the rails app rack 1.0.1 is required

So we get an error like this: “can’t activate rack (~> 1.0.1, runtime) for [], already activated rack-1.1.0”

Our solution:
– use bundler:
– small modifications in the rails 2.3.x-files:
– configure and create the gem bundle
– start unicorn in the “bundler context” like this:
/usr/local/bin/bundle exec “/usr/local/bin/unicorn_rails -c config/unicorn.rb -E production”

typo3 layered menu bug update

Regarding Torben Hansen said today:

“Since 0012376 got into the CORE (TYPO3 4.4.5), the TMENU_LAYERS of one of my TYPO3 sites don´t work anymore. I get exactly the same error (Too much recursion) as described in this bugreport. The menu-DIVs do not have unique IDs, which leads to this error.

The Bugfix in 0012376 works fine with menus having one sublevel. If you have 4 sublevels, it does not work correctly, since “substr(md5(‘gl’ . serialize($this->mconf)), 0, 6)” does not produce unique results.

The approach from this bugreport using PHP uniqid works great and every menu has its unique ID.

So maybe the “uniqid-solution” – suggested by us – will be taken into consideration for future releases ….

typo3: remove htmlspecialchars in header

If you have a content element in typo3 with a header value containing “special chars” like romanian “diacritics” the header will be rendered like sh… – because the “special chars” are transformed using the &#xxx;-syntax, after which the & is transformed into &. The result looks like: &#xxx;

To get rid of this write in the setup part of your template:
lib.stdheader.10.setCurrent.htmlSpecialChars = 0

truncate typo3 indexed search tables for multiple typo3 sites

On a shared host we have some typo3-based sites where we use indexed search.

The table index_rel grows very fast, having over 6.000.000 entries. Even a simple search takes over 30 seconds to complete.
I searched for an elegant solution with very little success.

Here is a brute force solution: a ruby-script that search for databases that have a index_rel-table, truncates the “indexed search tables” if they reach a given size. The table will be automatically refilled every time a page is accessed, even by bots….

The script truncates the “cache tables” also, the “indexed search tables” will not be rebuild if only the cache for a given page is returned by a request.

If you do not have a single user that has access to all the databases, you should configure usernames/passwords per database.

th_mailformplus voodoo with allowedReferers and email_redirect

We maintain a typo3-site which is available under several domains – since it’s not our server we do not 100% understand the network/domain forwarding, etc… arhitecture there. It seems relatively voodoo to me

However we installed the th_mailformplus for a real simple form.

If called from one domain – it worked perfectly and after successfully sending the email we were forwarded to the “thank you”-page we specified(email_redirect-pageID).

If called from the other domain – the mail was not sent and instead of being redirected correctly the TEMPLATE_SUBMITTED_OK-subpart of the template was rendered. I repeat: the TEMPLATE_SUBMITTED_OK-subpart. Once again TEMPLATE_SUBMITTED_OK contains SUBMITTED_OK … subitted ok – yeah right. Pretty stupid behaviour in my opinion…

The solution was simple, add both domains to the allowedReferers. Now it’s working.

Programmatically getting a JavaScript list of current country names

I’ve been working on this great and challenging project for quite a bit now, concentrating on backend development at first,
in the last week or so I’ve moved on to the frontend. The link between the two places should, of course, be a Login / Register
part. I’ve handled login thus far and went on towards registration. Andreas said that a field entailing the user’s country should
be present there as well, albeit in an optional form.

My first reaction was “Oh, I’ll just add a normal select and that’s that” — upon second thought though I winded up choosing the
commonly used UX pattern of Autocomplete . However, in this case, local autocomplete is the name of the game, it makes no
sense to issue AJAX requests all over the place, knowing that a current list of country names should be publicly available.

The quest for this semi-elusive publicly available list of country names was on, and after googling around I’ve found a suitable
site, (listed here in German since we are primarily a German-speaking team).
Please notice that it’s table-based and, “programmer-unfriendly” — no API, no “Copy to Clipboard”, anything.

Having implemented some web scraping for other projects, I thought I’ll just write a Rails method for scraping the site, yet another
interesting solution came up : inject jQuery and manually output a JavaScript Array ! We are indeed “web programmers”, so
why not, should be fun, right ?

Load up the site listed below, your trusty Firebug (or “Inspect Element Tool Thingy” for Chrome / Safari) and check out the code

That would be it, I’ve found another site listing country codes but its table-based (!) structure
was a bit less intuitive (to be read “painful to programmatically read even via jQuery”).

I hope this can help someone at some point :-).

Said and done, thank you for reading up to this point, here is the code :

// Gets Country Names from the ForeignWorld website,
// . May break,
// depending on changes to the layout. Can produce output in other
// languages as well, see on-site links above. Found it quite annoying
// that no API whatsoever was provided so built a quick one myself.

// Relies on appending jQuery and then traversing the DOM to
// get the desired names. Should work for all the languages listed
// within the website.

// Available with Firebug / Safari + Chrome Inspector, perhaps
// Opera Dragonfly as well.

// Wait for jQuery to Load before executing the second part of
// the script. You have to clear out the last comma before
// using the array, was a bit lazy to add that as well.

var out = "[";
jQuery.each(jQuery("tr"), function(idx, elem)
  var x = jQuery(elem);
  var y = x.children().nextUntil(".center"); 

  if (y.length)
    var z = y.children("a[target='new']");
    var countryName = z.html();
    if ( (z != null) && (countryName != null) )
      out += "\"" + countryName.trim() + "\"" + ",";

out += "]";