Skip to main content

Posts

Build Wine rpm with 32 bit application support

Wine is a software to allow running Windows applications in Linux, MAC etc. platforms. It is available for installation from package managers like yum (RHEL, CentOS) and apt (Ubuntu). You can find more details on how it works in Wine wiki . But the default Wine package available from package manager does not have support for 32 bit Windows applications. This was the case for me. In Redhat Enterprise Linux 7.3, the wine package did not contain support for 32 bit windows applications. So the only option was to build a separate rpm of wine which will include this support. All the steps are executed on a RHEL 7.3 VM (x86_64). Step 1 Download and run shell script which will make wine 64 and 32 support for RHEL: https://github.com/zma/usefulscripts/blob/master/script/install-wine-i686-centos7.sh It accepts a version no. as CLI parameter e.g. 2.0.3 The script installs wine in /usr/local/ directory by default. We can verify the files that are being copied for wine using "...

Build Wine rpm with 32 bit application support

Wine is a software to allow running Windows applications in Linux, MAC etc. platforms. It is available for installation from package managers like yum (RHEL, CentOS) and apt (Ubuntu). You can find more details on how it works in Wine wiki . But the default Wine package available from package manager does not have support for 32 bit Windows applications. This was the case for me. In Redhat Enterprise Linux 7.3, the wine package did not contain support for 32 bit windows applications. So the only option was to build a separate rpm of wine which will include this support. All the steps are executed on a RHEL 7.3 VM (x86_64). Step 1 Download and run shell script which will make wine 64 and 32 support for RHEL: https://github.com/zma/usefulscripts/blob/master/script/install-wine-i686-centos7.sh It accepts a version no. as CLI parameter e.g. 2.0.3 The script installs wine in /usr/local/ directory by default. We can verify the files that are being copied for wine using "...

Non capturing group in regular expression and it's use

Recently I have been stuck in a regular expression where I had to use grouping in places, values of which were not required. It won't make sense to explain the problem without the text. So here it is Controller Id Connection Status Connection State Secure Role ------------- ----------------- ---------------- ------ ------ 1             Connected         Active           No      Slave 25             Disconnected      Idle             No      Master My goal was to get the numeric values at the beginning of the line while still matching the whole line for safety (so that any other numeric values in the output don't match). As you see in the output, each column can contain a value from a list of fixed values. e.g. Connection Status can only contain Connected or Disconnected . That demands the following ...

Simple employee table with OpenStack Horizon DataTable module

I was working on OpenStack dashboard (aka Horizon ) few past few months and I will share a simple way to build your data tables based on Horizon. To give a brief introduction of Horizon, it is the official dashboard project of OpenStack, the cloud operating system. Horizon is a python Django application. It provides pre-defined modules for common web application requirements like tabs, workflow, table etc. From Grizzly release onward Horizon modules are separated from OpenStack specific code. It allows one to use Horizon modules independently. To build a data table in Horizon you need to simply create a model class for your data. The important thing to remember here is that the class must have an "id" attribute . Horizon will build rows based on this id. It can be alpha numeric also. Though it is not mandatory to display the id column in the table, you can still have it. Below is the data model for my Employee table - The employee class has 4 attributes -...

Get current UTC timestamp in Python

Converting current time to UTC (GMT) in python is a very common query that is searched in Google but, I did not find a compact answer when I did the search for my work. I figured out the code by some help from Google and some experimentation of my own. I'll share the code, in case it is useful to someone. First I'll explain the Epoch time (or POSIX/Unix time) and UTC (Coordinated Universal Time) time format. Epoch time is calculated as number of seconds elapsed since midnight Jan 1, 1970. It is used in all *nix systems and has become a standard when considering date/time from multiple systems. In python time module allows us to get the current epoch time in local time zone. UTC time is basically synonymous of GMT. It marks the 0 offset time zone. Time in all other time zones are calculated with positive/negative offset from UTC. It is used in many cases where there are multiple machines, located in different time zones are involved. To get current UTC time in python we ...

Upgrade wireshark version in Ubuntu

