Friday, June 12, 2015

Working offline with Maven

While working with projects managed by maven you could run into issues where you have to disconnect your development environment from the internet and continue to work on the code. The experience i had was i had to debug a system deployed to a customer network which had no internet access. I suddenly realized my development environment on my laptop was completely useless. Pretty bad when there are people standing behind you and waiting for you to resolve their problem.

The solution is downloading the maven dependencies to your local by executing below command from the same directory where your pom file is located.

[rozaydin@RO]$ mvn dependency:go-offline

Maven will download all dependencies your project needs and you could be able to continue working with no need to internet access.

Saturday, June 6, 2015

Ucuz Elektrik


Türkiye'de elektrik tarifeleri 3 zamanlı olarak ücretlendirilmekteler. Bu zaman (tarife) dilimleri aşağıda listelenmiştir.

Gündüz (T1)      : 06:00 – 17:00
Puant (T2)          : 17:00 – 22:00
Gece (T3)           : 22:00 – 06:00

En ucuz elektrik 22.00 - 06.00 arasında satılırken en pahalı elektril 17.00 - 22.00 saatleri arasında satılmakta. Hali hazırda geçerli olan ücret tarifelerine göre "Mesken" tipi abonelerin tarifeleri aşağıda listelenmiştir. 


Mesken:

Gündüz: 19,7183
Puant:     35,8753 
Gece:      8,0527 

Görüldüğü gibi en ucuz zaman dilimi GECE tarifesi olmaktadır. Eğer enerji tüketimimizin tamamını gece tarifesi üzerinden yaparsak harcadığımız aynı enerji miktarı için 3 kat daha az ödüyoruz. Basit bir örnek verir ise ortalama enerji faturamız aylık 60 lira ise ödeyeceğimiz rakam 20 liraya düşüyor. 1 sene içerisinde yapacağımız tasarruf miktarı 40 x 12 = 480 lira. Az bir rakam değil. 

Peki enerji tüketimimizin tamamını GECE tarifesi üzerinden yapmak mümkün mü ? Eğer enerjiyi depolayabilir isek evet mümkün. Büyükçe şarj edilebilir bir pilimiz olduğunu düşünün, Tarifenin en ucuz olduğu zaman diliminde kendi kendisini otomatik şarj ediyor ve diğer zaman dilimlerinde ise bu pildeki enerjiyi evimizde kullanıyoruz harcadığımız elektrik miktarını kısmadan ciddi miktarda tasarruf sağladık.

İşte bu şekilde şarj edilebilir bir pil artık var. Elektrikli araçları ile ünlü Amerikan "Tesla" şirketi Power Wall adlı ürün ile karşımızda. Power Wall evinizin duvarına monte ettirebileceğiniz oldukça şık bir ürün. Ancak ürünün fiyatı biraz yüksek 3000$ ve 3500$ fiyat etiketine sahip ki Türkiye standartları için bu ciddi bir rakam. Ancak bu ürünlerin muadilleri daha uygun fiyat etiketi ile çok kısa sürede pazara sürülecektir. Bu durumda daha satın alınabilir bir etiket ile elektrik faturalarımızı ciddi miktarda düşürebilir olacağız.

Monday, May 11, 2015

Latitude Longitude Boundaries on World Map


You might have encountered situations where you wanted to get the latitude and longitude boundaries of an rectangular area on world map, I have put together a simple js application using leaflet js and leaflet.draw plugin to provide the functionality.

  1. You can access the hosted application from here. 
  2. You can access the sources from here. 
Enjoy and please comment if you encounter any issues.


Figure 1 - Boundary Application



Wednesday, May 6, 2015

How to kill multiple processes from terminal with single line

You might encounter situations where you need to kill group of processes, such as when google-chrome is running. Chrome spawns multiple processes and you might want to shut it down from terminal.

[rozaydin@RO ~]$ ps -e | grep chrome
 5017 ?        00:00:01 chrome
 5027 ?        00:00:00 chrome-sandbox
 5028 ?        00:00:00 chrome
 5033 ?        00:00:00 chrome-sandbox
 5036 ?        00:00:00 chrome
 5055 ?        00:00:00 chrome
 5083 ?        00:00:00 chrome
 5091 ?        00:00:00 chrome
 5107 ?        00:00:00 chrome
 5111 ?        00:00:00 chrome
 5115 ?        00:00:00 chrome
 5123 ?        00:00:00 chrome
 5131 ?        00:00:00 chrome
 5139 ?        00:00:00 chrome
 5142 ?        00:00:00 chrome
 5154 ?        00:00:00 chrome
 5160 ?        00:00:00 chrome
