Skip to content

Instantly share code, notes, and snippets.

View handakumbura's full-sized avatar

Dumidu Handakumbura handakumbura

  • Colombo
View GitHub Profile
@handakumbura
handakumbura / DatabaseUser.java
Last active November 29, 2018 13:36
JDBC usage example.
package com.dumiduh;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class DatabaseUser {
private Connection connectionObj;
private Statement statementObj;
@handakumbura
handakumbura / Driver.java
Created March 8, 2014 06:59
Driver for the DatabaseUser.
package com.dumiduh;
public class Driver {
public static void main(String[] args)
{
DatabaseUser user = new DatabaseUser();
user.run();
}
}
@handakumbura
handakumbura / wso2server.sh
Created May 24, 2016 10:57
Hiding the secure vault pwd inside the server startup script. Taken from WSO2 ESB 4.8.0.
#!/bin/sh
# ----------------------------------------------------------------------------
# Copyright 2005-2012 WSO2, Inc. http://www.wso2.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@handakumbura
handakumbura / logchecker.sh
Created July 2, 2016 10:08
this script checks the existence of a char sequence in the last X number of lines of a files and plays a wave file if a match is made.
#!/bin/bash
#this script checks the existence of a char sequence in the last X number of lines of a files and plays a wave file if a match is made.
# sh logchecker.sh <number of lines to tail at one go> <logfile> <char sequence> <wav file to play>
while [ 1 -gt 0 ]; do
tail -n $1 $2 | grep -e "$3"
if [ $? -lt 1 ]; then
aplay $4 ;
exit ;
fi
sleep 10; #check interval
@handakumbura
handakumbura / grepout.sh
Created July 2, 2016 10:39
grep out a log tail to a separate file
#!/bin/bash
tail -f $1 | grep -e -B $2 -A $3 $4 >> GREPOUT
#!/bin/bash
#A convenient way to check if bash scripts contain syntax errors using the bash -n command.
INTERVAL=10
while [ 1 -gt 0 ]; do
bash -n "$1"
if [ $? == 0 ]; then
echo 'No Syntax errors were found. Keep marching on soldier!'
fi
sleep $INTERVAL; #check interval
autocmd CursorHold,CursorHoldI * update
@handakumbura
handakumbura / gist:8d424dd4023d67de8a7a77d859fd6720
Last active April 26, 2017 04:57
Error handling with status codes in BASH
#do something if error code denotes a failure
if [ $? -gt 0 ]; then
echo "something went wrong!"
fi
#status checking in command pipe
cat textfile.txt | ( [[ $? == 0 ]] && grep "cat" )
curl -X GET -v $ENDPOINT > RESPONSE
cat $RESPONSE | grep -i "success"
findproductnames()
{
DELIMITER="*"
PROD_ONE="Apache JMeter"
PROD_TWO="Apache Tomcat"
echo $PROD_ONE$DELIMITER$PROD_TWO
return
}