Monthly Archives: December 2014

Insert Javascript code in JSF page

jsf_js
Usually you may need to insert a couple of JavaScript in your JSF page markup.
The following advice helps you do it right:

 <ui:composition ...>
    
    <ui:define name="body">
        
        <!-- your code -->
        
        <h:outputScript target="body">
            <![CDATA[
                alert("It works!");
            ]]>
        </h:outputScript>
        
        <!-- your code -->
        
    </ui:define>
    
</ui:composition>

So, as you see in JSF we use h:outputScript tag with CDATA inside to workaround issues like “The content of elements must consist of well-formed character data or markup” for valid XHTML.

Thanx to http://stackoverflow.com/a/4338816

Convert Java stacktrace to String

stacktrace
To present java stacktrace as string use next snippet:

Exception e = new Exception("EX!");

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);

String stacktraceAsString = sw.toString();

Thanx to http://stackoverflow.com/a/1149712

Web

Check is jQuery loaded

jq
The simplest way to check jQuery library exists and loaded on page is next:

if (window.jQuery) {
  // your jQuery code here...
}

Thanx to http://stackoverflow.com/a/24284903

JBoss remote debug

jboss_logo
To connect to JBoss application server remotely you should perform next action:

open run.conf.bat (for windows) or run.conf (for linux) file in JBoss bin folder
and add the following java argument:

JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

If you miss -Xdebug parameter you can enter to debug mode but after timeout (a few minutes) you’ll be disconnected and JBoss restart occurred!
Read more at http://stackoverflow.com/questions/18182666/eclipse-remote-debugging-with-jboss.

Thanx to http://stackoverflow.com/a/18211332

Web

Sticky header with CSS and JavaScript

Before scroll:
sticky_header1

After scroll:
sticky_header2

To obtain of sticky header effect you can use next code snippet.

1. Add CSS styles:

.persist_header_container {
}

.persist_header {
    padding: 10px;
    background: yellow;
    z-index: 1;
}

.floating_header {
    position: fixed;
    top: 0;
    visibility: hidden;
    -webkit-box-shadow: 0px 2px 12px 0px rgba(50, 50, 50, 1);
    -moz-box-shadow: 0px 2px 12px 0px rgba(50, 50, 50, 1);
    box-shadow: 0px 2px 12px 0px rgba(50, 50, 50, 1);
}

2. Add JS code:

$(function() {
    $(".persist_header_container").each(function () {
        var header = $(".persist_header", this);
        header.before(header.clone())
              .css("width", header.width())
              .addClass("floating_header");
    });

    window.updateHeader = function () {
        $(".persist_header_container").each(function () {
            $(".floating_header", this)
                .css({"visibility": ($(window).scrollTop() > $(this).offset().top ? "visible" : "hidden")});
        });
    };

    $(window).scroll(function () {
        updateHeader();
    });
    updateHeader();
});

Download source code: sticky_header

Also,
http://www.cssreset.com/creating-fixed-headers-with-css/
http://css-tricks.com/persistent-headers/

Firefox plugins what i use

ff
Here is a list of plugins for Firefox browser which i use everyday.

1. ColorfulTabs - colors every tab in a different color and makes them easy to distinguish while beautifying the overall appeal of the interface.
ColorfulTabs
https://www.binaryturf.com/free-software/colorfultabs-for-firefox

2. Tab Mix Plus – duplicating tabs, controlling tab focus, tab clicking options, undo closed tabs and windows, plus much more.
tabmixplus
http://tmp.garyr.net/

3. Tab Utilities – utilities for tabbed browsing.
TabUtilities
https://addons.mozilla.org/en-US/firefox/addon/tab-utilities/

4. Firebug - edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
Firebug
www.getfirebug.com

5. Ghostery - see who’s tracking your web browsing and block them.
Ghostery
https://www.ghostery.com/en/

6. gTranslate - translates the selected text via Google Translate.
gTranslate
https://addons.mozilla.org/en-US/firefox/addon/gtranslate/

7. Flash and Video Download – download flash games and videos with a single click.
FlashandVideoDownload
http://www.fnvfox.com/

Have fun with FF!

How to kill session in Oracle DB

oracle
To kill session in oracle we need:

Step 1: Find SID and SERIAL#:

SELECT SID, SERIAL# FROM v$session WHERE username = 'TEST';

Step 2: Try to disconnect session:

ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' POST_TRANSACTION;

Or:

ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' IMMEDIATE;

If doesn’t help, use next step.

Step 3: Run kill session command:

ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;

If doesn’t help, use next step.

Step 4: Kill system process. Firstly find SPID:

SELECT P.SPID, S.SID, S.SERIAL# FROM V$PROCESS P, V$SESSION S WHERE P.ADDR = S.PADDR AND S.SID = XXX;

And then for windows:

orakill ORACLE_SID spid

Or for linux:

kill spid

For more info, read here:
http://oracle-base.com/articles/misc/killing-oracle-sessions.php
http://www.ora00600.com/wordpress/articles/kill-oracle-session/