Wireshark is a great and may be most widely used network protocol analyzer. In last few months I had used it extensively in a network project. Wireshark was a great help in debugging hard to find protocol problems. During this project I was using Ubuntu 10.04 as my development environment. I installed wireshark using sudo apt-get install wireshark But default wireshark version provided by Ubuntu 10.04 repository is 1.2.7 which was not suiting my purpose. I needed the newer versions of wireshark which provides some important features for analyzing protocols. There are 2 ways to upgrade your wireshark version from the default version provided by Ubuntu - Add a third party repository to your repo conf and you can upgrade the wireshark. But I do not prefer this way as it imposes the restriction of version that can be installed. Install wireshark from source. This is best way as you can install any version of wireshark in your Ubuntu. Here are the steps to follow - ...

Call an external program from MySQL trigger

MySQL is the choice of many when it comes to database. Its free and quite robust. During one of our prototype implementations we had a requirement of calling some external processes when there is a change in a MySQL table. MySQL triggers are provided for the same purpose. They get executed when the table is changed in certain ways that is specified by the programmer. Now it is very easy (rather trivial) to do some thing in other MySQL database tables when trigger gets fired. But, our requirement was to call a C program. Fortunately MySQL provides a way to implement your own functions, its called User Defined Functions (UDF). The "how to" is here . Now that we know, how to define your own functions and call them from MySQL events, we need to write our logic in a C program by following the interface provided by MySQL and we are done. Wait a minute. That is already done by somebody. They have made a library of UDFs. One of them, LIB_MYSQLUDF_SYS does exactly what we want....

Read a log file in tail mode from python

When you want to develop a log reader application, you'll need to keep reading the log. There is a Linux utility doing exactly the same. Its the tail command. tail blocks on the file till new entries are appended to it. I needed the similar functionality in python and there was a small library providing it already. Its called filetail.py . The program performs tail functionality and also handles log rotation. But in my case, the log file used to change (file name) depending on the date. filetail could not handle it as the file name has changed already. To handle this I have made following changes to the filetail code - In nextline() method file size should be checked to be less or equal to the cursor position: In _reset() method I have added the logic to re-create the log file name from the current date value and replace it with the original file name: I apologize for not following standards of coding here. It served the purpose for me.

jQuery UI dialog without any close option

We use jQuery UI for designing web pages in out project. Some times back we had a scenario where the user log in to a dashboard was implemented using jQuery UI dialog (modal) component. Requirement was that the dashboard page should not be reached without passing the authentication process. But the dialog component of jQuery UI library provides a default X icon at the top left corner of the element which provides an option to close the dialog. In our case, we wanted to reload the same page on click of the X icon. So that the user can not escape the login dialog by using the X icon. We achieved this by writing the page reload code inside dialog's close handler.  Everything worked fine until we had to handle the successful log in. Once user login succeeds we need to call dialog widget's close handler which reloads the page in turn. Because of this, even after a successful login, user gets the login dialog again. The only way to stop this was, to r...

Setup VNC server in Ubuntu 10.04

I needed a system outside my company firewall to access access some internet based applications. I wanted to use a web browse from that. But all I had was, a cloud node running Ubuntu 10.04 with command line access to it. I installed VNC server in that to run firefox web browser. Steps are below - sudo apt-get install xinit sudo apt-get install x11vnc sudo xinit & x11vnc -safer -localhost -nopw -xkb -once -display :0 & Create a ssh connection from Putty. I have user ssh port forwarding feature to make the connection secure. After configuring normal host name, user id or ssh key etc. go to Connection > SSH > Tunnels section. Input 5902 for Source and localhost:5900 for Destination. Click Add. Now open this session from Putty. Download Tightvnc java client and unzip it to some directory. Run the jar file that was extracted in last step. In the new window, input 127.0.0.1 for Server and 5902 for port. It should launch another window showing Ubuntu system. No...

Run Cherrypy web server in Android

