Posts

DDNS with IPv6

My ISP provides /64 IPv6 block but it's a not a static block, so it's really annoying when I trying to  access my home server (yes, it's a raspberry pi) remotely as allocated IPv6 prefix block changes time to time. here's my solution for that Getting the current IP #!/bin/sh if [ -z "$1" ] then echo "usage : ./$0 <iface>" else ip -o -6 addr show $1 | sed -e 's/^.*inet6 \([^ ]\+\).*/\1/' | grep '/128' | awk -F '/' '{print $1}' fi I am using freedns.afraid.org as my DDNS provider (it's free), this is my script to run as a cron job to update latest IPv6 address #!/bin/sh ip6_addr=`./get-addr-dialog-bb.sh eth0` # last_ip6_addr=`cat ./.last_ip6_addr 2> /dev/null` host=`hostname -f` auth='<user>:<password>' # freedns.afraid.org credentails if [ "$ip6_addr" != "$last_ip6_addr" ] then curl -k "https://freedns.afraid.org/nic/update?hostname=$host...

Create a single executable from a pure Python code with Cython

Primary purpose of Cython is may not be creating an executable from a Python source, there's a very useful option in Cython to creates executables, so that my users will feel like it's native executable here's my simple python program print "Hello World!" print "Hello Again" First step: Covert my Python code to C code using cython --embed -o hello.c hello.pyx Second step: Compile and link generated C code to Python and it dependency libraries statically (some common libraries dynamically) gcc -v -Os -I /usr/include/python3.5m -o app hello.c \ -Wl,-Bstatic -lpython3.5m -lz -lexpat -Wl,-Bdynamic -lpthread -lm -lutil -ldl Final step : Test the application and see dependencies output of program $ ./app Hello World! Hello Again output of ldd ldd app linux-vdso.so.1 => (0x00007fff6932a000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f65bae7f000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f65...

Consuming a RESTful Web Service with C++ using QT libraries

After a long time I got a chance to work again with QT framework, Here are some of the findings about how to invoke RESTful webservices using QT. It's pretty easy really!! requirements g++  or compatible c++ compiler QT5 or later with QtNetwork module source main.cpp #include <QCoreApplication> #include <QtCore/QUrl> #include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkReply> #include <QJsonDocument> #include <QJsonObject> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QEventLoop eventLoop; QNetworkAccessManager mgr; QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); QNetworkRequest req( QUrl( QString("http://api.openweathermap.org/data/2.5/weather?q=colombo,lk") ) ); QNetworkReply *reply = mgr.get(req); eventLoop.exec(); if (reply->error() == QNetworkReply::NoError) { QString strReply = (QString)reply->r...

Hello World using OpenCL

I've recently acquired a new laptop with an API Radeon GPU. I'm always interested in HPC and how it is used in various industries and research areas. I had experience with MPI/OpenMP earlier but not got a chance to look into GPU style frameworks such as CUDA or OpenCL. I've a lot of free time these days, so I studied some online tutorials and got a little bit familiar with OpenCL and it's very interesting to me. I'm using AMD's APP SDK 2.9 for my work, my first OpenCL code as below, it can be compiled using gcc with -lOpenCL #include <stdio.h> #include <string.h> #include <CL/cl.h> const char source[] = " \ __kernel void hello( __global char* buf, __global char* buf2 ){ \ int x = get_global_id(0); \ buf2[x] = buf[x]; \ }"; int main() { char buf[]="Hello, World!"; char build_c[4096]; size_t srcsize, worksize=strlen(buf); cl_platform_id platform; cl_d...

Quick Start Apache Stratos from EC2 images

Image
In this blog post I focus on deploying the pre-built EC2 image of Apache Stratos. Note : This blog post is based on "Stratos Quick Start Guide",  Starting the Apache Stratos demo image Spawning the Apache Stratos instance Configuring the Apache Stratos instance Registering a tenant and configuring Cartridges Starting the Apache Stratos demo image Common Prerequisites The following are the recommended prerequisites when running the Apache Stratos demo setup in a single node. Please note that for production deployment the prerequisites will vary based on the scalability requirements.  System Requirements Processor : 2.8GHz CPU Memory : At least 8GB memory. However, 16GB is recommended. Disk : 40G hard disk space The following are the memory allocations for Amazon EC2 instance types that you may require: m1.large = 7.5 GB m1.xlarge =15 GB m3.xlarge= 15 GB Software Requirements Git Facter Java (JDK1.6.x) ZIP MySQL Serv...

How to automate the installation of Eclipse plugins with ant task

In this blog post I suggest a simple way to automate the installation of Eclipse plugins with ant task and maven-antrun-plugin. ${project.basedir}/target/eclipse = eclipse dir (extract using maven dependency plugin) ${project.basedir}/target/p2-repo = p2 dir of plugins  (extract using maven dependency plugin) sample1.feature.group, sample2.feature.group,.... = sample feature group names a snippet of my code follows. <plugin>  <artifactid>maven-antrun-plugin</artifactid>          <executions>      <execution>      <id>install-eclipse</id>      <phase>package</phase>      <goals>       <goal>run</goal>      </goals>      <configuration>      <tasks>       <java classname="org.eclipse.equino...

How to change the mouse icon/feedback when we drag a node to the canvas from the tool palette in a GEF/GMF based editor

In this blog post I suggest a simple way to change the drag icon/feedback to indicate to the user that it is to drop or illegal to drop what they are dragging at the current location in a GEF or GMF based editor. You can do it simply by implementing custom DragDropEditPolicy and installing to your EditPart. a snippet of my code follows. import java.awt.MouseInfo; import java.awt.Point; import org.eclipse.draw2d.FigureCanvas; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.ImageFigure; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Control; import...