08 јул 2014

SQL Fiddle

If you need fast try and error check against some of the most popular relational database management system SQL Fiddle is the wright address. It is also free as in beer :)

It is an online application in which you can select to work some of supported RDBMS.
There are 2 text area fields: first is used to set your schema and data, the second is used to write some query that will run against your schema and data.

Using SQL Fiddle you can share your script similar to Gist for source code sharing.

It is also useful as online SQL code beautifier and formatter.

Here is an example of SQL Code for Oracle DB: http://sqlfiddle.com/#!4/1897b/1

11 јун 2014

XMLUnit


XMLUnit for Java provides a set of supporting classes (e.g. Diff,  DetailedDiff, Transform, SimpleXpathEngine, Validator,NodeTest) that allow assertions to be made about:
  • The differences between two pieces of XML
  • The outcome of transforming a piece of XML using XSLT
  • The evaluation of an XPath expression on a piece of XML
  • The validity of a piece of XML
  • Individual nodes in a piece of XML that are exposed by DOM Traversal
XMLUnit for Java can also treat HTML content (even badly-formed HTML) as valid XML to allow these assertions to be made about the content of web pages too.

 

Experience


I've used XMLUnit in 2 situations: assert that 2 xml files are semantically the same regardless of structural differences (eg. different formatting, different namespace prefixes, usage of opening and closing tag vs. empty tag...) and finding real differences between two xml files regardless of prior mentioned differences in structure.

The equality of two xml files can be compared in two ways. We can check if two documents are identical. Two documents are considered to be "identical" if they contain the same elements and attributes in the same order. But we can check if two documents are similar, where those two documents must contain the same elements and attributes regardless of order. In most cases you will checking similarity and that is what is checked when XMLAssert.assertXMLEqual methdo is called.

Howto


There are only few classes that needs to be known. Not so complicated but not so easy when compared to ordinary Assert implementations (JUnit, TestNG or FEST).
XMLUnit class is used as a static configuration class. If there is need for some general configuration change (eg. to ignore whitespaces, to normalize text nodes, to ignore xml comments...) this is a place to do it before calling asserts. Also it is possible to change parsers and engines used by XMLUnit.

DifferenceEngine is comparing Nodes (just Nodes of type: ELEMENT_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_TYPE_NODE, PROCESSING_INSTRUCTION_NODE and TEXT_NODE) and when difference is found the responsibility gets delegated to DifferenceListener interface which implementation is the final judge if difference is significant. DifferenceEngine is not used directly but in some not so simple use cases difference listener should be set.
There are several implementations of DifferenceListener, most useful are Diff and DetailedDiff.

Diff is used for simple comparison where only the state of comparison is needed (identical, similar or different) and the comparison is halted as soon as the status is known with certainty.

If you need o collect all the differences and have all details DetaildedDiff should be used. It is just a decorator for other DifferenceListeners.

MatchTracker interface gets notified when a match between test and actual node is found. It is useful to implement listener that logs matches so that you get insight of comparison process. This interface has no implementation.

ElementQualifier Interface used by the DifferenceEngine to determine which elements can be compared within a NodeList of child nodes. It controls which two nodes from test and actual XML document should be compared.

There are few implementations of this interface: ElementNameQualifier which is default, compares element nodes whose tag name is same. ElementNameAndAttributeQualifier uses tag name and attribute, ElementNameAndTextQualifier uses tag name and text content, RecursiveElementNameAndTextQualifier compares all Element and Text nodes in two pieces of XML. Allows elements of complex, deeply nested types that are returned in different orders but have the same content to be recognized as comparable. 

Every single compare is done using ElementNameQualifier. I had a special case where I needed recursive ElementQualifier but which compares single nodes not just by tag name but also by attributes. So I have tweaked RecursiveElementNameAndTextQualifier to be just a recursive decorator around existing ElementQualifier implementation.

Example


