Skip to main content

Posts

Showing posts from October, 2012

Unix - useful command line tools

This post lists unix command line tools which are very helpful during a work with these systems. alias create alias for a command // use aliast to a command alias ls='ls -ltr' awk // split text into tokens using '.' separator echo testFile.txt | awk -F'.' '{print$2}' // prints 'txt' chmod set access privileges to a file // owner rwx, group r-x, others --- chmod 750 fileName.txt Meaning of numbers: owner, group, others (respectively) 4 - read 2 - write 1 - execute find search for files // search for all files in a current directory and display lines with a 'stringToFind' find . -name "*.*" | xargs grep 'stringToFind' // search for a file and skipp all info about errors find . -name 'testFile.txt' 2> /dev/null grep use regexp to display lines from a file // display all lines without a # sign grep ^[^#] testFile.txt // display all lines with a # sign grep ^# testFile.txt gzip compress and decompre

SQL - useful statements

1. Statements ---list databases SHOW DATABASES; --select a database to work with USE test; --list tables in a database SHOW TABLES; --list tables in a database which name contains 'someText' SHOW TABLES LIKE '%someText%'; --create new database CREATE DATABASE test; --create new table with 2 columns 'id' and 'name' CREATE TABLE test (id int [NULL| NOT NULL], name varchar(20) [NULL| NOT NULL]); --create new view CREATE VIEW mini AS SELECT id FROM test; --create new index (unique index doesn't allow duplicates) CREATE [UNIQUE] INDEX index_id ON test(id); --add new column to a table ALTER TABLE test ADD surname varchar(20) NOT NULL; --insert a record into a table INSERT INTO test VALUES val1, val2, val3; --insert an value into a row INSERT INTO test(coulumnName) VALUES value; --insert into a table values from other table INSERT INTO test(id, name, surname) SELECT id2, name2, surname3 FROM anotherTest WHERE id = 8; --select values from a t

Iterator allows to remove elements during iteration

With a for each loop you can iterate easily through a collection but you cannot remove elements during iteration. List<String> list = new ArrayList<String>(); list.add("Max"); list.add("bob"); list.add("Alex"); // for each loop: // execution this loop ends with a // java.util.ConcurrentModificationException for (String element : list) { list.remove(element); } A java.util.Iterator is a suitable solution for the above situation, because it allows you to remove elements from a collection during iteration. Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) { iterator.next()); iterator.remove(); } Iterator interface has three methods: boolean hasNext() E next() void remove() and allows for iteration in a one direction. If you want to iterate through a list in both directions you should use a ListIterator (implements Iterator) which has additional methods: boolean hasPrevious() E previous() int previousI

java command line tools (java, javac, jar)

javac used to compile source files (*.java) javac [-options] files java used to run a compiled code (*.class) java [-options] class [args...] jar used to archive files into JAR (*.jar) jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files In practise: Source for Hello.java package com.blogspot.programmerutilities; public class Hello { public static void main (String[] args){ System.out.println("Hello World!"); } } Location of the file: \src\com\blogspot\programmerutilities\Hello.java Directory structure: -src -com -blogspot -programmerutilities -Hello.java -build Compile source file using javac (-d option points to a directory where compiled files will be placed) javac -d build \src\com\blogspot\programmerutilities\Hello.java After compilation a Hello.class file will be placed in \build directory (and subdirectories accordingly to the package name). -src -com -blogspot -programmerutilitie

sqlplus used in perl

sqlplus is a command line tool used to work with an Oracle database. #!/bin/perl my $sqlString ='sqlplus -s user/pass@SID << END set heading off set echo off set feedback off set pagesize 0'; $sqlString = "$sqlString\nSELECT 'test' FROM dual;"; my $result; = `$sqlString`; print $result; usage: sqlplus [-s] user/pass@SID -s parameter enables a silent mode. Only result of statement executions will be returned to a standard output (data like 'SQL>' prompt or a connection confirmation will be skipped) To disable a default human-redable format of returned data the following parameters are set: heading, echo, feedback, pagesize.

IT acronyms

ACID Atomic Consistency Isolation Durability API Application Programming Interface CMP Container-Managed Persistence CMT Container-Managed Transactions CORBA Common Object Request Broker Architecture CRUD Create Read Update Delete DNS Domain Name System EIS Enterprise Information System IDE Integrated Development Environment IDL Interface Description\Definition Language IIOP Internet Inter-ORB Protocol IT Information Technology JAXB Java Architecture for XML Binding JAXBRI Java Architecture for XML Binding Reference Implementation JAXP Java API for XML JCA Java Connector Architecture JDBC Java Database Connectivity JDK Java Development Kit JMS Java Message Service JNDI Java Naming and Directory Interface JNI Java Native Interface JPA Java Persistent API JTA Java Transaction API JTS Java Transaction Service LAN Local Area Networks LDAP Lightweight Directory Access Protocol MEP Message Exchange Patterns MTOM Message Transmission Opti

Eclipse - shortcut keys

ctrl + O outline current class ctrl + L go to line ctrl + 3 entry point of everything ctrl + shift open resource ctrl + 1 quick fix (for example add import) ctrl + shift + o add all imports ctrl + shift + m add import ctrl + 2, L assign to local variable alt + shift + R rename ctrl + . next error ctrl + , prevoius error ctrl + m maximize text editor alt + shift + m extract method alt + shift + l extract local variable shift + enter new line before ctrl + shift + enter new line after ctrl + F3 outline selected class F3 open decalration (go to parent class) ctrl + H File search (rebinding) ctrl + shift + J generate javadoc F10 go to main menu bar shift + F10 context menu F12 activate editor shift + G find references in project ctrl + shift + G find references in workspace ctrl + shift + U find references in file ctrl + D delete line alt + up arrow move row or selection up alt + dow

ShutDownHook - the last breath of an application

ShutDownHook allows you to perform operations (e.g. close opened resources, remove temporary files and so on) just before virtual machine shuts down. A documentation says that JVM may shut down in two cases: program finishes execution normally when all threads finishes their work (except deamon-threads like garbage collector) virtual machine receives a termination signal (for example after sending kill signal under unix or ctrl + C key combination under windows) Below is an example which will start endless loop which do nothing. But an important thing in this code is a part where shutDownHook is added. When an termination signal will be send to JVM a code from a run() method will be executed just before JVM shuts down. public class ShutDownHook { public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Close opened resources"); } }); while (true) { // do nothing } } }