Skip to content
Jun 16 13

Change character set of all MySQL tables

by Tomek

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

  1. 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:

  1. ALTER TABLE mytable CONVERT TO CHARACTER SET utf8
Apr 19 13

RESTful web services presentation

by Tomek

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:

You may also want to see:

If you are fan of JSON as data transfer format, you might be interested in

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.

Oct 10 12

Mac Gems: easy PDF creation

by Tomek

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).

 

Aug 29 12

Komunikacja w San Francisco – jak się poruszać po mieście

by Tomek


This post is in Polish only, and tells about how to move around San Francisco using public transportation

Jul 5 12

Japoński off-topic

by Tomek



This is Polish only post about my participation in Japanese-village-blog-giveaway hosted by Polish blogger living in countryside Japan.

May 29 12

Pimp my Git

by Tomek

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...

May 20 12

Server behind NAT not available in LAN

by Tomek

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.

Feb 11 12

Syringe: iOS and OSX Dependency Injection framework

by Tomek

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...

Jan 30 12

Gadu-Gadu scanning URL addresses

by Tomek

Apparently, Gadu-Gadu, most popular polish communicator is scanning URL addresses sent in chat window.

Jul 21 11

Environment independent WAR in Grails

by Tomek

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:

  1. environments {
  2.     production {
  3.         grails.serverURL = "http://localhost:8080/${appName}"
  4.     }
  5.     staging {
  6.         grails.serverURL = "http://localhost:8080/${appName}"
  7.     }
  8.     development {
  9.         grails.serverURL = "http://localhost:8080/${appName}"
  10.     }
  11.     test {
  12.         grails.serverURL = "http://localhost:8080/${appName}"
  13.     }
  14. }

You can do exactly the same thing in DataSource.groovy and add database url for new enviroment:

  1. environments {
  2. // ...
  3.  
  4. integration {
  5. dataSource {
  6. dbCreate = "update"
  7. url = "jdbc:hsqldb:file:intDb;shutdown=true"
  8. }
  9.  
  10. }
  11. }

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:

  1. environments {
  2.     production {
  3.         grails.serverURL = "http://localhost:8080/${appName}"
  4.         ebay.url = "http://open.api.ebay.com/"
  5.     }
  6.     staging {
  7.         grails.serverURL = "http://localhost:8080/${appName}"
  8.         ebay.url = "https://api.sandbox.ebay.com/"
  9.     }
  10.     development {
  11.         grails.serverURL = "http://localhost:8080/${appName}"
  12.         ebay.url = "https://api.sandbox.ebay.com/"
  13.     }
  14.     test {
  15.         grails.serverURL = "http://localhost:8080/${appName}"
  16. ebay.url = "https://api.sandbox.ebay.com/"
  17.     }
  18. }

You can access variables defined inside braces via ConfigurationHolder singleton:

  1. 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:

  1. Environment.getCurrent()

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:

  1. Environment.getCurrent().getName()

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!