I've crated example at https://github.com/aurelije/xmlunit I had an use case where I needed to refactor one complex wsdl file. I wanted to sort all operations, types and messages, so I can easily compare that sorted Old API wsdl file with New API wsdl file and see what is changed and what is added. So I needed some proof that the original and sorted wsdl are semantically the same. And then I could also use this test to list all differences between Old API and New API wsdl.

References


17 новембар 2013

How to download multiple files using cURL

A few months ago I've bought Kobo Aura HD eBook reader. That is my best investment this year :) I am using every chance to read books, but also I am reading magazines that do have ePub format (PragProg, Libre!, FullCircle, BSDMag and Linux Magazine.

But I've had a problem to download all issues of some magazine. If download URL for particular issue can be guessed than cURL will do the job perfectly. As example here is a command to download all 78 issues of FullCircle:

curl http://dl.fullcirclemagazine.org/issue[1-78]_en.epub --create-dirs -o "/home/zlatan/Downloads/fullcircle/fullcirclemagazine#1.epub"

Particular url is http://dl.fullcirclemagazine.org/issueXX_en.epub where XX is issue number. The option o controls output, and because there are 78 files filename will be constructed from fullcircleXX.epub name where XX is corresponding issue number taken from URL

cUrl is free software that exists as package for almost all platforms. So Linux user can use their package manager to install cUrl (if packege is not installed already) and MS Windows users can downloaded it from: http://curl.haxx.se/download.html

Simillary  to download all epub versions of PCLinuxOS Magazine copy and paste the following line into terminal:

curl http://pclosmag.com/download-epub.php?f=[2012-2013][01-12]epub.epub --create-dirs -o "/home/zkadragic/Downloads/pclinuxos/pclinuxos#1-#2.epub"

10 фебруар 2013

How to install Lotus Notes 8.3 on Kubuntu 12.04

Installing Lotus Notes became easier than in previous versions and fortunately there is no need to edit .deb files anymore.
Follow these steps to install Lotus Notes (Kubuntu 12.04.1 32b):

  1. untar the installation: tar xvf lotus_notes853_linuxUb_en.tar
  2. run installer: sudo dpkg -i ibm-lotus-notess-8.5.3.i586.deb
  3. dpkg will throw missing dependencies, you should search and install all that dependencies using apt-get, aptitude or Muon package manager
  4. run: sudo dpkg -i ibm-lotus-notess-8.5.3.i586.deb again
  5. install other lotus notes parts: sametime, activities and so on using the same approach
  6. similarly untar and install fixpack
  7. install the wrapper:
mkdir -p /tmp/notesfix
cd /tmp/notesfix
 
wget –no-check-certificate https://github.com/sgh/lotus-notes_gtk2.23.3/raw/d3492c997bc7a92b895fa1369d4743a8e20b56b5/Makefile
 
wget –no-check-certificate https://github.com/sgh/lotus-notes_gtk2.23.3/raw/d3492c997bc7a92b895fa1369d4743a8e20b56b5/libnotesgtkfix.c
 
wget –no-check-certificate https://github.com/sgh/lotus-notes_gtk2.23.3/raw/d3492c997bc7a92b895fa1369d4743a8e20b56b5/notes-wrapper
 
make
chmod +x notes-wrapper
 
sudo cp notes-wrapper libnotesgtkfix.so /opt/ibm/lotus/notes/
The final step is to edit menu. Right click to Kickoff App Launcher -> Edit Application, find the Lotus Notes entry in Office menu, and put this line into command field:

sudo -u $USER env  GTK2_RC_FILES="/usr/share/themes/Raleigh/gtk-2.0/gtkrc" /opt/ibm/lotus/notes/framework/../notes-wrapper
Now you can "enjoy" your Lotus Notes :)

23 јун 2012

Pro Spring 3