[rozaydin@RO ~]$
 

Killing these processes  one by one is a tedious task instead you can use below command the kill them with one single line. (Bird massacre with single stone)


ps -e | grep <processname> | awk '{system("kill -9 "$1)}'


[rozaydin@RO ~]$ ps -e | grep chrome | awk '{system("kill -9 "$1)}'
sh: line 0: kill: (5033) - No such process
sh: line 0: kill: (5036) - No such process
sh: line 0: kill: (5055) - No such process
sh: line 0: kill: (5083) - No such process
sh: line 0: kill: (5107) - No such process
sh: line 0: kill: (5111) - No such process
sh: line 0: kill: (5115) - No such process
sh: line 0: kill: (5123) - No such process
sh: line 0: kill: (5131) - No such process
sh: line 0: kill: (5139) - No such process
sh: line 0: kill: (5142) - No such process
sh: line 0: kill: (5154) - No such process
sh: line 0: kill: (5160) - No such process
[rozaydin@RO ~]$
[rozaydin@RO ~]$ ps -e | grep chrome
[rozaydin@RO ~]$

Tuesday, March 24, 2015

How to list rpm dependencies


You can easily list the dependencies the rpm file requires prior installation, this is particularly useful when you are shipping your rpms in a removable media this way you can ensure you have provided all the dependencies.

Open a terminal and type below command,

rpm -qpR name_of_rpm

You will see output like below;

/bin/sh
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
...

Wednesday, March 4, 2015

Building Berkeley DB XML for CentOS systems



Go to this link and download Berkeley DB XML. Version used in this guide is "6.0.17". Once the download complete, unzip the file.

[rozaydin@RO Tutorials]$ ls
dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ tar -xzf dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ ls
dbxml-6.0.17  dbxml-6.0.17.tar.gz
[rozaydin@RO Tutorials]$ cd dbxml-6.0.17/
[rozaydin@RO dbxml-6.0.17]$ ls
buildall.sh  db-6.1.19  dbxml  README  xerces-c-src  xqilla
[rozaydin@RO dbxml-6.0.17]$

 DB XML uses  XQilla which is an XQuery and XPath 2 library implemented on top of the  Xerces-C. DB XML requires Berkeley DB as well. So before using it we need to install each of the following dependencies in the following order;
Build and install Berkeley-DB
Build and install Xerces
Build and install XQuilla
Build and install XML-DB
DB XML compilation failed to compile with java 8 switching to java version "1.7.0_72" compilation completed with no errors. Open a terminal switch to root user and set JAVA variables. (PLEASE note you need to use this same terminal for all commands listed below)

[rozaydin@RO dbxml-6.0.17]$ pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17
[rozaydin@RO dbxml-6.0.17]$ su -
Password:
Last login: Wed Mar  4 12:19:38 EET 2015 on pts/0
[root@RO ~]# export JAVA_HOME=/usr/java/jdk1.7.0_72
[root@RO ~]# export PATH=$JAVA_HOME/bin:$PATH
[root@RO ~]# cd /home/rozaydin/Desktop/Tutorials/dbxml-6.0.17
[root@RO dbxml-6.0.17]#

Now proceed with building Berkeley DB with configure, make, make install use following commands;

[root@RO dbxml-6.0.17]# ls
buildall.sh  db-6.1.19  dbxml  README  xerces-c-src  xqilla
[root@RO dbxml-6.0.17]# cd db-6.1.19/
[root@RO db-6.1.19]# ls
build_android  build_vxworks  build_windows  docs      lang     README  test
build_unix     build_wince    dist           examples  LICENSE  src     util
[root@RO db-6.1.19]# cd build_unix/
[root@RO build_unix]# ../dist/configure --enable-cxx --enable-java
[root@RO build_unix]# make
[root@RO build_unix]# make install

When operation completes this will install Berkeley DB to /usr/local/BerkeleyDB.6.1 directory. Change directory back to where you unzipped XML DB.

[root@RO build_unix]# cd /usr/local/BerkeleyDB.6.1
[root@RO BerkeleyDB.6.1]# ls
bin  docs  include  lib
[root@RO BerkeleyDB.6.1]# cd /home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/
[root@RO dbxml-6.0.17]# pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17

After this step proceed with building XERCES library.

