// shall I write some keywords here to boost search engine ranking?

Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Monday, August 26, 2019

Offload your SSD (on Windows) and SD Card (on Linux)

As many of us aware, both SSD and SD Card wearing out upon write operation. So to extend life span of the storage, we may look into reduce the write operation.

(With wear leveling, most modern SSD have lifespan that is long enough where you might want to skip this post. But no harm to know something new, right ?)

For SSD, you may consider putting the Windows's TEMP folder into a RAM disk. RAM disk, as the name implies, it is a virtual drive that reserve and utilise the space on your RAM. There are many RAM disk software out there, and I'm using ImDisk's RamDisk Configuration.

You can define the space of the RAM disk, and set the TEMP folders to the RAM Disk with this tool:

(ImDisk RamDisk Configuration)


For SD Card that store your OS (i.e. Raspberry Pi), we will put the `/var/log` on RAM with log2ram. This will make the logs stay in RAM and only flush to storage once a day by default (configurable).

After done installation and reboot your Raspberry Pi, you shall see the screen below:

(log2ram: new mounting point after installation and restart)
This shall extend the lifespan of your SD Card.

Thanks for reading.

Wednesday, April 29, 2015

Chrome unable to load Google sites

Recently I had been facing problem loading Google sites such as its search engine, Gmail, Youtube, etc.


It is either take extra ordinary long time to load, or just failed with `ERR_QUIC_PROTOCOL_ERROR`.

I did a search and found I am not alone, and below are the solution [1]:

  1. Open a new tab in Chrome, and type `chrome://flags/` into address bar, then press Enter.
  2. Search for `Experimental QUIC protocol`
  3. Disable it.
  4. Restart Chrome. Done.
It had been about a week, and the error never happen again.

[1]: https://productforums.google.com/forum/#!topic/chrome/xKFfhDvhjU8


Saturday, October 05, 2013

Set Transfer Encoding of Attachment for Axis2

When sending SOAP request with attachment, Axis2 handle the attachment via Axiom, and the default transfer encoding for binary file are binary.

In order to change the transfer encoding to something else, we will utilize the org.apache.axiom.attachments.ConfigurableDataHandler instead of the usual javax.activation.DataHandler.

Below is the sample code:

Wednesday, June 13, 2012

Axis2 + Rampart: Generate Nonce and Created when Plain Text Password was Used

Axis2 support WS-Security via Apache Rampart module. I had develop the SOAP client based on tutorial : UsernameToken Authentication with Rampart

However, the default implementation of Apache Rampart will not generate Nonce when plain text password was used.

After some google, I found this page talk about a configuration called "addUTElements".

So below are the modified configuration fragment:


Saturday, November 05, 2011

Revert to the old Google Reader? Let's enhance the new one

IMHO, The redesign of Google Reader to integrate with Google+ do not impress me.

I am agree with the review of ex-Product Manager of Google Reader. The space allocated for reading is just too small, and I personally like the light blue theme than the current grey scale page.

I failed to google any workable way to restore the old Google look and feel. However, I found the ways to enhance the Google Reader (for Firefox).

Below is the original new Google Reader look and feel:


Below is the modified look and feel:


Below are the steps:
1. Install Greasemonkey plugin
2. Install script "Google Reader - Compact Design" (this script make interface more compact thus give you more space to read)
3. Install Stylish plugin
4. Install user style "Google Reader Revert" (to get back the light blue theme)

So far this 2 scripts do not conflict with each other. Feel free to try.

Saturday, March 19, 2011

JQuery UI: Datepicker with Month and Year only

This can be done by hiding the calendar via some CSS trick:

Saturday, February 19, 2011

JQuery UI: eliminate "stop running this script?" warning in IE

In IE, when the Javascript on the page take too long duration to execute, the browser will popup a warning of "Stop running this scripts?"

In order to eliminate the warning, we need to hint the browser that the script is not infinitely running, by having some pause via Javascript setTimeout method.

However, for Javascript framework such as JQuery that use selector and method chaining extensively, Just setTimeout alone will not help much.

We will need to slice the elements list from selector into few smaller batches, before chain it to the next method.

Below is the sample code snippet:



Feel free to share if you have a more elegant approach to this problem. :)

Sunday, August 08, 2010

Split String with Empty Trailling Tokens in Java

The "-1" do the tricks:

String[] stringTokens= dataString.split(",", -1);

Sunday, April 25, 2010

Print Directory Tree with Groovy (with closure recursion)

While looking for a script that display directory tree, I came across this Groovy script.

The code look just fine but it don't work (I test it with Groovy 1.7). After some google, I found that this is due to the closure as a first class object in Groovy, it can't be call within the closure itself.

And below is the solution:

def listRecursivly

listRecursivly = { file, arg ->
    println "${'|  ' * arg}`- ${file.getName()}\\"
    file.eachFile() {f ->
        if(f.directory) {
            listRecursivly(f,(arg + 1))
        } else {
            println "${'|  ' * (arg + 1)}`- ${f.getName()}"
        }
    }
}

