We have several datacenters some of which may be located pretty far away from each other. In all of them there are several tables which are going to be populated on the leaf DBs and then the resulting rows will have to be moved to a central database. This means that we need here some kind of globally unique id generation mechanism between distant applications. Another problem is that there’s also the requirement that some of the rows in those synchronized tables may be inserted from other locations outside of my Java app’s scope. These rows would not be able to use Hibernate’s UUID generation strategy, instead IDs for these rows should be generated inside the database.
If you’re using Oracle database with java that usually means that you’re also using Hibernate as an ORM. If you do, then it’s always a good idea to generate your IDs in java and specify them when inserting new rows. You can do this in hibernate quite easily by specifying the ID generation strategy. Hibernate needs to know the ID of the inserted row for it’s internals to work correctly, that’s why if you use the inside-Orace ID generation then for each row there’s going to be a round trip for hibernate to actually find out what ID was assigned to the newly inserted row. This is definitely the case when you have UUID ( or GUID in Oracle terminology) as your PK (this is probably not the case if you’re using sequences cause the sequence allows hibernate to allocate large chunks of IDs and use them for the inserts). Hibernate offers 2 UUID generation strategies(uuid and uuid2) so a natural question arose, which one to choose?
Read more…
What happened to me a couple of days back was that I discovered that one of my mysql dumps done with mysql’s own mysqldump utility has all texts in utf8 corrupted. Everything looked like this: ╘┐╒Ñ╒╢╒┐╓Ç╒╕╒╢╒í╒»╒í╒╢ ╒ú╓Ç╒í╒╜╒Ñ╒╢╒╡╒í╒» and this: ╘╗╒╢╒Ñ╒»╒╕╒ó╒í╒╢╒»╒╕╓é╒┤. The original text was in Armenian.
The cause of all this beauty was my mistake. I shouldn’t have used piping when dumping the database in the powershell on my windows 7 machine. To avoid this kind of stuff in the future always use mysqldump’s -r flag when dumping the database. That way mysqldump opens the dump file and writes everything in it directly. If you don’t use the -r flag the dumped data will be first passed to your console program where it may be converted to some weird alien encoding and only after that it will be written to the file which the console program will create. In my case here all utf8 characters got converted into 2 characters. I don’t exactly know how this happened but each utf8 Armenian character is 2 bytes so to me it looks like powershell converted each character into 2 ascii ones. Read more…
Let’s be honest, RMI is a great thing to use, but it’s still kind of raw, and has some drawbacks:
- Disconnections: There’s no centralized and convenient approach to handle disconnections, reconnections and all that network stuff, if something dies – you have a lot of things to do.
- The “remote” syndrome: In order to be usable via RMI, everything should be remote. When somebody writes a service interface, he’s not usually foreseeing that the thing will be exposed by RMI someday and vice versa – Remote objects are kind of weird when used only locally.
- Sexual relationships: You have to deal with artificial entities like skeletons and stubs, compile them, place in your classpath etc.
- Try/catch cumbersomeness: Every single call requires a try/catch block, or a corresponding something to avoid it, sometimes we don’t really need anything of the kind.
You can use TRMI to avoid the above mentioned sruff. TRMI uses Java’s proxy and reflections to achieve it’s goals. It was developed by an Israeli guy named Guy Gur-Ari of whom I am thankful, and the reason this article is being written by me.
Read more…
This is a really small article and i’m not yet sure if i’m going to write many of these in the future. But lets get to the point itself
I got “Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause” error when creating a table as shown bellow with SQLyog probably the best MySql GUI available at the moment
CREATE TABLE classroom (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`modifyDate` TIMESTAMP ,
`createDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
)
this error is fixed by adding “NULL DEFAULT NULL” to the modifyDate field as in the code bellow
CREATE TABLE classroom (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`modifyDate` TIMESTAMP NULL DEFAULT NULL,
`createDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
)
i’ve got 5.1.41 MySql and this is probably a bug, and i have no idea if it’s fixed in later builds
Okay . . . So this is one of the things i hate the most! And this hated moment of choice arises nearly every time you start doing something new. I really can’t say that i’m good at this but i know some guidelines you should follow when choosing a domain name and some ways to help you to come up with something sane & proper. So lets start with the guidelines.
Read more…
Keep in mind that if you just want to address some URL in a short way then you don’t really need to read this article. You just have to use one of the multitude of services which provide URL mapping to tiny, generated URLs. Some of those services are: http://tinyurl.com/, http://u.nu/, http://bit.ly/. Just use the one you find the sexiest
What i needed was a way to make URLs on my website as short as possible. I had a huge list of numbered entries each of which had it’s own unique ID and a URL looking like this: mywebsite.com/entries/789465479916 . The best way of making the last number part of the URL as short as possible i found is converting the huge decimal number to the base of 62. Why 62? Because we’ve got 62 alphanumerical symbols there (0-9a-zA-Z) !
The first thing i found after some googling is that php actually provides a function named base_convert() which does what i want. BUT! It doesn’t support base of 62 and really huge numbers. A little disappointed i left this function be and resumed my search of the ideal solution!
In the comments of base_convert() i found a wonderful comment doing nearly exactly what i want. The only bad thing about it was that it didn’t support bug numbers. So i modified the code to use the bcmath php extension which provides support of huge number calculations. Bellow is the modified code.
Read more…
Categories: IT, Math & Algorithms, PHP Tags: algorithms, base converting, bcmath, big numbers, huge numbers, numbers, PHP, short urls, tiny urls
If you’re a real geek, you might want to make an ssh client… using php, well, this is something that no one will probably ever need to do… but if you’re reading this, maybe it happens so that you need it
So, to start with, there is a php extension called libssh2, and it’s really tricky to install it on some server configurations. I’m not going to discuss that part here because it’s purely server administration issue. I will just get to the coding part.
What we want to do here is to create php script that would run from console, will connect to remote ssh server, execute commands, and display output just like every ssh client does. The first problem is – libssh2 documentation on php site really sucks.
Read more…

