GoogleMaps API multiple markers

I have a database with some records that among other details they also declare a local (Greek) street addresses. The requirement is to retrieve all these records from the database and display them with markers on a Google Map. Before everything, if you want to get an idea on how the API works see the following links:

GoogleMaps API – Getting started
GoogleMaps API – Simple markers

The flow for my task has as follows:

– Connect to database
– Retrieve all the locations from DB
– Convert Greek characters to Latin for avoiding issues with the Web Service request [ code on code.loon.gr ]
– Use GoogleMaps API to retrieve GPS coordinates based on the given location
– Parse JSON response
– Use JavaScript to add the markers layers

Full code on GitHub.

 

Advertisement

Java HTTP library

Being in need to issue POST requests from within a Java application, and wanting re-usable code, I created a very simple Java library for issuing POST and GET requests to a remote server.

POST source codeGET source code

Usage (POST example):

POST post = new POST();
post.postRequest("http://www.myservice.com/service", "param1=foo&param2=bar", "Mozilla/5.0");

In other words, the arguments are:

post.postRequest(SERVER_URL, PARAMETERS, AGENT);

The output can be manipulated as desired, depending on what you response you except you should use a corresponding element/object.

Java libary in Android project

If you have developed your Java library that you would like to use within your Android project, or you want to use an existing Java library, make sure that the library itself is compiled with Java 1.6 rather than 1.7. Have been always forgetting that and have wondering for a couple of days why am I getting “NoClassDefFoundError” error.

Assigning HTML “rel” attribute to all page images

Very briefly, in a CakePHP app, I want to apply the lightbox script on all the images that link from a thumbnail to a larger image. If there are more than two, I want them to appear as a lightbox group. I don’t want the user to mess with TinyMCE and HTML, therefore I automatically apply the rel attributed for every single image in a page that is a hyperlink. The following PHP bit is added in app/Plugin/Nodes/View/Nodes/view.ctp. With some small changes it can be used for any PHP compatible web site.

$body = $this->Nodes->body();
if (strpos($body, "img")) {
   $pattern ="/<a(.*?)href=('|\")(.*?).(jpeg|jpg|png)('|\")(.*?)>/i";
   $newLink = '<a$1href=$2$3.$4$5 rel="lightbox[group]".$6>';
   echo preg_replace($pattern, $newLink, $body);
} else {
   echo $body;
}

Java encrypt class

A simple implementation of an encryption class to be used in Java applications for either encrypting strings and calculating files’ fingerprint.

import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Encrypt {

   private FileInputStream fis;

   public Encrypt() { }

   public String encryptString(String input, String salt, String algorithm) {
      String output = null;
      String fullInput = null;

      if (!salt.equals(null)) {
         fullInput = salt + input;
      } else {
         fullInput = input;
      }

      try {
         MessageDigest digest = MessageDigest.getInstance(algorithm);
         digest.update(fullInput.getBytes(), 0, fullInput.length());
         output = new BigInteger(1, digest.digest()).toString(16);
      } catch (NoSuchAlgorithmException ex) {
         ex.printStackTrace();
      }
      return output;
   }

   // Based on: http://www.mkyong.com/java/how-to-generate-a-file-checksum-value-in-java/
   public String calculateFingerprint(String fileName, String algorithm) {
      StringBuffer sb = new StringBuffer();
      try {
         MessageDigest md = MessageDigest.getInstance(algorithm);
         fis = new FileInputStream(fileName);
         byte[] dataBytes = new byte[1024];
         int nread = 0;
         while ((nread = fis.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); }
         byte[] mdbytes = md.digest();
         for (int i = 0; i < mdbytes.length; i++) {
            sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
         }
      } catch (Exception ex) {
         ex.printStackTrace();
      }
      return sb.toString();
   }
}

Link to GiHub repository. The class is intended to be used as a library within Java applications.

Example for encrypting a string:

Encrypt en = new Encrypt();
String encryptedString = en.encryptString(textField.getText().toString(), \
"salt goes here if you want", "md5")));

Example for calculating the fingerprint of a file:

Encrypt en = new Encrypt();
String fingerPrint = en.calculateFingerprint("/path/to/file", sha1);

Android SQLite Adapter class

Working with an SQLite database on Android can require some times more effort than what you should really give. For instance, if you ship a pre-configured and populated database with an application, you would need first to copy over the database to the specific database directory and then open it for reading and/or writing data to it. The SQLiteOpenHelper class provides a few methods that make life a bit easier but it does not provide a copy method for handling this issue. In addition to this, a check method would be required before copying the database and so on. Following on this, I implemented a SQLite adapter class to cover my needs as bellow:

– Copy database to the correct directory.
– Open and close the database.
– Execute raw SQL query.
– Execute SQL query for string, int, long, double.
– Drop table.
– Return count of a table.
– Download a db copy from Internet and replace local one.

Source code at GitHub.

HPC-Europa2 Virtual Cluster liveDVD – milestone6 (final release)

