Change character set of all MySQL tables
Yes, you did it again. Created new MySQL database on defaults, your automated database migration tool created tables on defaults and you end up with latin1_swedish everywhere.
Next time you will remember to execute
CREATE DATABASE new_db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
But since milk is already spilt you can save the day and convert your tables (and VARCHAR fields too) with one-line-saviour:
ALTER TABLE mytable CONVERT TO CHARACTER SET utf8
RESTful web services presentation
4Developers 2013 is over, and it was really great event - I'd say too great because it was technically impossible to listen to 12 presentations at once. The big plus was possibility to meet people you would not meet in normal circumstances: .NET developers, UX people, project managers and more. Unlike on typical Java event you could have taken fresh breath and listen to something completely different.
Responding to requests here is my slide deck:
- Roy Fielding's dissertation
- Leonard Richardson notes on maturity levels
If you are fan of JSON as data transfer format, you might be interested in
- Hypertext Application Language (HAL) - an attempt to introduce linking in JSON payloads
- Collection+JSON - like above, but trying to bring more standarization of collections, queries and more.
Books
There are couple of books that may be interesting reading.

Restful Web Services by Leonard Richardson

REST in Practice: Hypermedia and Systems Architecture by Jim Webber
Both of them provide in-depth course on RESTful web services, and there are mocked up example applications which are designed and developed through the book.
Mac Gems: easy PDF creation
One of the niceties of Mac OS X is great support for PDF documents out of the box. And it has been for very long time: PDF is just first class citizen in Mac's operating system.
One task that we may need to perform is to combine multiple JPEGs into one multi-page PDF file. In Windows world I'd start looking for software, hoping to find something free. In Mac OS X first thought leads to powerful, but a little obscure tool: Automator.
Apparently, this job is done by just a few clicks. Start with creating new workflow. Next, from PDFs category, choose "New PDF from images". Second click is to plug any source of files - I had mine in iPhoto, and quickly found "Ask for Photos" workflow step.
Last step is to just run the workflow, pick images from iPhoto and in a second, nice PDF is waiting on your desk(top).
This post is in Polish only, and tells about how to move around San Francisco using public transportation
Japoński off-topic
This is Polish only post about my participation in Japanese-village-blog-giveaway hosted by Polish blogger living in countryside Japan.
Pimp my Git
It is not hip anymore to use Git. Git went mainstream, and you should really watch out for suddenly appearing Gits.
Git has many faces, there is growing number of graphical clients, but command line interface is essential to master, and unfortunately not truly user friendly. Let's see what can be done. read more...
Server behind NAT not available in LAN
Personal note to remember, but it may be helpful for anyone.
Case: Linksys router with DD-WRT 2.4 software (which is most important part of the problem). Personal web- (or other) server connected to Internet via NAT. Port forwarding is configured.
Problem: apparently services are accessible only from Internet, not from local network.
Solution:
iptables -t nat -I POSTROUTING -o br0 -s 192.168.1.0/24 -d 192.168.1.0/24 -j MASQUERADE
Apparently adding missing rule to "nat" table solves the problem.
Dependency Injection is very well known tool in land of Boring Business Technologies like Java and .NET. Many benefits include promotion of modular architecture by loose coupling, easy escape from dreaded singleton pattern (in favor of simulated singleton pattern
. Dependency-injected code is also much easier to test. read more...
Gadu-Gadu scanning URL addresses
Apparently, Gadu-Gadu, most popular polish communicator is scanning URL addresses sent in chat window.
Environment independent WAR in Grails
Sometimes I like to break out of Grails convention of building separate WAR archives for each environment. I guess that typical Grails application is developed with development profile and when code is ready it is pushed straight to the production. Unfortunately, that is not the case in corporate environment
Common choice of environments I see everyday is development, integration, certification (or staging) and production. Possibilities are almost endless, and depend on creativity of your enterprise architects
Suppose we want adapt light web framework to heavyweight corporate standards:
Adding custom environment is simple. Open Config.groovy and add new section id Grails' DSL:
environments { production { grails.serverURL = "http://localhost:8080/${appName}" } staging { grails.serverURL = "http://localhost:8080/${appName}" } development { grails.serverURL = "http://localhost:8080/${appName}" } test { grails.serverURL = "http://localhost:8080/${appName}" } }
You can do exactly the same thing in DataSource.groovy and add database url for new enviroment:
environments { // ... integration { dataSource { dbCreate = "update" url = "jdbc:hsqldb:file:intDb;shutdown=true" } } }
Finallly, run grails application with usual command line option:
grails -Dgrails.env=integration run-app
or, even better, add this command line switch to your favorite servlet container environment options.
I want more
Adding custom environment with just another database setting is trivial use case. You may want to have additional per-environment configuration settings, different for each environment. For example, while developing eBay auction sniper, you would like to publish production like instance, but connecting to "sandbox" API. Thanks to Grails' flexibility it is plain simple. Go back to Config.groovy and add anything you with to environment blocks:
environments { production { grails.serverURL = "http://localhost:8080/${appName}" ebay.url = "http://open.api.ebay.com/" } staging { grails.serverURL = "http://localhost:8080/${appName}" ebay.url = "https://api.sandbox.ebay.com/" } development { grails.serverURL = "http://localhost:8080/${appName}" ebay.url = "https://api.sandbox.ebay.com/" } test { grails.serverURL = "http://localhost:8080/${appName}" ebay.url = "https://api.sandbox.ebay.com/" } }
You can access variables defined inside braces via ConfigurationHolder singleton:
ConfigurationHolder.config.ebay.url
Telling current configuration from code
You may want to show running environment name somewhere on page, to make sure application your testers are playing with is not connected to production ebay environment
Grails offers a way to obtain current running configuration:
Environment is actually enum type and getCurrent() returns value for current configuration. There is one catch: this is enum, so it lists only factory-defined configurations: PRODUCTION, DEVELOPMENT, TEST, and for everything else: CUSTOM. Casting this enum to string will effectively return "CUSTOM" for all custom configuration. However, if you make call like this one:
You will find that getCurrent() method is smart enough to alter CUSTOM enum's name property and set it to right value.
This is why people love Grails: it is simple, yet flexible. Have fun!


Polski
English