Right now I am reading Pro Spring 3 written by Clarence Ho and Rob Harrop (a SpringSource co-founder). Very up to date book about Spring covering version 3.1. This book doesn't lack information, almost every part of Spring is covered including some useful addons like Spring Data JPA, Spring Batch, Spring Integration and Roo, The book is not just about Spring it is about how to be productive with Spring. Author explains how to use SpringTool Suite (STS), how to decide which approach to follow, examples are very profound. And through the book author is developing a real application! I wish that authors have paid attention on Spring security (not covered at all) and Beans Validation chapter is too thin with only 2 field validation annotations mentioned (@NotNull and @Size). Still this is the best book that will make you a good and capable Spring programmer even if you don't have any precognition about Spring.

21 јун 2012

YU18n

Raspad SFRJ doneo je mnogo problema lokalizatorima za naše pordučje. Autori Java jezika se nisu baš najbolje snašli u tome pa i u javi 6-te verzije postoje problemi. Rešenje za te probleme kao i kratak istorijat problema pogledajte na sledećem linku: http://klaus.e175.net/java-yu

Hvala Draženu na ovom linku :)

29 фебруар 2012

Zanimljivosti iz istorije Ujedninjenog kraljvestva

Dok sam u Škotskoj često gledam emisije iz njihove istorije što i nije teško naći jer ih ima na svim kanalima a postoji i poseban kanal samo za to pod slikovitim nazivom Yesterday.

Evo nekoliko zanimljivosti nabacanih na gomilu:

U toku 2. sv. rata zalihe čaja su strateški raspoređene na 7 lokacija kako bi se izbeglo uništavanje što bi po moral Britanaca bilo pogubno.

Šetland, ostrvo na pola puta između Britanije i Norveške danas deo Škotske je istorijski deo Norveške. Norveški vladar je dao engleskoj kraljici u zakup ostrvo a ono nikad nije vraćeno majci Norveškoj. Na ostrvu i dan danas imaju svetkovine posvećene Vikinzima jer oni i jesu njihovi potomci

Racionalisanje ishrane (dobijanje sledovanja hrane na bonove, tačkice i slično ograničavanje i razdeljivanje hrane) u UK je ukinuto tek 1954. godine. Toliko ih je rat upropastio.

U 17. veku je škotskim brđanima (Highlanderima) bilo zabranjeno da nose tartane i oružje. Mnogi klanovi (npr. Mc Donald) su bili desetkovani zbog nepoštovanja naredbe. Vojska je imala naredbu da nikog starijeg od 17 godina ne ostavi u životu.

Britanija je zagospodarila morem tako što su se prvo zakačili u 16. veku sa moćnom španskom armadom. Povod je bio vrlo prozaičan, Španci su trgovali robovima, Britanci pokušali da sa samo 2 broda uzmu koju mrvicu iz tog ogromnog posla ali im ni toliko nisu dali već su ih napali španski brodovi. Jedan od preživelih britanskih mornara je čitav život posvetio borbi protih Španaca i bio je vrlo ubedljiv. Špancima se škrtarenje nije isplatilo :)

Najveći poraz engleska mornarica je doživela kad je parlament zavrnuo slavinu za mornare. Brodovi su nedeljama stajali usidreni kod Londona, a onda su došli Nizozemci, probili se kroz Temzu i iznenadili englesku mornaricu. U očaju Englezi pale i potapaju nekoliko brodova kako bi zatvorili prolaz ali kasno. Najveći engleski brod su Nizozemci zarobili i odveli. Takvu sramotu sebi Englezi nikad nisu zaboravili.

Krajem 18. veka kad se razivija nova klasa sastavljena od trgovaca i ostalih koji su bogatstvo stekli na krilima britanskog gospodarenja morem. Čaj je jako skup ali je ova klasa imala dovoljno para da pravi redovne čajanke. Čajanke su postale sastavni deo društvenog života. Iako su te domoćice imale služavke, same su pravile čaj, tako nešto skupo nisu želele da prepuste služavkama.

