Showing posts with label DEVELOPMENT. Show all posts
Showing posts with label DEVELOPMENT. Show all posts

Friday, September 19, 2014

Pagination With Oracle In JPA Native Query

Pagination in MySQL or PostgreSQL with limit is very easy. But Oracle doesn't support limit. So, in oracle generating paging query is a real trick.
Finally found a nice solution. With this piece of code generation pagination query is like charm. So have fun with this.














AUTHOR:OBSCURE

Wednesday, December 5, 2012

Serial Port Communication From Java - RxTx Installation.

Want to communicate with serial port using Java? You may want to try RxTx library. It's easy to use.
To install follow the instruction below:

The official RxTx binary pack is available here. The provided link will download the distro with some standard binaries (for linux 32bit, 64 bit, etc). If binaries for your specific operating system are not included, you may consider recompiling RxTx yourselves.
For a custom Win64 RxTx distro, have a look at the CloudHopper's web site.
To install it, unzip the distribution file in a temporary place and do the following copies:
  • File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
  • The necessary library( .so for linux, .dll for windows) should go under JDKDIR/jre/bin/
AUTHOR: OBSCURE

Friday, November 23, 2012

Sending SMS via USB Connected Cell Phone with Python

import serial
import time
class SMSsender:
    def __init__(self):
        self.destination = ""
        self.msg = ""

    def setRecipient(self, dest):
        self.destination = dest

    def setContent(self, message):
        self.msg = message

    def connectPhone(self):
        #replace '/dev/ttyACM0' with your device name
        #replace 460800 with a suitable baud-rate of your phone 
        self.ser = serial.Serial('/dev/ttyACM0', 460800, timeout=2)
        time.sleep(1)

    def sendMessage(self):
        self.ser.write('ATZ\r')
        time.sleep(1)
        self.ser.write('AT+CMGF=1\r')
        time.sleep(1)
        self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
        time.sleep(1)
        self.ser.write(self.content + "\r")
        time.sleep(1)
        self.ser.write(chr(26))
        time.sleep(1)

    def disconnectPhone(self):
        self.ser.close()
