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.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:
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!
Phocus! iPhone app update
Caution: if you are not a photographer, or your understanding of photography is taking pictures of kids or girlfriend with compact or phone camera - don't worry text below is beyond of your understanding.
I'm happy to annouce update of my little Phocus! app. Version 1.1 brings a cool new feature: calculating optimal aperture and focus point to achieve given depth of field. Everything else (including delicious UI
is left unchanged.
Remove untracked files in Mercurial
It happens after wild act of creation that we notice we went wrong way. Quick decision is made: "go back and start over". With VCS it is plain simple, just type hg revert and you're at home. Almost. Unsurprisingly, hg revert reverts only modifications and leaves new files intact.
There is simple solution for that: and there's again nice, but obscure feature that is included in the box, but just not activated. Let's edit the .hgrc in your home directory, and make sure there is something like this:
[extensions] purge =
and once it is, just type
hg purge
to send unwanted files to /dev/null.
For some time one small thing bothered me in TextMate: extremely weird behaviour of PageUp and PageDown. Basically it was not deterministic
Quick googling pointed me to the solution, the guilty one is Apple's smooth scrolling feature, which, thankfully, is easy to disable in TextMate while leaving it active for other apps.
Just key in a magical command:
defaults write com.macromates.textmate AppleScrollAnimationEnabled -bool NO
And scrolling is back sraight!
[via http://lists.macromates.com/textmate/2011-January/032098.html]
Have a CIDR
Java developers are constantly being indulged by state of the art development tools. Even free tools provide tools that dramatically increase productivity, and if you are willing to spend some $$$, you can get even more. JetBrains annouced their plans to develop IDE for Objective-C, and now, wait is over.
It's still an EAP, but it is quite impressive. It fills the gaps in places I missed so much: refactoring, quick fixes, and on-the-fly code analysis. I played with it just a little, but definitely:
- rename works
- extract method works
- change method signature works
- @class and #import is added automatically when class is used
- you can generate ivars and @properties
and many more. Great job, JetBrains!
I only wish Apple not making some stupid decision about banning or blocking other IDEs. I hope I'm paranoid in that case.
Easy JSON pretty-print
It turns out that pretty-printing any give JSON data is dead simple if you have Python by hand. On decent OSes you get Python interpreter right out-of-the box. For the less decent ones, you can download distribution. Once you got it, just filter it through simple python interpretter invocation, like:
echo '{ "Japko.net" : "Rulez" }' | python -mjson.tool
Add some color to Mercurial
I do use command line regularly, especially on OSes which command line does not suck (read OS X, Linux and friends). By default, Mercurial looks a bit boring, but by just adding a few lines to configuration file, Mercurial may explode with colors. Let's open .hgrc with our favorite editor:
vim ~/.hgrc
And add some magical lines:
[extensions]
color =
highlight =
graphlog =
color and highlight enable colored output of diff and stat. graphlog adds new command, glog, which will just try to draw revision graph using ASCII-art alongside with normal log output. There's a lot of extensions to be discovered, I just started with bringing some life to dull default interface.
No calendar API on Android?
So much is spoken about Android's "openess" versus iPhone being close, proprietrary and very bad at all. And "open" is not always the same "open" you may think of. Today I've come to surprising discovery: there is no API to access calendar in Android SDK. What? Even iOS has this (well... right, it was added in iOS 4.0). Of course you can access cloud-based Google Calendar Data. Anyway, Google is not a charity. They do want you to work in cloud and have good reason for that.



Polski
English




