Posts

How to configure a globally routable FreeBSD 12 Jail with IPv6, VNET and ZFS

It's holiday season in Sri Lanka. I really got a free time to play with one of my favorite OS FreeBSD. For a long time I had idea to setup a FreeBSD Jail. I went through some online documentations. there was a good article on nixCraft for FreeBSD 11 (it didn't worked for me on FreeBSD 12), so I used that to get idea about initial setup especially ZFS configuration, also I looked at FreeBSD official example directory for jails at /usr/share/examples/jails and my own configuration IPv6 setup to make it globally routable The steps to create a jail as follows Check the feasibility of setting up a jail with globally routable Install required tools Create a ZFS data set for jails Create the base jail files Configure the base jail and create a new jail files Configure the jail.conf on the host Turn on jail service and start a jail Login to a jail and play with it Step 1: Check the feasibility of setting up a jail with globally routable Setting up a jail with VNET re

Getting information about list of installed webcams programmatically using udev

If your writing an application in Linux where you dealing with low-level hardware details, using udev is a better choice rather than calling executable and reading the content in their STDOUT This is a small C code to get information about list of installed webcam programmatically using udev. This is written in C, this can be integrated with other languages such as Python, Java using a wrapper interface such as JNI(Java) or Python/C API   #include <libudev.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <unistd.h> int main(void) { struct udev * udev; struct udev_enumerate * enumerate; struct udev_list_entry * devices, * dev_list_entry; struct udev_device * dev; /* Create the udev object */ udev = udev_new(); if (!udev) { printf("Can't create udev\n"); exit(1); } /* Create a list of the devices in the 'video4linux' subsystem. */ enumerate = udev_enumerate_new(udev); udev_enu

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&a

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 Server