Skip to content

Instantly share code, notes, and snippets.

View dulichan's full-sized avatar

Dulitha Wijewantha (Chan) dulichan

View GitHub Profile
@dulichan
dulichan / gist:1710636
Created January 31, 2012 14:02
J2me Splitter class
public class Splitter {
public String[] split(String original, String separator) {
Vector nodes = new Vector();
// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
@dulichan
dulichan / gist:1789893
Created February 10, 2012 14:23
My first Python script - Asking questions from the user...
'''
Created on Feb 10, 2012
This module will be used to answer a set of questions and to
give intelligent answers
@author: Duli-chan
'''
import time
import re
print("We will now analyze what programming component is good for you?")
@dulichan
dulichan / PosPrinter.java
Created December 2, 2012 02:17
COM port printer writing java example
package app.posmachine.machine;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
public class PosPrinter {
@dulichan
dulichan / SoundLevels.java
Created December 3, 2012 07:09
Slider listening example for SO
package org.dchan.orm;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@dulichan
dulichan / mapstructure.py
Created December 4, 2012 09:47
Dictionary sum
'''
@author: dulithar(Dulitha Ransanga Wijewantha)
Helping a Stack Overflow Question
a[0] = [0, 1, 2]
a[1] = [0, 2, 2]
a[2] = [100, 200, 300]
Should output as - [{0:2, 100:1}, {1:1, 2:1, 200:1}, {2:2, 300:1}]
Not sure about the efficiency of the code. But you can find better solutions at http://stackoverflow.com/q/13699169/813471
@dulichan
dulichan / test1.java
Created December 5, 2012 08:59
Code of layout issue - StackOverflow
package org.dchan.context;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@dulichan
dulichan / CardLayoutHelper.java
Created December 5, 2012 09:02
CardLayout Helper
package org.dchan.ui;
import java.awt.CardLayout;
import javax.swing.JPanel;
/**
*
* @author Dchan(Dulitha Wijewantha)
*
@dulichan
dulichan / connection.py
Created December 5, 2012 18:55
Python connection to postgres database
import psycopg2
import sys
connection = None
try :
connection = psycopg2.connect(database='postgres', user='test', host='localhost')
cur = connection.cursor()
cur.execute('SELECT version()')
ver = cur.fetchone()
@dulichan
dulichan / FrameGrab.java
Created December 10, 2012 09:54
Grabbing a Photo from web cam from Java
package com.test.frame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
@dulichan
dulichan / notify.py
Created December 10, 2012 09:58
Fedora Notification Wrapper for simple notification
try:
import gtk, pynotify
pygtk.require('2.0')
except:
print "Error: need python-notify, python-gtk2 and gtk"
class NotificationWrapper:
def __init__(self, title="Testing Title", message="Testing message"):
self.title = title
self.message = message
def showNotification(self):