[root@RO dbxml-6.0.17]# cd xerces-c-src/
[root@RO xerces-c-src]# ls
config        CREDITS  LICENSE      NOTICE    samples  version.incl
config.h.in   doc      m4           projects  scripts  xerces-c.pc.in
configure     INSTALL  Makefile.am  README    src      xerces-c.spec
configure.ac  KEYS     Makefile.in  reconf    tests
[root@RO xerces-c-src]# ./configure
[root@RO xerces-c-src]# make
[root@RO xerces-c-src]# make install

When operation completes this will install XERCES library to /usr/local/bin directory. You should see similar output as below:

test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
  /bin/sh ../libtool   --mode=install /bin/install -c CreateDOMDocument DOMCount DOMPrint EnumVal MemParse PParse PSVIWriter Redirect SAX2Count SAX2Print SAXCount SAXPrint SCMPrint SEnumVal StdInParse XInclude '/usr/local/bin'
libtool: install: /bin/install -c .libs/CreateDOMDocument /usr/local/bin/CreateDOMDocument
libtool: install: /bin/install -c .libs/DOMCount /usr/local/bin/DOMCount
libtool: install: /bin/install -c .libs/DOMPrint /usr/local/bin/DOMPrint
libtool: install: /bin/install -c .libs/EnumVal /usr/local/bin/EnumVal
libtool: install: /bin/install -c .libs/MemParse /usr/local/bin/MemParse
libtool: install: /bin/install -c .libs/PParse /usr/local/bin/PParse
libtool: install: /bin/install -c .libs/PSVIWriter /usr/local/bin/PSVIWriter
libtool: install: /bin/install -c .libs/Redirect /usr/local/bin/Redirect
libtool: install: /bin/install -c .libs/SAX2Count /usr/local/bin/SAX2Count
libtool: install: /bin/install -c .libs/SAX2Print /usr/local/bin/SAX2Print
libtool: install: /bin/install -c .libs/SAXCount /usr/local/bin/SAXCount
libtool: install: /bin/install -c .libs/SAXPrint /usr/local/bin/SAXPrint
libtool: install: /bin/install -c .libs/SCMPrint /usr/local/bin/SCMPrint
libtool: install: /bin/install -c .libs/SEnumVal /usr/local/bin/SEnumVal
libtool: install: /bin/install -c .libs/StdInParse /usr/local/bin/StdInParse
libtool: install: /bin/install -c .libs/XInclude /usr/local/bin/XInclude

After this step proceed building XQuilla library (PLEASE note that you need to provide the xerces-c-src directory using ABSOLUTE path not doing so will fail the compilation)

[root@RO xqilla]# ./configure --with-xerces=/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/xerces-c-src
[root@RO xqilla]# make
[root@RO xqilla]# make install

When operation completes this will install XQuilla library to /usr/local/lib directory.
The last step involves building XML DB in dbxml directory type below commands:

[root@RO dbxml]# pwd
/home/rozaydin/Desktop/Tutorials/dbxml-6.0.17/dbxml
[root@RO dbxml]# cd build_unix/
[root@RO build_unix]# ../configure --enable-java --with-berkeleydb=/usr/local/BerkeleyDB.6.1 --with-xqilla=/usr/local/lib
[root@RO build_unix]# make
[root@RO build_unix]# make install

When operation completes this will install XML DB to /usr/local/BerkeleyDBXML.6.0/ directory. Verify the installation by typing below commands

[root@RO build_unix]# cd /usr/local/BerkeleyDBXML.6.0/
[root@RO BerkeleyDBXML.6.0]# ls
bin  include  lib
[root@RO BerkeleyDBXML.6.0]# cd bin
[root@RO bin]# ls
dbxml  dbxml_dump  dbxml_load  dbxml_load_container
[root@RO bin]# dbxml
bash: dbxml: command not found...
[root@RO bin]# ./dbxml
dbxml>

if you see the prompt you are good :)



Sunday, February 8, 2015

sample pom.xml file for javaee rest application

here is the sample pom file i most of the time use to form the basis of my java web application projects. I use slf4j with logback for logging, mockito, junit and jersey test framework for testing and google gson for json conversion.

  
  
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo application</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
            <scope>provided</scope>
        </dependency>       
        
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>            
            <version>2.3.1</version>
        </dependency> 
        
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.10</version>
        </dependency> 

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency> 

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.2</version>
        </dependency>
        
        <!-- Test -->
        <!-- https://jersey.java.net/documentation/latest/user-guide.html#d0e15523 -->
        <dependency>
            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
            <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
            <version>2.15</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>            
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>  
            <scope>test</scope>          
        </dependency>
                        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>