I was in much need of a way to run Python CGI scripts in Android. Basically I needed a web server capable of running CGI scripts in Android platform but, I found none. Finally I modified my CGI script to suit the Cherrypy web server and it could run on Android. I'll try to describe the steps here which I had to figure out myself. The information I found by googling was not completely correct as Android platform has changed from the time of the publication. So, I'll mention the version no. for each software I've used to make sure it is not misunderstood later. First thing we need is to download the SL4A (r4) software in the Android (2.3) emulator. It can be done from your Android browser by going to the SL4A site . Now install the software in emulator. Then install Python for Android from the same SL4A site. It'll download an apk of version r4. Launch SL4A application and check that HelloWorld python script is running. It will make sure that your installation is...

Flexigrid table becomes read only when no rows returned from server - solution

Flexigrid is a popular jQuery plugin which builds multipurpose data grid in web pages. It is a light weight plugin with rich controls. I have used Flexigrid heavily in my project. While using the plugin I faced one problem. It disables the grid when there are no rows in it. This looks like a proper behavior until you need the buttons in the table (Add) to be enabled for the first row to be added. To clarify the requirement I had, there is a grid with Add and Delete buttons in it. The first row in the grid will be added through the add button. So, when the table loads for the first time, there is no row and this makes the grid read only. Now, we can not click the add button. It becomes a recursive problem. The Flexigrid code that does this - I have devised a dirty fix for this problem - Use this code in your document.ready() function. I tried asking the problem in the Flexigrid mailing list also, but could not get any other solution. So, currently this is the only working so...

Resolve Hibernate connection timeout issue with MySQL server

This problem has been faced by many of the developers but the fix is not very common. I had to do some research to find out the problem and solve it. If you are using a MySQL server, the default connection timeout is 8 hours (tested on MySQL 5.2). This causes a problem in production environment as the database could not be connected overnight. Below is the log trace of the problem - org.hibernate.util.JDBCExceptionReporter: The last packet successfully received from the server was 56697 seconds ago. The last packet sent successfully to the server was 56697 seconds ago, which  is longer than the server configured value of ‘wait_timeout’. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem. As the description says, we can increase the wait_timeout property of MySQL server but it is...

A simple REST based web service

REST stands for Representational State Transfer. Roy Fielding, the father of HTTP protocol, had coined the term in his doctoral thesis. REST is not a software, rather it is a concept or an architecture. The biggest use of REST architecture is in WWW (World Wide Web). The services that conforms to REST standard are termed as RESTful services. REST based services contain a client and a server. The server contains resources that can be represented by various states. A client initiates the request to server when it is ready to transition it's state. The server responds with the required state. The REST based web service is quite popular now. This type of web service is called RESTful web service. In RESTful web service we represent a service by an URI. Common HTTP methods are used to request for a specific state transfer. Create PUT Update POST Read GET Remove DELETE I have used an open source java library called Jersey  for creating this simple RESTful web service. ...

Using web service client behind a http proxy server

Web service is a popular medium of communication between devices over a network. But most of the time you find yourself behind a http proxy server to connect to the network. Proxy servers are often found in company networks. The main reasons for their introduction are - security, resource caching, auditing etc. But ultimately they block unauthorized access to internet from the inside network. This leads to the problem we are going to solve now. We are going to use w3schools temperature converter service ( WSDL download ) for testing. Make sure you are actually running this code behind a http proxy server. You also need to know the proxy server's host name and the port no.  I'll assume that you can generate the client stubs using JAX-WS (or some other tool). I have used wsconsume tool to generated my stubs. In my case,  com.w3schools.TempConvert is the implementation class and  com.w3schools.TempConvertSoap is the interface. Then I have a com.w3schools.client.WSClie...

Write your first JAXWS web service

Today I'll try to explain how easily one can build a JAX-WS web service. Web Services are very popular now-a-days. They are used every where. But I found it difficult to write my first web service with jax-ws, partly because I was trying myself and partly because I could not get a simple explanation of steps. That is why I'll try to show the simplest web service possible using jaxws. First thing first, what do you need to build your first jax-ws web service. JDK 1.6 (I used update 23) Eclipse IDE (you can use some other IDE as well) Are you kidding? nothing else. JAX-WS 2.0 is actually Sun's (now Oracle) reference implementation of Web Service stack. It is bundled with JDK 6 and above. First you need to create a Java project in Eclipse. Then create a class called com.ws.HelloService . This will be our web service class. Have a public method in this class which will be exposed as web service. Below is the code - The catch here is the @WebService annotation. Thi...