To send sms use this follow the code below:
sms = SMSsender()
sms.setRecipient('+8801*********')
sms.setContent('Write your message here')
sms.connectPhone()
sms.sendMessage()
sms.disconnectPhone()
You may also try this link(I've not tested yet): sms-over-3g-and-bluetooth-from-python
Source: linux-101.org

Monday, November 5, 2012

Python - Coding with fun

How to reverse a string?

s = 'abcdef'
s = s[::-1]
print s 
Explanation: "::" is known as stride notation
s[::2]
s[::-2]
Returns "ace" and "fdb" respectively.

How to read from console in Python?
name = raw_input()

Want to read an integer?
num = raw_input()
num = int(num) # raw_input returns string, so convert it to integer

Swap values in python:
a, b = b, a

My motivation to learn python is: life is short - you need Python

Saturday, October 13, 2012

Installing Apache Maven-Java tool

Download maven.

Windows OS:


  1. Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.
  2. Add the M2_HOME environment variable. [almost similar as this]: adding the M2_HOME variable in the system variables with the value                                                                                      C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces.
  3. In the same dialog, add the M2 environment variable in the system variables with the value %M2_HOME%\bin.
  4. In the same dialog, update/create the Path environment variable in the system variables and prepend the value %M2% to add Maven available in the command line.
  5. In the same dialog, make sure that JAVA_HOME exists in your system variables and it is set to the location of your JDK, e.g.C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
  6. Open a new command prompt and run mvn --version to verify that it is correctly installed.



Linux based/Ubuntu Operating Systems:


  1. Extract the distribution archive, to the directory you wish to install Maven 3.0.4. These instructions assume you chose /home/username/java/tools/maven.
  2. Open terminal and type:  gedit ~/.bashrc
  3. Set environment variable by adding the following lines at the bottom of .bashrc :
    •  export M2_HOME=/home/username/java/tools/maven
    • export M2=$M2_HOME/bin
    • export PATH=$M2:$PATH
    • export JAVA_HOME=/usr/lib/jvm/jdk-default #if JAVA_HOME not exist.
  4. Run mvn --version to verify that it is correctly installed.

Tuesday, October 9, 2012

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info

Send and receive SMS using GSM modem or phone on Ubuntu | TechyTalk.info.

#go to terminal and give the msg as below
#sudo python sms.py 'CellNumber Msg you want to send'
import gammu
import sys

def main():
    words = sys.argv[1].split(None, 1)
    dest = words[0]
    msg = words[1]
    print msg + "-----" + dest
    #return

    sms = gammu.StateMachine()
    sms.ReadConfig()
    sms.Init()

    message = {
        'Text': msg,
        'SMSC': {'Location': 1},
        'Number': destinationNumber,
    }
    print sms.SendSMS(message)

if  __name__ =='__main__':
    main()

Thursday, September 20, 2012

How to create non-editable JTable:

Override the method "isCellEditable" and implement as needed, such as:

//instance table model
DefaultTableModel tableModel = new DefaultTableModel(){
    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
};
//...other codes
table.setModel(tableModel);

Tuesday, September 18, 2012

System.getProperty(key) key list for JAVA:

java.versionJava Runtime Environment version
java.vendorJava Runtime Environment vendor
java.vendor.urlJava vendor URL
java.homeJava installation directory
java.vm.specification.versionJava Virtual Machine specification version
java.vm.specification.vendorJava Virtual Machine specification vendor
java.vm.specification.nameJava Virtual Machine specification name
java.vm.versionJava Virtual Machine implementation version
java.vm.vendorJava Virtual Machine implementation vendor
java.vm.nameJava Virtual Machine implementation name
java.specification.versionJava Runtime Environment specification version
java.specification.vendorJava Runtime Environment specification vendor
java.specification.nameJava Runtime Environment specification name
java.class.versionJava class format version number
java.class.pathJava class path
java.library.pathList of paths to search when loading libraries
java.io.tmpdirDefault temp file path
java.compilerName of JIT compiler to use
java.ext.dirsPath of extension directory or directories
os.nameOperating system name
os.archOperating system architecture
os.versionOperating system version
file.separatorFile separator ("/" on UNIX)
path.separatorPath separator (":" on UNIX)
line.separatorLine separator ("\n" on UNIX)
user.nameUser's account name
user.homeUser's home directory
user.dirUser's current working directory



Monday, April 9, 2012

Generics are not supported in -source 1.3 error in Maven Project

When compiling via maven project, you may have encountered following error:
generics are not supported in -source 1.3 error in Maven Project. use -source 5 or higher to enable generics.

Annotation is not allowed in -source 1.3 use -source 5 or higher to enable annotation.

To solve this you must add the below lines at your pom.xml :


    
        
            org.apache.maven.plugins
            maven-compiler-plugin
            
                1.5</source>
                1.5
            
         
    

Tuesday, January 17, 2012

C++ : keywords

32 keywords defined by standard C.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

A list of some commonly used extended keywords:
asm  _cs  _ds  _es
_ss  cdecl  far  huge
interrupt  near  pascal

All C (and C++) keywords are lowercase. Also, uppercase and lowercase are
different: else is a keyword; ELSE is not.

Saturday, July 2, 2011

Basic Programming Knowledge, What to know before interviews??

1. Basic programming on
  • string processing, 
  • recursion,
  • number theory etc.
2. Data Structures -
  • Stack, 
  • Queue,
  • Linked list etc,
3. Algorithms-
  • Searching, 
  • sorting, 
  • DFS, 
  • BFS, 
  • shortest path etc
4. OOP programming concept
5. Database concepts:

  • Very typical database orientated questions like
    • joining, 
    • normalization,
    • De normalization
  • Query writing using joining -
    • inner join, 
    • outer join, 
    • left outer join etc.
  • Design E-R diagram of a small system like result processing
6. Questions on projects that you've done so far at your university & in your professional life.
7. Asp.Net/C#/Vb.Net
8. Sql Server 2000 or 2005:
9. Basic knowledge on SS 2000 or 2005
10. Write down
  • stored procedures, 
  • views,
  • functions & 
  • cursors to use them in projects.