Warning: Declaration of LJXP_Walker_Category_Checklist::start_lvl(&$output, $depth, $args) should be compatible with Walker::start_lvl(&$output, $depth = 0, $args = Array) in /home/victorsergienko/victorsergienko.com/wp-content/plugins/lj-xp/lj-xp-options.php on line 796

Warning: Declaration of LJXP_Walker_Category_Checklist::end_lvl(&$output, $depth, $args) should be compatible with Walker::end_lvl(&$output, $depth = 0, $args = Array) in /home/victorsergienko/victorsergienko.com/wp-content/plugins/lj-xp/lj-xp-options.php on line 796

Warning: Declaration of LJXP_Walker_Category_Checklist::start_el(&$output, $category, $depth, $args) should be compatible with Walker::start_el(&$output, $object, $depth = 0, $args = Array, $current_object_id = 0) in /home/victorsergienko/victorsergienko.com/wp-content/plugins/lj-xp/lj-xp-options.php on line 796

Warning: Declaration of LJXP_Walker_Category_Checklist::end_el(&$output, $category, $depth, $args) should be compatible with Walker::end_el(&$output, $object, $depth = 0, $args = Array) in /home/victorsergienko/victorsergienko.com/wp-content/plugins/lj-xp/lj-xp-options.php on line 796

Warning: Cannot modify header information - headers already sent by (output started at /home/victorsergienko/victorsergienko.com/wp-content/plugins/lj-xp/lj-xp-options.php:796) in /home/victorsergienko/victorsergienko.com/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 60
code name / Programming: Java, Groovy, C++, .NET, OOD, a little this and that
Skip to content

Documenting Python REST API whining


A downside of Python dynamic nature is that REST API documentation won’t generate right out of your code, like Swagger does for Java.
The best you can get is http://pythonhosted.org/sphinxcontrib-httpdomain/, for which you need to duplicate all of your REST service method signatures in ReStructured text, a format I’m not a fan of.
One can get a pretty-formatted Twitter-Bootstrap-enabled doc for Eve REST framework. But I’m not using Eve, and one has to duplicate service methods API in a Cerberus schema description.

Fast Windows JSON pretty-printer


Just built a Win32 version of yajl, a comandline C JSON pretty-printer and validator. Viva CMake.
Welcome to downoad.

The dead end of Russian software engineer?


Ex-USSR has got a great school of engineers. Russia is the 3rd software outsourcing country (market) in the world.
Russian (let’s use the name, though I’m Ukrainian, for instance) engineers are very educated and think out of the box.

We got OOP gurus, Java buddhas, UI Picassos, Haskell Lamas, agile addicts and tech team management professionals. Even some good business analysts.

This leads them nowhere. Most of them don’t have a decent area to apply their superior skills.

Getting Glassfish stdout logging under control


By default, Glassfish does an ugly thing: takes an application’s stdout/stderr and wraps it into its own log with INFO level for stdout and WARN level for stderr.
Other logging facility normally log to stdout.
In the end, a log entry looks pretty stupidly (and it’s damn multiline!):

[#|2012-11-21T11:25:07.225+0200|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=100;_ThreadName=Thread-2;|11:25:07.225 [http-thread-pool-8080(2)] DEBUG c.mycompany.packages.SomeClass - Finally, some useful text!

One can replace a Glassfish logging server-wide.
There’s a logging.properties file in the root of Glassfish domain, it has a “handlers” property that one can swap for Logback’s handler.
Of course, this requires adding Logback JUL bridge to Glassfish classpath.

Rendering QR codes to SVG


Had a hard time rendering a QR-code to SVG. Drawing simple rect-s didn’t work well, visible gaps appeared between bars.

I looked for a SVG QR renderer, but apparently neither zxing nor other libraries have a gapless algorithm. There is an online renderer by Kerem Erkan that uses path tag, but the author is apparently not intending to publish the code.

The closest algorithm that CAN be used to render a QR code as a whole path is marching squares, with a usable implementation here. Still there’s a lot to be done in order to render a whole path, mostly hole detection.

Luckily, it was enough to group the rect-s together with a g tag.

Now on free CDN


Thanks to Dreamhost, now running on CloudFlare CDN.
WP Super Cache happily supports it.

BTW CloudFlare got a free plan, and it’s easy to set up so that it doesn’t interfere:

  • Add a cdn subdomain to your hosting;
  • Add your domain to CloudFlare;
  • On CloudFlare, disable CDN for all subdomains except for cdn.
  • Set up your site to serve static content from cdn.*. Do it by hand, by mod_rewrite or whatever — I am using WordPress “WP Super Cache” plugin here.

Got a StackOverflow careers invitation.


They do a pretty cool thing: force you to tell “the truth” — no matter how subjective this term is — as opposed to emasculated official style:

  • what you really did (whatever it means to you);
  • what opensource/published projects did you participate in;
  • Top Stack questions you answered;
  • your professional reading and (sic!) writing.

Here I am: http://careers.stackoverflow.com/victors
(have to complete it still)

Got 5 invites btw.
Actually, just testing a new LiveJournal crosspost plugin.

Why I don’t like GMock


I don’t like GMock.

It’s not as if it was badly written or designed. But it lets you to unit-test dirtier code, tying to method call structure instead of resulting data.

For instance, this GMock code can be rewritten:

Groovy Comparator for class field names


I wonder why this was not in JDK/Groovy Collections.

Just put together a Comparator for StackOverflow question – a Groovy Comparator that would sort class field names in the declaration order. Feel free to use:

class PropComparator implements Comparator {
    private Class clazz
    PropComparator(Class clazz) { this.clazz = clazz }

    int compare(Object o1, Object o2) {
        clazz.declaredFields.findIndexOf{it.name == o1} 
          - clazz.declaredFields.findIndexOf{it.name == o2}

Couple of Grails tricks to remember: reload scaffolding and fieldValue formatting

  • Grails doesn’t reload scaffolding on-the-fly if you change local templates. But you can open a Groovy console inside application and run in it:
  • In order to change default g:fieldValue formatting for, say, BigDecimal, have a CustomEditorRegistrar in your resources.groovy, and register custom PropertyEditor:
    registry.registerCustomEditor(BigDecimal.class, 'myProperty',
        new OurBigDecimalEditor(BigDecimal.class))

DB2 supports LIMIT and OFFSET syntax, in MySQL compatibility layer…


It hasn’t even been a ten years that DB2, one of the most, er, expensive DBMSes, got a feature needed by every other application – dataset paging.

Before, you had to use window functions rownumber() and fetch first 40 rows only. When used by Hibernate, this resulted ugliness like:

select * from ( 
  select inner2_.*, rownumber() over(order by order of inner2_) as rownumber_ 
  from ( 
    select  ...
    fetch first 40 rows only
    ) as inner2_
  ) as inner1_ 
where rownumber_ > 20 
order by rownumber_

Since this summer version – DB2 9.7.2 – you can just append LIMIT and OFFSET: More…

Prim’s allgorithm in Groovy: inspired by Fortran and Java versions


A friend of mine defended Fortran against half-literate coders on an example of Prim’s allgorithm.

Good pretext for another language comparison. Let’s see Groovy vs Java vs good old Fortran.

Great Fortran implementation

Great Java implementation by Bruno R. Preiss, P.Eng. and scientist.

Some beginner’s C+ implementation (or is it just a link farm? Whatever).

And here’s the algorithm in Groovy, copied as precisely as possible from pseudocode in Russian Wikipedia article.