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

Remote cPanel backup via FTP

Here is the scenario:

– Domain that needs to be backed up (public_html, mail, database).
– Only access available via cPanel and FTP.
– Need automated daily full backup.

Solution:

– Take full backup on server and compress its contents (cronjob on remote server)
– Download via FTP the compressed file to the local machine (cronjob on local machine).
– Delete compressed file.

There might be tools that do this, although I didn’t come across any while looking on the web. I implemented a simple solution based on bash scripts that gets the task done.

backup.sh: Goes on the remote server to run as a cronjob.
ftp.sh: Runs locally (on the machine that will store the backup) as a cronjob.
.netrc: Defines the FTP account details (stored in /home/$user/.netrc)

Gmail SMTP relay with Postfix

The following configuration has been performed in Debian but should apply in any Linux distro with Postfix installation. The task quite simple: use Gmail as SMTP relay for outgoing email traffic.

1) At first place I had to install the following packages and turn off sendmail:

apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
service sendmail stop

2) Then edit the configuration file at /etc/postfix/main.cf by adding the following options at the end of the file:

# Gmail SMTP relay
relayhost = [smtp.gmail.com]:587
smtp_use_tls=yes
smtp_sasl_auth_enable = yes 
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_security_options =

3) Create the authentication file at /etc/postfix/sasl_passwd and set the right permissions:

[smtp.gmail.com]:587    <username>@gmail.com:<password>
chmod 400 /etc/postfix/sasl_passwd

Make sure the file is owned by the user who runs the Postfix daemon.
4) Reload Postfix:

service postfix reload

5) Confirm the configuration is actually working by sending a test mail:

echo "Test mail from postfix" | mail -s "Test Postfix" pkritikakos@isbs.gr

The sender of the email should be the given Gmail account. Also, in the “Sent” folder of the Gmail account you should see the email you have sent with Postfix.

If your domain is using Gmail’s infrastructure for handling emails, you can replace @gmail.com with your domain and use the corresponding account details.

NOTE: This configuration will be sending any system message as “username@gmail.com” and therefore is not advised to be used in multi-user environment.

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.

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;
}

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.

Converting OS X .plist to XML

The failure of my MacBook Pro seems that it didn’t cost much in terms on data loss, actually all the really crucial data were there. There are though some bits here and there that need to be moved over to my Linux box. One of the most important for everyday use the was the feed list for my RSS Aggregator. I was using the elegant, nice and simple NewsFire which uses binary plists (XML-like) for storing the feed list and I was never bothered exporting the feed list to OPML. The plist command in OS X can convert the .plist file into a .xml file, however I had no other Mac to do this operation or copy over the plist and export in OPML from there. Therefore I had to find a workaround for getting the plist working on RSSOwl or Liferea. Found the Perl plutil for Linux which converted the binary plist to standard XML. RSSOwl managed then to import the XML with all the blogs’ feeds as on NewsFire.

Regarding liferea, it wouldn’t import the XML file as it wasn’t proper OPML. But since RSSOwl imported the XMl file, I exported the feed list as OPML, which would be imported into Liferea or any other application.

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.

Ethernet device rename

I have been looking recently to find a way of creating a bridge interface on SliTaz in order to get KVM/libVirt working with the expected br0 interface. Unfortunately, the network configuration files of SliTaz do not provide any information, neither the documentation. A post on the forum didn’t get any replies either. Rather than trying figuring how a proper bridge interface would work on SliTaz, I thought of renaming eth0 to br0, as the later would be expected by KVM/libVirt. As far as I know the following process would need to be followed for other distros as well as there is no specific way of renaming an interface other than using udev rules.

On SliTaz, the required udev rule is defined /etc/udev/rules.d/70-persistent-net.rules. The default entry looks like the following (where Xs the MAC address):

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="XX:XX:XX:XX:XX:XX",
ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

The generated rule matches the eth0 interface with the specific network card. The required change is the renaming of the NAME field to br0. If the targeted system is a virtual machine with changeable MAC address, or most likely a live distro like in my case, the ATTR field, that specifies the MAC address, would need to be changed as well. Changing it to 0* would work and on the next boot the device should be renamed. The final udev rule:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="0*",
ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="br0"

There is one more addition to do on SliTaz and that is to rename the default ethernet device in /etc/network.conf from eth0 to br0. That would allow higher level applications and scripts to look for br0 rather the non-existant eth0.

Virtual Cluster liveDVD milestone 3 released

The Virtual Cluster liveDVD milestone 3, an activity of the HPC-Europa2 project, is available from today for download.

“The “HPC-Europa2 Virtual Cluster Live DVD” is a SliTaz based Live Linux DVD. It boots and runs completely from DVD providing recent tools, compilers and libraries for the development of parallel applications. Further on the DVD includes training material, videos from past virtual surgeries and reports from past HPC-Europa visitors.”