Thursday, May 31, 2018

How to highlight code in blogger or blogspot.com?

<pre class="prettyprint"><code class="language-html">YOUR CODE HRER</code></pre>
Above the code is for HTML. If you want to use syntax highlighter for specific style or language, you must replace language-HTML with language-value. Given the value and attribute of some style or language:
Highlight ForvalueAttribute
HTMLhtmllanguage-html
CSScshlanguage-
JavaScriptjslanguage-js
XMLxmllanguage-xml
xHTMLxhtmllanguage-xhtml
Cclanguage-c
C++cpplanguage-cpp
C#cslanguage-cs
PHPphpLanguage-php
Pythonpylanguage-py
Javajavalanguage-java
Rubyrblanguage-rb
Perlperllanguage-perl
Resource Link: https://www.compromath.com/code-formatting-syntax-highlighter-for-blogger/

How to optimize if condition in groovy

Main Code:
        if (text != null) {
            return text.toString().replaceAll("<[Bb][Rr]>", "\n")
        } else {
            return text
        }
Optimization#1:
return text?text.toString().replaceAll("<[Bb][Rr]>", "\n"):text
Optimization#2:
return text?toString().replaceAll("<[Bb][Rr]>", "\n")
It will give null pointer exception. because text?.toString() also gives null. But it is not checked. So do it like below:

return text?toString()?.replaceAll("<[Bb][Rr]>", "\n")
Test Case:
@Unroll
    def "#caseNo : check replaceBrTagToNewLine method"() {
        when:
        def result = itemScreenService.replaceBrTagToNewLine(text)

        then:
        assert result == expected

        where:
        caseNo | text               | expected
        1      | null               | null
        2      | ""                 | ""
        3      | "test"             | "test"
        4      | "
"             | "\n"
        5      | "test
line"     | "test\nline"
        6      | "test
line"     | "test\nline"
        7      | "test
line"     | "test\nline"
        8      | "test
line"     | "test\nline"
        9      | "



" | "\n\n\n\n"
    }

Friday, April 27, 2018

Windows: java.net.BindException: Address already in use: bind

Issue Details:


Caused by: java.net.BindException: Address already in use: bind

        at sun.nio.ch.Net.bind0(Native Method)

        at sun.nio.ch.Net.bind(Net.java:433)

        at sun.nio.ch.Net.bind(Net.java:425)

        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)

        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)

        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)

        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:980)

        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:573)

        at org.apache.catalina.connector.Connector.startInternal(Connector.java:993)

        ... 17 common frames omitted

27-04-2018 23:31:20 [o.a.c.h.Http11NioProtocol:179] log : Pausing ProtocolHandler ["http-nio-3000"]

27-04-2018 23:31:20 [o.a.c.c.StandardService:179] log : Stopping service Tomcat

27-04-2018 23:31:20 [o.a.c.u.LifecycleBase:179] log : The stop() method was called on component [StandardServer[-1]] after stop() had already been called. The second call will be ignored.

27-04-2018 23:31:20 [o.a.c.h.Http11NioProtocol:179] log : Stopping ProtocolHandler ["http-nio-3000"]

27-04-2018 23:31:20 [o.a.c.h.Http11NioProtocol:179] log : Destroying ProtocolHandler ["http-nio-3000"]

27-04-2018 23:31:20 [o.s.b.a.l.AutoConfigurationReportLoggingInitializer:101] logAutoConfigurationReport :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.

27-04-2018 23:31:20 [o.s.b.d.LoggingFailureAnalysisReporter:42] report :

***************************

APPLICATION FAILED TO START

***************************

Description:

The Tomcat connector configured to listen on port 3000 failed to start. The port may already be in use or the connector may be misconfigured.

Fixation: 

First, find out which PID is using the port 3000. Then kill the process id.

C:\Users\drakula>netstat -ano | find "3000"

  TCP    0.0.0.0:3000           0.0.0.0:0              LISTENING       8464

  TCP    [::]:3000              [::]:0                 LISTENING       8464

C:\Users\drakula>TASKKILL /PID 8464 /F

SUCCESS: The process with PID 8464 has been terminated.

C:\Users\drakula>