книга з патернів проектування від львівського розробника
http://designpatterns.andriybuday.com/
усі патерни описано дотепно та весело, читати можна (і навітьрекомендується) не зважаючи на приклади мовою С# (і відповідне неканонічне форматування коду)
середа, 15 лютого 2012 р.
вівторок, 14 лютого 2012 р.
calc median in mysql
Aloha! As you know, MySQL is a very poor rdbms, but cheap. There aren't a lot of build in functions, special for statistic processing...
But imagine, you need to calculate median. It seems very easy, isn't it? Well, I have bad news for you - Mysql doesn't have this aggregation function.
I've googled it and found several solutions, but all of them have a problems with performance and ugly plan... So, I created own stored procedure (inspired by comment to http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html)
CREATE PROCEDURE calcMedian(IN tbl CHAR(64), IN col CHAR(64))
BEGIN
DECLARE counter INT;
SET @counter:= 0;
SET @s1 = CONCAT('select floor(count(',col,')/2) into @counter from ',tbl);
prepare rowsCounterStmt from @s1;
execute rowsCounterStmt;
SET @s2 = CONCAT('select ',col,' from ',tbl,' order by ',col,' asc limit ',@counter,', 1' );
PREPARE stmt FROM @s2;
EXECUTE stmt;
END
Another way: you can use User defined function as explained here http://mysql-udf.sourceforge.net/. In fact, it's much more powerful solution, but it's not suitable for all of us
But imagine, you need to calculate median. It seems very easy, isn't it? Well, I have bad news for you - Mysql doesn't have this aggregation function.
I've googled it and found several solutions, but all of them have a problems with performance and ugly plan... So, I created own stored procedure (inspired by comment to http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html)
CREATE PROCEDURE calcMedian(IN tbl CHAR(64), IN col CHAR(64))
BEGIN
DECLARE counter INT;
SET @counter:= 0;
SET @s1 = CONCAT('select floor(count(',col,')/2) into @counter from ',tbl);
prepare rowsCounterStmt from @s1;
execute rowsCounterStmt;
SET @s2 = CONCAT('select ',col,' from ',tbl,' order by ',col,' asc limit ',@counter,', 1' );
PREPARE stmt FROM @s2;
EXECUTE stmt;
END
Another way: you can use User defined function as explained here http://mysql-udf.sourceforge.net/. In fact, it's much more powerful solution, but it's not suitable for all of us
пʼятниця, 10 лютого 2012 р.
funny trap : JUnit vs TestNG
I've found a funny trap just several minutes ago:) If you have strong background in JUnit and then you start coding in TestNG, you can fall in trouble with asserts.
In JUnit we have: assert(expected, actual)
In TestNG: assert(actual, expected)
So, be careful!
In JUnit we have: assert(expected, actual)
In TestNG: assert(actual, expected)
So, be careful!
понеділок, 16 січня 2012 р.
use runtime data in soapUI
If you are using SoapUI for web-service testing, you can want to set up some data in the request in runtime (for example, for testing purposes).
The easiet way to set up date time in runtime is:
Also, you can get values from system setings or from special property file:
вівторок, 20 грудня 2011 р.
Poperly reading xs:date from xml
Actually, correctly read xs:date from XML isn't easy task.
Let's investigate how to do it whith famous JodaTime
There is built in formatter for xs:datetime:
However, there is not formatter for xs:date - hopefully we can build next custom formatter to handle this situation:
It works correcly in the most of cases, but according to standart, xs:date can have leading '-'. To hadle this situation, just add two more formatter with leading '-', and it'll work properly
Let's investigate how to do it whith famous JodaTime
There is built in formatter for xs:datetime:
ISODateTimeFormat.dateTimeParser()
However, there is not formatter for xs:date - hopefully we can build next custom formatter to handle this situation:
new DateTimeFormaterBuilder().append(null, new DateTimeParser[]{ DateTimeFormat.forPattern("yyyy'-'MM'-'ddZ").getParser(), DateTimeFormat.forPattern("yyyy'-'MM'-'dd").getParser() }).toFormatter()
It works correcly in the most of cases, but according to standart, xs:date can have leading '-'. To hadle this situation, just add two more formatter with leading '-', and it'll work properly
середа, 16 листопада 2011 р.
EclipseLink
Had a chance to work with EclipseLink. If you are using Oracle and don't ahve any plans to migrate to other DBMS or support several DB at one time, you have to choose EclipseLnk, because it's defently better than Hibernate fot your aims.
Awesome things, not available in Hibernate:
1) All queries are generated with Oracle hints - it's can be useful and seems realy cool:)
2) Hierarchy queries are already supported
3) Much less open bugs in EclipseLink project
Also, EclipseLink is etalone JPA implementation.
Also, I love SQL logginig in EclipseLink. It perfect and has binding by default, also it's much more readeble that hibernate log (about logging http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#How_To_Configure_Logging)
Awesome things, not available in Hibernate:
1) All queries are generated with Oracle hints - it's can be useful and seems realy cool:)
2) Hierarchy queries are already supported
3) Much less open bugs in EclipseLink project
Also, EclipseLink is etalone JPA implementation.
Also, I love SQL logginig in EclipseLink. It perfect and has binding by default, also it's much more readeble that hibernate log (about logging http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#How_To_Configure_Logging)
понеділок, 15 серпня 2011 р.
Atomic Java
Дуже корисна і цікава стаття про неблокуючі операції в джава, засновані на атоміках. Нарешті я побачив реальнокорисне використання атоіків, а не банальний код з лічильниками, яким зазвичай ілюструють цей функціонал.
Отже, в статті потокобезпечна черга та стек, в коді яких не було використано ані синхронізації, ані локів чи якихось мютексів:
http://codeidol.com/java/java-concurrency/Atomic-Variables-and-Nonblocking-Synchronization/Nonblocking-Algorithms/
PS особливого перфомансу слід чекати коли задіяно більше двох потоків
Отже, в статті потокобезпечна черга та стек, в коді яких не було використано ані синхронізації, ані локів чи якихось мютексів:
http://codeidol.com/java/java-concurrency/Atomic-Variables-and-Nonblocking-Synchronization/Nonblocking-Algorithms/
PS особливого перфомансу слід чекати коли задіяно більше двох потоків
Підписатися на:
Дописи (Atom)