Skip to content

Instantly share code, notes, and snippets.

@sureshnath
sureshnath / unix_ssh_close_conn.sh
Last active December 9, 2015 21:08
Close SSH session after command execution
ssh user@host "sh script.sh </dev/null >/dev/null 2>/dev/null &"
@sureshnath
sureshnath / xpath_list_attr.txt
Last active December 14, 2015 15:48
XPath - list all attributes of elements with a specific criteriaexample: list href of links with class="list"
//a[@class="list"]/@href
@sureshnath
sureshnath / sql_merge_stmt.sql
Last active December 15, 2015 03:29
ORACLE SQL Merge : insert or update key value pair
--create table configuration(key varchar(50), val varchar(100));
merge INTO configuration t USING --- table name configuration
(SELECT
substr(keyVal,1, instr(keyVal,'=')-1) key
, substr(keyVal,instr(keyVal,'=')+1) val
----- add other columns
from (select 'key=val' keyVal FROM dual) d ------- replace key=val
) s ON ( s.key = t.key )
@sureshnath
sureshnath / mercurial-list.sh
Last active December 15, 2015 09:19
Shell one line script to list Mercurial repositories
curl --user username:password -k https://URL 2>&1 | xidel - -e '//a[@class="list"]/b' 2>/dev/null
@sureshnath
sureshnath / h2.help.txt
Created April 2, 2013 10:14
sample h2 memory url and sql scripts to load from class path
DB_URL=jdbc:h2:mem:datasource;MODE=Oracle;INIT=runscript from 'classpath:/sql/h2.creation.sql'
h2.creation.sql
-------------------------
runscript from 'classpath:/testing/beforeclass/001-init.sql'; -- from class path
runscript from '~/001-init.sql'; --from ${user.home}
@sureshnath
sureshnath / schell-script-location.sh
Last active December 15, 2015 19:39
Bash script tell what directory it's stored in
#### http://stackoverflow.com/a/246128/1669145
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
@sureshnath
sureshnath / TestNGParameterisedTest.java
Last active December 16, 2015 06:58
Create a test for different inputs and exceptions
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
public class TestNGParameterisedTest {
@Test(dataProvider = "parseIntInputs")
public void testInt(String input, Object expected){
@sureshnath
sureshnath / simple-xml-serialise-test.java
Last active December 16, 2015 06:58
test simple xml serialisation
public static <T> T testSerialisation(Class<? extends T> type, T expected) {
Serializer serializer = new Persister();
StringWriter sw = new StringWriter();
T actual = null;
try {
serializer.write(expected, sw);
} catch (Exception ex) {
LOG.error("testing serialisation failed", ex);
Assert.fail("testing serialisation failed");
}
@sureshnath
sureshnath / log4j.xml
Created April 16, 2013 10:52
log4j xml EnhancedPatternLayout package limited
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5p: %c{1.} - %.1000m%n" />
</layout>
@sureshnath
sureshnath / CollectionUtil.java
Last active December 16, 2015 08:08
Collection Util isEmpty ImmutableList Java
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.util.List;
public class CollectionUtil {
public static <T> List<T> getImmutableNonNullList(List<T> list) {
return isEmpty(list) ? ImmutableList.<T>of() : ImmutableList.copyOf(list);
}