Posts

How costly are your `Option`s?

Image
Code which is optimised and performant (for a majority of use cases) doesn't have to be ugly and unreadable, for there's a lot of performance gains to be made by simply following good design and clean coding principles. Scala's Option is a very idiomatic way of representing optional values. Now, I'm not against the use of Option , however, more often than I'd like to, have I come across it being misused/abused. For example, when defining generic types: case class Asset(name: String , shareQuantity: Option[ Int ] , sharePrice: Option[ BigDecimal ] , bondYield: Option[ BigDecimal ] , cashValue: Option[ Amount ]) which should've been modelled as specialised types: sealed abstract class Asset(name: String ) case class Stock(name: String , shareQuantity: Int, sharePrice: BigDecimal ) extends Asset(name) case class Bond(name: String , bondYield: BigDecimal ) extends Asset(name) case class C...

Partial HTML5 support in IE8 without shims or javascript

Image
Today, I stumbled across something strange in IE8 where it was able to identify and render HTML5 elements like <section> and <article> without the use of the HTML5-shiv or even without having to use document.createElement() . I figured it had to do with an "xmlns" attributed which accidently landed up on one of the <section> tags in my html. To illustrate my point, I'll use variations of the following HTML: <!DOCTYPE html> <html>   <head>     <style>       .outer,.middle,.inner {         padding: 20px;       }       .outer {         border: 1px solid black;         background: lightblue;       }       .middle {         border: 1px solid red;         background: yellow;       }       .inner {         border...

ListView/ExpandableListView randomly changes background colour on scroll/click/expand/collapse