Get JSON data response with JQuery Form plugin for a file upload form

My latest project involves JQuery for UI development. Frankly speaking, I did not have much idea of JQuery before. But I found it very easy to understand. All APIs are well documented with lots of examples available on Internet. The best feature of JQuery is its plugins. There are thousands of plugins available to play with. For every need of my web app I could find a plugin. In my web app I am using JQuery Form plugin to submit the forms through AJAX. The return from my servlet is JSON object. The form plugin works great for all my forms. Well almost all, there is a HTML form which has a file upload box along with other input fields. This form was not able to get the response in JSON format. Though it worked in Google Chrome, but Firefox was presenting me with a file save dialog box. I did a lot of googling to find out whats going on. Finally I observed that the problem is with HTTP headers that the form submit request has. Here are the headers captured by Chrome Request heade...

log4j.xml - A sample configuration

I could not post anything last month though all the time I was dying to post something. The reason behind this was I change in my profession profile. Actually, I changed my employer. All of the last month I was busy in official work and to settle down in my new office. The last week of the year is normally a holiday in the new company. So, I could rest a while in my home and able to write the blog post. Though I had a couple of other topics in mind but writing them will take more time which I don't want to spend during the festivities. So, I'll discuss about a simple but useful thing. How many of us in Java sphere use log4j for logging? You know the answer. log4j is a very popular logging framework. Configuring log4j is quite simple. Still when you get the task of doing it, you try to find an example (I do the same). That is why I'll show a simple log4j configuration to print to a file. There are 2 ways to configure log4j, log4j.properties and log4j.xml. I prefer the...

Strings in Switch statements - a new JDK 7 feature

JDK 7 is the next release of Java language. There are lot of expectations from this release. For the first time Java is being modeled outside Sun Microsystems. Now JDK 7 has got a net host, openJdk community. There are quite a few features planned in JDK 7. Some of them may prove to be a milestone for Java language. But my personal liking is a very small feature rather project called Project Coin . Coin serves to add small language features to Java which will make programmer's life easy. The JavaOne 2010 presentation for Project Coin lists the following features as accepted ones in JDK 7 time frame. Binary literals and underscores in literals Strings in switch Varargs warnings Diamond Multi-catch and more precise rethrow try-with-resources (formerly known as Automatic Resource Management, ARM) Out of these features, the most attractive to me was "Strings in switch". This is something I've longed for from my college days. I mean, though it was not Java (it...

An unwise attack on the Singletons

Few days back I was disturbed with some maven build issues in office. I got back home pretty late. Already, as you can understand, mood was off. I thought of relaxing by watching a good movie but next day I had an interview scheduled. So, I had to brush up my skills a bit (I don't use them often in office :-) ). The first topic I started with was Singleton pattern. This one is so famous among interviewers that you better be able to explain it. I had read the pattern many a times already. Nothing to prove the book wrong, never occurred to me. But that day, may be due the horrible mood, I challenged the pattern. I thought I'll find ways to break the pattern down. I wanted to create 2 Singleton instances in same JVM. Thats how the attack began. Below is the code for creating a Singleton class Here is the code to test the pattern I have used VisualVM (comes as part of JDK 6) tool to check the no. of instances for Singleton class. You just need to pass a VM argu...

Generate POM files for a 3rd party artifact in Maven

Maven is a popular software project management tool. It is used heavily for building you project deliverables. More information about maven can be found here . Maven works on the dependency concept. It essentially means that every project should identify its required artifacts. These artifacts can be found in repositories. Repository is a central place where you keep all your required jars (or other resources). There is a specific structure required to put your artifacts into the repository. We can not just copy every thing at same place. To identify a resource through dependency mentioned in pom.xml, maven looks for the specific structure. Also ther should be a .POM file at the same location of the artifact. Normally the artifacts generated by maven build comes with the POM for it. So that, any other project wanting to use this artifact can do that. But if the artifact is created from a build other than maven (e.g. ant, Makefile etc), it will not have the POM generated. So this ar...