Měsíc: Říjen 2005

Single controller application in Rails

Chcete si napsat malou MVC aplikaci s jedním controllerem v Ruby on Rails? Tady je kratičký návod.

Nejlepší je začít tím, že si přečtete něco málo about routing (nebo o routování, jak je libo). Funguje podobně jako mod_rewrite pro Apache, jen je trošku sofistikovanější, ale zhruba o pár tisícin vteřiny (na požadavek) pomalejší. Nicméně podle mého soudu nejschůdnější cesta v Ruby on Rails. Až to dočtete, nebudete potřebovat číst tento článek.

Vzhledem k tomu, že pořád čtete, asi tušíte co je single controller MVC application, ale ještě netušíte, jak zařídit routing. Pomůže Vám nahlédnutí do souboru config/routes.rb, ve kterém najdete něco jako:

Změňte poslední řádek, aby to všechno vypadalo nějak takto:

Pokud se Váš controller jmenuje jinak, než single, stačí záměna jmen. Všechny požadavky budou potom předány Vašemu single controlleru a zavolá se jeho příslušná akce.

Ruby on Rails sessions

Jste nováčci v Ruby on Rails a chcete se naučit ovládat stavy sezení (sessions)? O Ruby on Rails nikdo v češtině nepíše, takže jsem se rozhodl, že budu uveřejňovat své postřehy a tentokrát omezím porci své dost špatné angličtiny. Můj první postřeh je na téma session management.

Začnu tím, proč používat sessions. Protože jste chytří a vzdělaní, tak víte, že běžná webová aplikace je nestavová, tedy při přechodu z jedné stránky na druhou nelze jednoduše přenášet stavy aplikace. Abychom toto omezení obešli, potřebujeme mezi stránkami přenášet jedinečný identifikátor (unique identifier). V Ruby on Rails a mnoha dalších frameworks, je tento problém řešen pomocí cookies, ale pokud se cookies bojíte, můžeme to řešit třeba předáváním jedinečného identifikátoru v parametru URI (tomu se budeme věnovat zase někdy jindy). Tento článek popisuje, řešení pomocí cookies a integrovaného session managementu v Ruby on Rails.

Číst dále

Ruby on Rails low-cost webhosting

Do you like Ruby and it’s fresh full-stack web framework Ruby on Rails? Do you like web publishing and writing web applications? Do you need Ruby on Rails webhosting in Czech Republic?

I needed one too, but I haven’t found such a service. Fortunately I’m the happy owner of mid-range Intel server connected to the Internet backbone in Prague. Thus I’ve created new Ruby on Rails webhosting for people who want to play with Ruby on Rails and do not need high-end ultra mega expensive server, unlimited bandwidth and dual 24×7 support hot-line.

Ruby on Rails low-cost webhosting @ HQ.CZ

As I said, this is nothing seriously commercial, but my Ruby on Rails low-cost webhosting includes at least:

  • Intel P4 HT @ 2.5 GHz in the genuine Intel motherboard with 768 MB Kingston SDRAM and virtually unlimited disk space,
  • Fedora Core Linux 4 with the latest Ruby on Rails, Apache, MySQL and PostgreSQL stable packages,
  • bandwidth suitable for your needs,
  • FTP and SFTP access,
  • SCGI Rails runner ready environment,
  • pricing according to the server resources you want to use.

This basically does not include any phone support or service level agreement, because webhosting is not my primary job. I’m just offering a helping hand to Ruby on Rails newbies.

WordPress 1.5.2 patches for today

I’ve got inspiration in Arthur Dent‚s comment in another blog. Two guys’ve discussed trackback SPAM, which is also the huge problem for WordPress users and they usually solve this problem by completely closing trackbacks to their sites.

So my two few line patches for WordPress 1.5.2 (Strayhorn) are available for download. First patch solves the trackback problem in a smarter way and the second is related to another problem, which is connected to trackback posting.

Note that there is also more complex existing solution for preventing trackback SPAM called Trackback Validator Plugin.

Registered users only trackbacks patch

For people who want to live a simple life.

Download: http://hq.cz/sitedoc/patches/wordpress-1.5.2/regusers-trackbacks.zip

Site prefix patch

For those who want to use relative URLs in WordPress configuration, for example because they want to use both HTTP and HTTPS protocols.

Note: Option named siteprefix must exist in options table before applying this patch. Otherwise, it will do nothing.
Download: http://hq.cz/sitedoc/patches/wordpress-1.5.2/siteprefix.zip

Eye wrinkles

Do you prefer men or women with or without eye wrinkles?

I thought about it while studying methods of plastic surgery. Started with remembering eyes of all those girls I’ve ever loved. It’s neither small nor big number, somewhere in the middle … But, back to the problem. One of those girls had wrinkles, because she is five years older than me. Only one.

But now I’m five years older too, I have a daughter, and … no, don’t ask me if I have eye wrinkles or not … I naturally prefer women five years older. Will they all have eye wrinkles? Will I marry a woman having eye wrinkles?

Probably yes, but what? I feel happy facing this fact, because I remember one evening, when I was talking to one of my she-friends (no, she never was my girlfriend, if you want to know), sitting close to her at one table and looking to her eyes with … wrinkles. Tiny nice eye wrinkles, warning me that we are a little bit older than when we met for the first time.

And I feel happy remembering that evening, because I know that I can fully respect and love somebody having eye wrinkles. I still can’t say that I prefer women having eye wrinkles, but maybe I’m closer to it.

What about your friends? What about your wife or husband?

Note: This article is dedicated to my she-friend.

Nobel Peace Prize 2005

Nobel Peace Prize for 2005 is to be shared, in two equal parts, between the International Atomic Energy Agency and its Director General, Mohamed ElBaradei, for their efforts to prevent nuclear energy from being used for military purposes and to ensure that nuclear energy for peaceful purposes is used in the safest possible way.

Maybe a little bit surprising, but in my opinion, wise decision. It emphasized the power of nuclear energy in today’s world and the importance of it’s peaceful use. Hopefully our children will not fear.

Links: full press release

Is Petr Štefek also crazy as a loon?

I looked into my RSS feeder archive and I was surprised with one article appearing twice with the same timestamp:

Czech original:
2005-10-04 11:33 Já Petr Válek jsem magor z PCTuning.cz
2005-10-04 11:33 Já Petr Válek z PCTuning.cz

Translation 2 English:
2005-10-04 11:33 I, Petr Válek, am a loon from PCTuning.cz
2005-10-04 11:33 I, Petr Válek from PCTuning.cz

With the pagerank of originator’s blog there was absolute chance to get the words Petr, Válek and magor together as the first result of nearly any web search engine query.

Another man in the gun sight is Petr Štefek, who dug up the imaginary hatchet in comments and a pretty new private war glimpsed the light of the World. Hope it will be more fun, because his battle (current high-end NVIDIA vs. ATI cards) is already lost.

Question of the day: Is Petr Štefek also crazy as a loon?

Letinka: transmission interrupted

I crawled the web for a minute and found the message stating that Letinka takes a break to recharge her batteries.

For about a year, her web log was a place full of humanity and empathy, place where smart people posted their smart comments, the sequence of bits telling us that somewhere lives one real human being.

Oh, stop it, she’s not dead, only took a break. So let’s hope that her break will not take ages and wait for Letinka reloaded.