Image
Working on the same android app which I posted about a couple of times earlier, I had this one feature I wanted to implement where I show a list of persons and highlight those from that list who have a birthday today. I tried a couple of different approaches to to the "highlight" the list items which had a birthday today for e.g: setting the background colour for those items, setting up a background icon for those, changing the text colour of the list item, and with all of these I faced 1 common problem: if I had to scroll the list or expand/collapse one item group (in case of ExpandableListView ), then it would end up highlighting some random items from the list, and if I continued that excercise, finally almost all items would get highlighted. Since I had used an ExpandableListView , my getGroupView method looked somewhat like this: @Override  public View getGroupView(int groupPosition, ..., ViewGroup parent) {   Person person = (Person) getGroup(groupPosition);  ...

PreferenceFragment shows up with a transparent background

Image
In an android app that I'm currently working on, I wanted use Android's Preference API to provide an interface to modify some app specific settings. I didn't want to create another Activity or PreferenceActivity for that, and hence I thought of simply using a PreferenceFragment . Now, in my project I already had a MainActivity ( extends ActionBarActivity ) which had a MainFragment wired up to it somewhat like this in it's onCreate method: getSupportFragmentManager().beginTransaction()  .add(R.id.container, new MainFragment())  .commit(); And because of that I knew that I had to replace the existing MainFragment with my new SettingsFragment which extended PreferenceFragment . With that in mind, I went ahead and added the following to my MainActivity 's onOptionsItemSelected : getFragmentManager().beginTransaction()  .replace(R.id.container, new SettingsFragment())  .addToBackStack(null)  .commit(); When I saw this work in the emulator, it looked some...

"Application not installed" when APK is not signed

I wanted to test a small android app which I was working on, on my phone. I had already tested this app on an emulator and even on a physical device - my phone earlier, but I had done that via ADB. However, I wanted to install it this time from the apk file. Now, when I ran gradlew assembleRelease there were 2 apk files generated in the projectname /build/apk directory. One named projectname -debug-unaligned.apk and the other named projectname -release-unsigned.apk . The release unsigned one seemed to be the right one to try out. So I tried installing it on my phone. Everything went on well until I saw a message when it had just seemed like the app was installed which actually read: "Application not installed". I was a bit confused looking at the message, I didn't quite understand what went wrong as there was no details as to what went wrong in the message. I had pretty much everything configured the way I thought would be required like checking off the box against ...

Bundle containsKey() but returns null on getString()

Back to blogging after a long time, and this time its quite a lame one which I usually wouldn't want to blog about, but I did spend close to an hour trying to figure out what I was doing wrong. I just started a small android application and was trying to send a paramter from one Activity to another. Now, after a bit of searching around, I found out that I needed to create an Intent Bundle and put the parameter in it, and the new Activity which gets started will be able to fetch it from the same Bundle using the key that was provided while inserting data into the Bundle . So, I had something like this in the first activity: Intent intent = new Intent(FirstActivity.this, SecondActivity.class); EditText nameText = (EditText) findViewById(R.id.query_textbox); intent.putExtra("queryKey", nameText.getText()); startActivity(intent); and something like this in the second activity: Bundle extras = getIntent().getExtras(); String query = extras.getString("queryKey");...

Running multiple test suites using maven-karma-plugin

The maven-karma-plugin allows running your jasmine tests via karma from maven. For the most part, the documentation given in the readme.md at  https://github.com/karma-runner/maven-karma-plugin  is sufficient if you just want to run unit tests using karma. However, if you want to use the karma to run your unit tests as well as your e2e tests, you need to specify it in your pom.xml in a slightly different way. Firstly, the <configuration /> goes inside an <execution /> . Then every <execution /> needs to have an <id /> which should be unique. <plugin>     <groupId>com.kelveden</groupId>     <artifactId>maven-karma-plugin</artifactId>     <version>1.1</version>     <executions>         <execution>             <id>unit</id>             <goals>       ...

Openstack user admin commands removed from nova-manage

Lately I have been trying to get an openstack node up and running on an Ubuntu VM. For which, I was following a couple of the many guides available online. Everything went well until I found out that I was not able to create a user with an admin role using the nova-manage command. I was trying to run, nova-manage user admin openstack Much to my disappointment, I got the following error,  nova-manage: error: argument category: invalid choice: 'user' (choose from 'version', 'bash-completion', 'project', 'account', 'shell', 'logs', 'service', 'db', 'vm', 'agent', 'cell', 'instance_type', 'host', 'flavor', 'fixed', 'vpn', 'floating', 'network') I was a bit frustrated after going through the wiki for the nova-manage command which said that nova-manage was going away in the Folsom release of openstack, but never said anything about what is go...

Upgrading maven-jetty-plugin for Jetty 8 to use Servlet 3.0

When moving from Jetty 6 to Jetty 8, one of the biggest changes is the jump from Servlet version 2.5 to version 3.0. There is also a change in the JSP version which was 2.0 in Jetty 6.x while it is JSP 2.1 in Jetty 8.x. Keeping that in mind, the dependency for the servlet api needs to be configured to use Servlet 3.0 jars. This should have been sufficient if it wasn't for a change in "maven-jetty-plugin" also. Up to versions 6.x of the maven-jetty-plugin are available under the artifactId of "maven-jetty-plugin". So running, mvn jetty:run with the following in your pom.xml would be sufficient. <plugin>   <groupId>org.mortbay.jetty</groupId>   <artifactId>maven-jetty-plugin</artifactId> </plugin> But if you try to do that with Servlet 3.0, you would end up with a java.lang.ClassNotFoundException for javax.servlet.ServletRegistration$Dynamic.class This is because for jetty 7 and above, the artifactId for the plugin is "jet...

Login remotely to a ADS authenticated RHEL system

This week I was trying to get an RHEL system to authenticate me using my Active Directory credentials. After a bit of looking around, I cam across this wonderful step-by-step procedure to get it done: Attaching a RHEL6 server install to Active Directory for authentication Everything was going on well. I was able to do a local login using: ssh myuser@MYDOMAIN@localhost I just thought it might be cool to try logging in to my newly configured ADS authenticated box over SSH from another machine. So I tried, ssh myuser@MYDOMAIN@192.168.0.1 which obviously didn't work. The shell was treating "MYDOMAIN@192.168.0.1" as the hostname. With a little bit of playing around I found out that the following worked: ssh "MYDOMAIN\myuser"@192.168.0.1 It looks like specifying the domain the way usually Windows expects it really did work if it was enclosed in quotes!

Installing Windows 8 without an optical drive

Finally managed to get Windows 8 installed on a laptop without a optical disc drive. This was a Lenovo ideapad S405 which came pre installed with Windows 8, but since I was more inclined to use Linux on it, I had somehow managed to get Ubuntu installed on it. Now, I'm usually a Fedora guy, but for some reason the driver for the mouse/touchpad which comes compiled into the kernel was less stable in the version of Fedora that I was using, hence the brief switch to Ubuntu. Now when I had to give the laptop away to someone who's going to use Windows most of their time, I had to make sure that I could install Windows back onto it. I must say, that in spite of being warned by the salesman at the store to maintain a backup of Windows 8 if I was to wipe out Windows form the laptop; I did not follow his advice. I started off obtaining the iso for Windows 8, which could then be restored onto a USB drive with at least 4GB of storage capacity. When I tried directly restoring the iso image...

500 Internal Server error with codeigniter mysql connection

I was trying out CodeIgniter  today. I found it quite lightweight and easy to get started with. MVC was fine until I came across a strange issue. Every time I tried to connect to the database, I would end up getting the infamous "500 Internal server error". Unfortunately, even after checking through all http logs, I was not able to trace it to anything that could've gone wrong. I had apache, php, mysql installed and configured correctly. Spent about 4 hours trying out different configurations, playing around with the database names, model names, etc, just to realise later that I did not have the php-mysql driver installed! This time I was on an ubuntu machine, so I had to: apt-get install php5-mysql and then although I could see that apt-get had already restarted apache2 for me, I just thought of doing it myself as well, service apache2 restart and there it was. Everything was working the way I wanted it to be. It was a very silly thing to miss out on this one. I have don...

Accents in Windows 8 on a Mac

Having been used to the Compose Key in Linux, I was trying to find out a way to type Portuguese (accented) characters in Windows 8 installed on a Macbook Pro. After reading up about the Dead key and use of AltGr key, I started experimenting with different key combinations. My keyboard layout was set to US (English). While playing around with different keys, I just found out that you could use the left "control" key in almost the same way as you would use the "Compose Key" on Linux. For example,   <Ctrl>` a  gives you,   à  While using the control key, do mind the fact that in many instances, "CTRL"+<some aplhabet> are bound to some default actions, like <CTRL>+o opens a new file, etc. Well, that seems to work well only in the address bar of Chrome. So, next I figured that you can actually use others keys as well instead of just the <Ctrl> key if you change your keyboard layout to US-International Keyboard layout. <Alt> + ...

Backslashes and MinGW32

I was trying to create a directory today inside an existing directory in MinGW32 on Windows 8. When I tried executing the following command, mkdir code\project it just didn't complain about anything, but it did create a directory - not exactly the way I intended it to. It created a directory "codeproject" by simply stripping off the backslash from the command. If you still need to use backslashes only, then you should enclose the path in quotes like, mkdir "code\project" else, you could use forward slashes instead of backslashes.

Proxy Error 502 “Reason: Error reading from remote server” with Apache 2.2.3

I had a setup of tomcat running on port 8080 and Apache proxying for tomcat on port 80. If I tried to access webapps directly from tomcat on port 8080,. they were accessible, while on port 80, I would get the followig error: Proxy Error 502 “Reason: Error reading from remote server” with Apache 2.2.3 following fix worked: adding retry=1 acquire=3000 timeout=600 Keepalive=On after the Proxy directive in the http configuration.

jQuery UI plugin conflict with dot net's default jQuery UI

A very short note on something I came across today (I might elaborate on this later..) In a dot Net application, I found that when I tried to use the jQuery UI Autocomplete plugin, there was a conflict. The errors and messages that I came across in the console of Chrome, indicated that there was an API mismatch in the jQuery UI library and the jQuery UI Autocomplete plugin. After a bit of inspection, I found out that dot Net had it's own version of jQuery UI, which actually was a concatenation of many jQuery UI plugins along with the jQuery UI core (even though it was named as jquery-ui.js!). It was pretty straightforward to fix this - I just had to get rid of one of them, either the dot Net's version or the original jQuery UI's version. In my case, since it was a dot Net application, I thought it might be better to retain Microsoft's copy of  jQuery UI!

Moving a storage pool in Virt Manager/Qemu

Today, I had to move my storage pool in Qemu to some other partition due to low disk space on my root partition. I decided to move it to a directory in my /home partition (I'm used to allocating most of my disk space to the /home partition). First of all, we need to stop libvirtd. /sbin/service libvirtd stop Next, we should move the storage pool to the new location. By default the storage pool is located at /var/lib/libvirt/images . I choose to move it to the directory /home/ausmarton/vm . mv /var/lib/libvirt/images /home/ausmarton/vm Any storage pool that is configured, has an xml file created for itself in /etc/libvirt/storage . So, in our case, we just need to edit the file /etc/libvirt/storage/default.xml . Here, we need to edit the path element which comes under the target element. <path>/var/lib/libvirt/images</path> Now that line should look something like this: <path>/home/ausmarton/vm</path> I would like to point out that /etc/libvirt/storage/ a...

Errors while trying to monitor Asterisk through Nagios

Today, I was trying to configure nagios to monitor an asterisk setup. I installed the nagios-plugins-check_sip plugin available for CentOS. I also had check_asterisk downloaded from here just to try out both. Now, check_asterisk and check_sip are perl scipts which can be used to monitor an asterisk setup. When run through the command line, they seem to work fine, i.e: given that asterisk or any other sip server is listening and your command is correct, you should get output similar to this: ;SIP/2.0 200 OK, 0.000585 seconds response time, cnt=1 Although, that's exactly what I got, it didn't work the same way through nagios, I was getting the following as the output from the plugin. (Service check did not exit properly) After enabling debug info for nagios, I found this in the logs, HOST: remotehost, SERVICE: Asterisk, CHECK TYPE: Active, OPTIONS: 1, SCHEDULED: Yes, RESCHEDULE: Yes, EXITED OK: No, RETURN CODE: 3, OUTPUT: **ePN failed to compile /usr/lib64/nagios/plugins/chec...

Allow ssh access to multiple users on GoDaddy's shared hosting without sharing your password

My aim was to allow a couple of colleagues to ssh into my shared hosting server at GoDaddy. If it was any other server, I could have very well created another user which could be used by anyone else who needs access to the server. But, on GoDaddy shared hosting servers you get just one ssh user, hence this blog entry. As described in Max Beatty's  blog , its a very simple job. But my approach was a little different, I did not want to keep copying everyone's public key into my godaddy server's .ssh/authorized_keys2 file. Instead of that, I created a new public/private key pair [ausmarton@ausmarton ~]$ ssh-keygen Next, step which is similar to Max's approach is to copy the newly generated public key onto our server. [ausmarton@ausmarton ~]$ scp ~/.ssh/id_rsa.pub user@remote-host:.ssh/authorized_keys2 If you're on a linux system, you can use ssh-copy-id, which does it quite neatly. [ausmarton@ausmarton ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host Now, you just need...

Class 'DOMDocument' not found error in Drupal 7

Thought of trying out Drupal 7 after a long time, as much as I had used Drupal 6, I was expecting Drupal 7 to work out of the box for a system which was previously running Drupal 6.I noticed that, for some reason, there were these error messages in my httpd logs: [Wed Jul 25 17:40:13 2012] [error] [client 127.0.0.1] PHP Fatal error:  Class 'DOMDocument' not found in /home/ausmarton/Public/website/drupal-7.7/modules/filter/filter.module on line 1041 Now, since I had worked quite a bit with version 6, I knew that all that needs to be done was this: yum install php-xml and /sbin/service httpd reload  And it did work! Well, so it looks like besides the usual php extensions like php-gd, php-mysql and others, Drupal 7 also needs php-xml to be able to work properly. EDIT: I've tried this with PHP 5.3.11 on Apache 2.2.21.