U to vreme dosetio se jedan njihov vladar da oporezuje prozore. I to tako da je bila velika razlika između poreza na 10 i više prozora i onog na manje od 10. Kao posledica utaje poreza i dan danas se mogu videti na starijim kućama zazidani prozori :D

Britanija je uvela gas mnogo pre nego što je uvedena struja. Gas je do 60-tih bio pravljen od uglja. Služio je ne samo za grajanje i kuvanje već je bio preteča sijalica ne samo u uličnoj rasveti već i u samim domovima.

Kralj koji je bio kreativan po pitanju poreza na prozore je imao i druge zamisli. Oprezovao je ogledala po kućama pa čak i bele voštane sveće koje su samo imućniji imali. Sirotinja je imala lojane koje su stvarale mnogo čađi.

Britanija je konačno postala jedina supersila na moru tako što je porazila tada najstrašniju mornaricu sveta: Frnacusku. To je urađeno na vrlo originalni način. Većina brodova Francuzi su držali usidrene u luci Brest na Antlantiku. Jedan se Britanac dosetio da bi mogao isploviti i blokirati brodove u luci. Nikome ranije to nije palo na pamet iz jednog vrlo praktičnog razloga: tada se nije moglo biti dugo na moru, moranri bi se zbog loše i jednolične hrane posle par sedmica porazboljevali. No Britanac se dosetio da mu drugi brodovi donose zalihe sveže hrane i vode tako da je do beskonačnosti mogao držati Francuze za ... Za to vreme je ostatak britanske vojske uzimao francuske posede u srednjoj Americi, Quebec, Indiju... Francuzi nisu mogli imati pomoć mornarice niti dotur oružja i ljudstva. Kad je Frnacuskom kralju dosadilo da mesecima ne dobija novac iz kolonija kao i da gubi zemlju kojekude, naredio je ništa manje nego zauzeće Londona. Francuska mornarica je krenula u proboj kroz deo koji je pun hridina a koji su poznavali bolje od Engleza. Ali su se Englezi ipak usudlili da krenu za njima i rizik se isplatio, uništili su silu brodova tako da se Francuska nikad nije oporavila. Sve se ovo dešavalo za zemana Luja XV. Posle ovolikog gubitka nije ni čudo što je uskoro izbila revolucija u Francuskoj...

Struja je u Britaniji uvođena neplanski preko privatnih kompanija. Posledica toga je da se mreža do mreže razlikovala po naponu i po utičnicama. Tek posle 2. sv. rata je vlada odlučila da napravi nacionalnu prenosnu mrežu koja bi ujedinila i unifikovala sve te rasparčane mreže.

Kad je 60-tih otkriven prirodni gas prešlo se sa ugljenog na njega. Prirodni gas je kaloričniji i sve instalacije su morale biti prilagođene. Npr. gorionici na šporetima su zamenjenji. Domaćice tog vrena su se žalile kako ne mogu da se naviknu na novi gas, ako ga zategnu on se ugasi ako ga odviju onda im sve zagori :D

Jedini deo teritorije UK koji je nemačka vojska zauzela su Kanalska ostrva (Jersey i druga) u blizini Francuske. Ta ostrva su ustvari državice koje za svojeg vladara na neki način priznaju engleskog kralja/kraljicu. Inače nikakve direktne veze s Britanijom nemaju. Kad je Frnacuska pala UK vojska se brzom brzinom pokupila i pobegla. Nemci su na ostrvima ostali sve do 9. maja 1945. iako su iz Francuske protrerani mesecima ranije. Hitler je bio opsednut da drži makar deo nečega što u neku ruku pripada UK i što žulja Čerčila :) Zato je na ostrva poslao silu vojske, gradio podzemne baze za podmornice, utvrdio obalu... Britanci su se poneli krajnje hladno i racionalno, nisu hteli da ginu za slavu, čekali su da zauzmu Berlin pa da se ostrva sama vrate.