Sunday, July 28, 2013

Extract certain tag with inner tags from huge XML

Task: You have huge XML file (300 Mb), you need to get out(filter out/extract/grab) it only one tag with specific value.

Under Ubuntu 12.04 install xslt processor:
sudo apt-get install xsltproc

Structure of huge XML (hugeFile.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<Feed ExtractDate="07/25/2013" ExtractTime="15:30:15">
  ..... a lot of companies information
<COMPANY ... LegalName="MyCompany" .....>
     ..... a lot of inner tags .....
 ..... a lot of companies information

Create extract.xsl file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:template match="/">

<xsl:element name="TagToExtract">
   <xsl:apply-templates select="//COMPANY[@LegalName='MyCompany']" />

  <xsl:template match="//COMPANY[@LegalName='MyCompany']">
      <xsl:apply-templates select="@*|node()" />
  <xsl:template match="@*|node()">
      <xsl:apply-templates select="@*|node()" />

Execute XSLT processor (12 seconds):
xsltproc extract.xsl hugeFile.xml > 1.xml

Saturday, July 27, 2013

Keep command launching after logout from terminal

It is very common case - you need to login to linux box, launch smth huge and that takes time, but you do not want to wait its finish and want to logout, or you afraid that internet connection could be broken in the middle of process that terminate your process.

thanks a lot for explanation to Dennis Williamson at here.

Two scenarios:
1) You launch process in background:

$ nohup myprogram &
$ logout

Explanation: nohup is allow process to ignore termination signal SIGHUP (“hang-up”)  on your logout (manual), "&" - just launch process in background and do not block current terminal session.

2) You launched process but forget to do it in background:

$ myprogram
<press Ctrl+Z>
[1]+  Stopped     myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout

Explanation (copy-paste from stackoverflow):
You press ctrl-Z. The system suspends the running program, displays a job number and a "Stopped" message and returns you to a bash prompt. You type the "disown -h %1" command (here, I've used a "1", but you'd use the job number that was displayed in the "Stopped" message) which marks the job so it ignores the SIGHUP signal (it will not be stopped by logging out). Next, type the "bg" command using the same job number. This resumes the running of the program in the background and a message is displayed confirming that. You can now log out and it will continue running...
 ...You should be aware that when you use the "bg" command the result is the same as if you'd run your program in the background with an ampersand (&). It won't have any output to stdout so it should be made to write output to a file (nohup will redirect standard output to nohup.out or ~/nohup.out if you don't redirect it yourself).

FYI: to resume to stopped process to foreground you can use "fg" of "fg <number>" in our case "fg 1", where "<number>" - is number that shown after Ctrl+z.

Wednesday, July 10, 2013

How to resolve system variables in spring xml configuration

during Tomcat launch you can specify system variable as ".... -Dmy.value=Hello .... "

but do not forget to put in you Spring configuration following bean:
<bean id="system-properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

to make this variable resolvable in any other bean configuration like:

<entry key="myValue" value="${my.value}" />

Friday, July 5, 2013

Remove job from Oracle

There are few types of jobs:
till Orecle10 - packages DBMS_JOB is used.
from Oracle11 - package DBMS_SCHEDULER is used.

DBMS_JOB are used numbers for identifier.
DBMS_SCHEDULER use valid oracle object name (that can not be started from numbers) 
Links to spec: dbms_job is deprecatedschedulerdbms_joball_jobs.

when you try to remove old job by new package you got (2364 is job identifier):

Error starting at line 1 in command:
Error report:
ORA-20001: comma-separated list invalid near ,
ORA-06512: at "SYS.DBMS_UTILITY", line 236
ORA-06512: at "SYS.DBMS_UTILITY", line 272
ORA-06512: at "SYS.DBMS_SCHEDULER", line 623
ORA-06512: at line 2 

From SQLDeveloper I got different error when use old package DBMS_JOB:

[ERROR] ORA-23421: job number 2364 is not a job in the job queue
[ERROR] ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
[ERROR] ORA-06512: at "SYS.DBMS_IJOB", line 770
[ERROR] ORA-06512: at "SYS.DBMS_JOB", line 180
[ERROR] ORA-06512: at line 2

But it was ok from sqlplus under owner user :

BEGIN DBMS_JOB.remove(2364); END; commit;

How to change location of monitor according to laptop

When you use additional monitor to you laptop it is good to have ability to specify there is you monitor is located in relation to laptop to use mouse movement easily.

By default Ubuntu put your laptop to left side and monitor to the right side, so moving mouse to right edge will move it next monitor. That is cool, but what if you monitor is located on left side of your laptop,  and you can not switch monitor physical location - you need to switch its location  virtually :).

launch "Displays" or run "System Settings" and click on "Displays" in settings. You will see layout like this:

Just grab monitor rectangle by mouse and move it to left side of laptop's screen rectangle. That is all.

move window to other monitor at ubuntu

You need to install Compiz Config Settings Manager:
"sudo aptitude install compizconfig-settings-manage"

and launch it from Dash(main button) by filtering "compiz".

select in the "Window Management" section a "Put" item. With that enabled, you can set a shortcut key in the "bindings" tab for "Put to Next Output". By default, it's disabled, but is easy to set.
No restart is required (at least on Ubuntu 12.04 x64).

If you have two monitors - this combination will work like swap of window location on monitors.

My default is "Cntl+~".