listRecursivly (new File("."),0)

The little trick here is to define and initialize the closure in 2 separate lines.

Reblog this post [with Zemanta]

Friday, January 15, 2010

Scan File with AVG 8.5 in Windows Live Messenger

It is a bit tricky:

1. Create a batch file (said ScanAVG.bat) in your AVG installation directory:
2. Edit the batch file:


@echo off
"C:\Program Files\AVG\AVG8\avgscanx.exe" /SCAN=%1 /HEUR /ARC /PUP /CLEAN

3. In Live Messenger, Tools > Options > File Transfer
4. Check "Scan files for viruses using:"
5. Fill in the path to your batch file. (i.e. "C:\Program Files\AVG\AVG8\ScanAVG.bat")


Reference: http://forums.techguy.org/general-security/707127-solved-avg-8-free-windows-2.html

Saturday, January 09, 2010

Send Message to ActiveMQ via WGET

In ActiveMQ website, it does show the steps of consuming message from ActiveMQ via WGET.


In order to produce message and send into ActiveMQ queue, here is the command:
wget --post-file=message.txt http://localhost:8161/demo/message/MyQueue?type=queue

Where the message.txt is something like this:
body=the test message you would like to submit.
Reblog this post [with Zemanta]

Monday, September 07, 2009

Redirect Tomcat console output to log file

We know using proper logging library instead of System.out is important. But when there are a legacy application that still using the System.out and System.err, it will be good to be able to pipe it into file for troubleshooting.

The solution is set the swallowOutput="true" in Tomcat context of your webapp. Then this will pipe the stdout and stderr into the logger configured in the same context.

Thursday, March 05, 2009

Duplicate log in log4j

If you have log4j configured as below, you will notice that log entry from "yourLogger" will duplicate in appender


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout


To solve this, just change your configuration to:


log4j.rootLogger=info, stdout
log4j.logger.yourLogger=info, stdout
log4j.additivity.yourLogger=false

Saturday, December 27, 2008

Axis2 WSDL2Java error for SOAP Encoding

Recently had hit the SchemaCompilationException when using Axis2 wsdl2java to generate client stub from a WSDL file.

After some google, had found this page is describe same problem as what I face. And the reason for the exception is due to Axis2 do not support SOAP Encoding.

Fortunately after a while, my colleague had found the solution. Instead of using ADB for data binding, use XMLBeans. Below is example of the command:

wsdl2java -uri myService.wsdl -d xmlbeans

Friday, November 14, 2008

Java: convert UCS2 to UTF-8

While convert UCS2 into UTF-8, I hit UnsupportedEncodingException. So I use UTF-16 instead and it work well (at least till the time I write this post):


public String ucs2ToUTF8(byte[] ucs2Bytes) throws UnsupportedEncodingException{

String unicode = new String(ucs2Bytes, "UTF-16");

String utf8 = new String(unicode.getBytes("UTF-8"), "Cp1252");

return utf8;
}

Saturday, November 01, 2008

Duplicate Underscore in XML generated by XStream

When using XStream to serialise Java object into XML, alias name with undercore (_) will get duplicate. For example, "first_name" will be serialised as "first__name".

The reason is explained in their FAQ and the workaround is to provide your own XmlFriendlyReplacer. However, it do not give any example. So here is the example:


// replace $ with "ddd"
// replace underscore with underscore
XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
XStream xstream = new XStream(new DomDriver("UTF-8", replacer));

Sunday, October 26, 2008

Spring: factory method with arguements

Spring framework is a popular IoC framework. In the documentation, it show examples of instatiate object through constructor, static factory method, and instance factory method.

However, It do not show the example of factory method with parameters. After some google, below is the trick:

public class TestObject{

private String id;

private TestObject(String id){
super();
this.id = id;
}

public static TestObject getInstance(String id){
return new TestObject(i)
}
}


<bean id="testObject" class="TestObject" factory-method="getInstance">
<constructor-arg type="java.lang.String" value="object-id-123"/>
</bean>

Sunday, October 19, 2008

Java: Check if Socket Connection Broken

Most common ways of check if a socket connection to server was broken is by send a heartbeat message to server. However, for application that connect to server that do not support heardbeat, we can check connection by listen to the InputStream:

('is' refer to java.io.InputStream)


int bytesRead = is.read(receiveBuffer, 0, 1024);

// this is the trick to identify connection drop
if(bytesRead == -1){
throw new IOException("byteRead = -1, Connection closed.");
}

Sunday, September 28, 2008

Java: remove non-printable characters from String

Regular expression in Java is handy to remove non-printable character (control character, ASCII 0 - 31, 127) from a String:


String truncated = originalString.replaceAll("\\p{Cntrl}", "");

Wednesday, September 17, 2008

Turn Off Annoying Beep Sound on Windows

The annoying beep alert of Windows can be disable by editing registry key value. Below are the steps:

1) Open Registry Editor by: Start > Run > regedit
2) Open the key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Beep
3) Change value of "Start" to 4
4) Restart PC.