What if you already use some library that occupies the $ variable and you want to continue using it and jQuery together. What happens in this case if you load jQuery is that it will override the variable to jQuery object and you won’t be able to use your existing library. Possible solutions of this are:
- Reassign jQuery from $ to something like $jq.
- Include jQuery first and after it the other library. After this instead of typing $ you will have to type jQuery. Example: jQuery(‘#mydivId’);
- You can also use the jQuery.noConflict() method to revert the $ to the value it had before jQuery was included in the page.
Read more…
Well, after using jQuery inline form validation plugin for some time the most serious problem with it was that it didn’t allow me to freely customize my UI. If i had a defined design of a form before writing the validation part I always had to alter design so that validation bubbles don’t pop onto something important. Like a “Invalid CAPTCHA code!” poping up on the CAPTCHA image or other stuff like this. Check-boxes are also easy “eaten” by the validation bubbles.
What i’ve written is a simple patch for jQuery inline form validation plugin allowing custom positioning of the validation bubbles. It gives you the possibility to override the default positioning by adding promptPosition attribute to the validated element with a value of any possible positioning pattern supported by the plugin (topLeft, topRight, bottomLeft, centerRight, bottomRight). Read more…
Categories: Frameworks, IT, JavaScript, Useful Tools Tags: forms, inlive validation, javascript, JQuery, patch, plugin, prompt positioning, validation

jQuery Inline Form Validation Engine
Recently I’ve been surfing the net in search of a jQuery powered form validation plugin, the best of what I found is the jQuery Inline Form Validation Engine. On the left is a screenshot of plugin’s performance which i find quite good from both programming and design point of views. The screenshot is taken from plugin’s author’s website at http://www.position-absolute.com.
It’s quite easy to implement in your project and consists from just a couple of JS files one ( one of them contains error messages and validation rules and the other validation code itself). Also you have to include a single css file and that’s all. No images required at all.
You can easily add your own custom validation rules and tweak the stuff that’s already present in the code. Everything is pretty simple and requires a basic knowledge of JavaScript.
Read more…