The JRA2 team is proud to announce the release of HPC-Europa2 live DVD milestone 6. You can download milestone 6 ISO image (compressed with size 1.7 GB) from the below links:

CINECA (Italy) – http://www.hpc-europa.eu/?q=node/142
EPCC (Scotland) – http://hpce2jra2.epcc.ed.ac.uk/milestone6.iso.gz
HLRS (Germany) – https://fs.hlrs.de/projects/live-ptd/iso/milestone6.iso.gz

Release Note for Milestone 6
============================
The Virtual Cluster liveDVD:
* provides tools and libraries that are installed and used at the partner sites.
* emaulates the environment of the platforms available at HPC-Europa centers.
* allows hands-on building of a virtual cluster.

The liveDVD contains training and dissemination material published by the
HPC-Europa2 project, including material from the partner centers such as slides,
video tutorials and example code. Optional access to a source code repository enables
the migration of code and data from the Virtual Cluster to the user account created
on the HPC-Europa machines.

The liveDVD is based on SliTaz GNU/Linux, a free operating system, working completely
in RAM and booting from a removable media. The file size of the SliTaz GNU/Linux
3.0 ISO image is 29 MB. Hence, it leaves plenty of space for adding tools, libraries
and training material into this liveDVD. The SliTaz system is quick, responsive, and clean.
A lightweight and elegant desktop is included as well in the 29MB ISO image.

The milestone 6 ISO image has roughly the size of 3.8 GB including several tools
and libraries, as well as training material. Moreover, it contains a documentation
of how to build a virtual cluster using VirtualBox, and HPC-Europa2's Science and
Supercomputing in Europe research highlights for 2009 and 2010. Finally, this milestone
release addresses several bug fixes, such as firefox with flash support and
build scripts for Torque.

Since the previous release (milestone 5), existing packages have been updated, such as:
* MPICH2 to version 1.4.1p1
* Firefox to version 9.0.1 with flash support.
* Paraver to support the updated version of MPICH2.

In addition, this release has added several new packages:
* lava-1.0.6: Platform Lava - an open source version of Platform Load Sharing Facility (LSF).
* info (texinfo-4.13a) and man pages (man-db-2.6.0.2 and man-pages-3.35) for Linux documentation.
* Abiword and Gnumeric for office word documents and spreadsheets.
* Compiler wrappers (based on gcc and gfortran) to emulate Intel, IBM and NEC SX compilers.

You can download milestone 6 ISO image (compressed - size 1.7 GB) from the below link:
    http://www.hpc-europa.eu/?q=node/142

System Requirements
===================
* A laptop or computing with a DVD drive.
* Intel or AMD processor with a hardware virtualization support when using KVM
  and libvirt. Otherwise, this liveDVD can be run under VirtualBox or VMware or similar.

Known Issues
============
* PGI compilers require a license file in order to work (not included in this milestone).
* Totalview requires a license file in order to work (not included in this milestone).
  For requiring a demo license visit:
  http://www.roguewave.com/products/totalview-family/totalview.aspx
* On a MacBook Pro laptop, the mousepad does not work. Need to use an USB mouse
* Resizing video screen on VLC causes an unexpected exit of the program.
* VLC has no sound for viewing mkv videos.
* VLC cannot stream files or view incoming streams.

Acknowledgement
===============
This work was carried out under the HPC-EUROPA2 project (project number: 228398),
with the support of the European Community - Research Infrastructure Action of the FP7.

Shell script for NITROX calculations

The following script was developed for providing quick calculations over NITROX diving. It provides an interactive menu for the following calculations:

1 – Maximum Operational Depth (MOD)
2 – Operational Depth (OD)
3 – Best mix
4 – Equivelant Air Depth (EAD)
5 – Nitrogen percentage compared to Air
6 – Oxygen partial pressure (PO2)
7 – Central Nervous Systems Toxicity (CNS)
8 – Absolute pressure

############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################
#!/bin/bash

disclaimer()
{
echo "
=======================================================
Every individual diver is responsible for planning
and conducting dives using SCUBA equipment up to the
trained and certified qualification he or she holds.

The creator of this program does not have any
responsibility for symptoms of Decompressions Sickness
when the suggested values of this program are used
for conducting a dive.
========================================================
"
}
mod(){
   echo -n "NITROX mix: "; read mix
   MOD=`echo "scale=2; (((1.6/$mix)*10)*100)-10" | bc`
   echo " MOD for $mix NITROX: $MOD"
}

od(){
   echo -n "NITROX mix: "; read mix
   OD=`echo "scale=3; (((1.4/$mix)*10)*100)-10" | bc`
   echo " OD for $mix NITROX: $OD"
}

bestmix(){
   echo -n " Depth: "; read depth
   BESTMIX4=`echo "scale=2; 1.4/(($depth/10)+1)" | bc`
   BESTMIX6=`echo "scale=2; 1.6/(($depth/10)+1)" | bc`
   echo " Best mix for 1.4 PO2: $BESTMIX4"
   echo " Best mix for 1.6 PO2: $BESTMIX6"
}

