Skip to content

Instantly share code, notes, and snippets.

View AravindaM's full-sized avatar
🏠
Working from home

Aravinda Liyanage AravindaM

🏠
Working from home
View GitHub Profile
@AravindaM
AravindaM / BarcodeReader.java
Last active June 27, 2016 02:41
Bar Code Reader
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Listener for reading data from the barcode Reader
* @author Aravinda
*
@AravindaM
AravindaM / CustomJTable.java
Last active June 27, 2016 02:42
Change JTable Background / Foregorund Colour
import java.awt.Color;
import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class CustomJTable extends JTable {
Color backgroundColor = getBackground();
@AravindaM
AravindaM / ConfigPropertyReader
Created July 6, 2015 03:23
[JAVA] Reading configuration from Property file
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
* Read configurations from property file.
* @author Aravinda.
@AravindaM
AravindaM / JTableRowSelector.java
Last active June 27, 2016 02:42
[JAVA][JTABLE] Go to given row,column in a JTable and select
Public Class JTableRowSelector{
public static void selectRow(JTable table, int rowIndex, int vColIndex) {
if (!(table.getParent() instanceof JViewport)) {
return;
}
JViewport viewport = (JViewport)table.getParent();
// This rectangle is relative to the table where the
// northwest corner of cell (0,0) is always (0,0).
Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
@AravindaM
AravindaM / SampleMailClient.java
Last active June 8, 2016 05:49
Sample Gmail Client
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class SampleMailClient {
private static String USER_NAME = "ara123@gmail.com"; // GMail user name (just the part before "@gmail.com")
private static String PASSWORD = "pass@1235"; // GMail password
@AravindaM
AravindaM / primeNumber.java
Created January 12, 2016 03:14
Check if interger is a prime...
/*
* An optimized to check if a number is prime or not.
*/
public static boolean isPrime(int num) {
if (num == 2 || num == 3) {
return true;
}
if (num % 2 == 0 || num % 3 == 0) {
return false;
@AravindaM
AravindaM / LocalBroadcastExampleActivity.java
Created May 13, 2016 06:27 — forked from Antarix/LocalBroadcastExampleActivity.java
Simple Example of using LocalBroadcastManager in Android
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
@AravindaM
AravindaM / ConfigReader.java
Created June 8, 2016 05:47
Load Config properties outside a JAR file.
public class ConfigReader {
public static Map<String, String> readConfig() {
Map<String, String> config = new HashMap<>(3);
Properties prop = new Properties();
CodeSource codeSource = ConfigReader.class.getProtectionDomain().getCodeSource();
@AravindaM
AravindaM / SHA256HMAC.scala
Last active March 2, 2022 20:51
Generate HMAC using SHA256 in Scala
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
Object HMACgen {
def generateHMAC(sharedSecret: String, preHashString: String): String = {
val secret = new SecretKeySpec(sharedSecret.getBytes, "SHA256") //Crypto Funs : 'SHA256' , 'HmacSHA1'
val mac = Mac.getInstance("SHA256")
mac.init(secret)
val hashString: Array[Byte] = mac.doFinal(preHashString.getBytes)
@AravindaM
AravindaM / gist:b0e02023a81dff4ca4533ae759574bba
Created September 27, 2016 05:44 — forked from suruja/gist:10241312
Mongo dump and restore on Heroku
require 'uri'
namespace :mongo do
desc "Dump the production database and restore to development and staging databases."
task :dump_and_restore => :environment do
dev = URI.parse(ENV["MONGO_URI"])
prod = URI.parse(`heroku config:get MONGO_URI --remote production`)
prod_username, prod_password = prod.userinfo.split(':')