Some STRING functions in SQL:
select RIGHT(column, chars) from table;
select SUBSTRING_INDEX(column, char, which char (i.e, 1,2...)) from table;
select REVERSE(string);
select LTRIM(string);
select RTRIM(string);
select LENGTH(string);
Sunday, August 26, 2012
Monday, July 30, 2012
Java Pitfalls Book
This book "Java™ Puzzlers: Traps, Pitfalls, and Corner Cases
It explains what is wrong with this piece of code (It doesn't print out AB as one would expect):
public class PrintingSomeLetters {
public static void main(String[] args) {
System.out.println('A' + 'B');
}
}
Monday, July 23, 2012
Getting a list of installed services on a Linux server
$ chkconfig --list
Friday, June 22, 2012
Tuesday, May 15, 2012
Java 5 autoboxing fail on equality check
Double d1 = 25d;
Double d2 = 25d;
if (d1 == d2) {
System.out.println("equal (==)");
} else if (d1.equals(d2)) {
System.out.println("equal (using equals() method)");
}
The output is:
equal (using equals() method)
Double d2 = 25d;
if (d1 == d2) {
System.out.println("equal (==)");
} else if (d1.equals(d2)) {
System.out.println("equal (using equals() method)");
}
The output is:
equal (using equals() method)
Wednesday, May 2, 2012
Reverse search for a previous command on Linux
Use CTRL-r to reverse search through a history of your previous commands executed in Linux e.g.
Type in the text for a command you are searching for e.g. 'cat'
In this case the last command executed with the substring 'cat' is 'cat test.txt'.
To exit the reverse search just use CTRL-g.
$(reverse-i-search)`':
Type in the text for a command you are searching for e.g. 'cat'
$(reverse-i-search)`cat': cat test.txt
In this case the last command executed with the substring 'cat' is 'cat test.txt'.
To exit the reverse search just use CTRL-g.
Thursday, April 26, 2012
Using SED to Append or Prepend characters
You can use sed to Append/Prepend characters to a String e.g.
We have a file (test.txt) below and we would like to Prepend each capital letter with a space:
sed makes use of a special character "&" which implies the pattern found.
Similarly we could Append a sentence after the "Hello." string:
We have a file (test.txt) below and we would like to Prepend each capital letter with a space:
$ cat test.txt
Hello.ThisIsATestFile.
$ sed "s/[A-Z]/ &/g" test.txt
Hello. This Is A Test File.
sed makes use of a special character "&" which implies the pattern found.
Similarly we could Append a sentence after the "Hello." string:
$ sed "s/Hello./&HowAreYou?/g" test.txt
Hello.HowAreYou?ThisIsATestFile.
Subscribe to:
Posts (Atom)