ead(){
   echo -n " Depth: "; read depth
   echo -n " NITROX: "; read nitrox
   EAD=`echo "scale=2; ((((1-($nitrox/100))*4)/0.79)-1)*10" | bc`
   echo " EAD for $depth MSW and NITROX $nitrox: $EAD"
}

compare(){
   echo -n " NITROX: "; read nitrox
   EQU=`echo "scale=2; 100-(((1-($nitrox/100))/0.79)*100)" | bc`
   echo " ${EQU}% less nitrogen"
}

po2(){
   echo -n " Depth: "; read depth
   echo -n " NITROX: "; read nitrox
   PO2=`echo "scale=2; (($depth+10)/10)*($nitrox/100)" | bc`
   echo " PO2 at $depth MSW for NITROX $nitrox: $PO2 ATM"
}

cns(){
   echo -n " PO2 [1.4, 1.5, 1.6]: "; read po2
   echo -n " Duration: "; read duration
   if [ "$po2" == "1.4" ]; then
      CNS=`echo "scale=2; ($duration/150)*100" | bc`
   elif [ "$po2" == "1.5" ]; then
      CNS=`echo "scale=2; ($duration/120)*100" | bc`
   elif [ "$po2" == "1.6" ]; then
      CNS=`echo "scale=2; ($duration/45)*100" | bc`
   else
      echo " Choose between 1.4, 1.5 and 1.6 PO2"
      exit 1
   fi
   echo " CNS for $duration minutes and $po2 PO2: ${CNS}%"
}

absolute(){
   echo -n " Depth: "; read depth
   ABS=`echo "scale=2; (($depth/10)+1)" | bc`
   echo " Absolute pressure at depth of $depth MSW: $ABS ATM"
}

echo " 1 - Maximum Operational Depth (MOD)"
echo " 2 - Operational Depth (OD)"
echo " 3 - Best mix"
echo " 4 - Equivelant Air Depth (EAD)"
echo " 5 - Nitrogen percentage compared to Air"
echo " 6 - Oxygen partial pressure (PO2)"
echo " 7 - Central Nervous Systems Toxicity (CNS)"
echo " 8 - Absolute pressure"
echo
echo -n " Function: "; read option
disclaimer
case "$option" in
	1)
	  mod
	  ;;
	2)
	  od
	  ;;
	3)
	  bestmix
	  ;;
	4)
	  ead
	  ;;
	5)
	  compare
	  ;;
	6)
	  po2
	  ;;
	7)
	  cns
	  ;;
	8)
	  absolute
	  ;;
	*)
	  echo " Please choose a valid option from the menu"
	  exit 1
esac

HPC-Europa2 Virtual Cluster liveDVD – milestone 5

The fifth release of the HPC-Europa2 Virtual Cluster liveDVD is available (milestone 5) for download:

CINCENA (ITA) - http://www.hpc-europa.eu/files/iso/milestone5.iso.gz
EPCC (UK) - http://hpce2jra2.epcc.ed.ac.uk/milestone5.iso.gz

Release Note for Milestone 5
============================
The Virtual Cluster liveDVD:
* provides tools and libraries that are installed and used at the partner sites.
* emulates the environment of the platforms available at HPC-Europa centers.
* allows hands-on building of a virtual cluster.

The liveDVD contains training and dissemination material published by the HPC-Europa2 project, including material from the partner centers such as slides, video tutorials and example code. Optional access to a source code repository enables the migration of code and data from the Virtual Cluster to the user account created on the HPC-Europa machines.

The liveDVD is based on SliTaz GNU/Linux, a free operating system, working completely in RAM and booting from a removable media. The file size of the SliTaz GNU/Linux 3.0 ISO image is 29 MB. Hence, it leaves plenty of space for adding tools, libraries and training material into this liveDVD. The SliTaz system is quick, responsive, and clean. A lightweight and elegant desktop is included as well in the 29MB ISO image.

The milestone 5 ISO images has roughly the size of 3.7 GB including several tools and libraries, as well as training material.

Since the previous release (milestone 4), existing packages have been updated, such as:

* Open MPI to version 1.5.4
* Midori with flash support
* Firefox to version 7.0.1

In addition, this release has added a new package to support EVO (http://evo.caltech.edu/)

System Requirements
===================
* A laptop or computing with a DVD drive.
* Intel or AMD processor with a hardware virtualization support when using KVM and libvirt. Otherwise, this liveDVD can be run under VirtualBox or VMware or similar.

Known Issues
============
* Totalview requires a license file, which is no included, in order to work.
For requiring a demo license visit:
http://www.roguewave.com/products/totalview-family/totalview.aspx
* On a MacBook Pro laptop, the mousepad does not work. Need to use an USB mouse
* Resizing video screen on VLC causes an unexpected exit of the program.
* VLC has no sound for viewing mkv videos.
* VLC cannot stream files or view incoming streams.
* Flash cannot be viewed under Firefox. Use Midori instead.

Acknowledgement
===============
This work was carried out under the HPC-EUROPA2 project (project number: 228398),
with the support of the European Community – Research Infrastructure Action of the FP7.