Usman Saleem Java HelloWorld
Powered By
JBoss Web/7.0.13.Final
JavaServer Faces API - 2.0.1.Final
PostgreSQL 8.4.20
Primefaces
Openshift
Uzi's Blog - Main - IT
pp1234pp

Gruveo is an excellent anonymous Flash/browser based very simple video\audio chat website). Due to some weird bug in Ubuntu 13.10 which doesn't allow to change camera settings on individual website (such as Gruveo) through Flash settings popup, following workaround can be used through Flash's global settings.

Visit http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager06.html Select monitor with the eye tab (5th from the left), scroll down and select required site, http://www.gruveo.com, and then click radio button "Always Allow" (see following screenshot). Restart the browser and refresh gruveo again. The video chat is now working.

Screenshot:

Recently I switched from Fedora 18 to Ubuntu 13.10 on my personal Acer Aspire V5 laptop (a wrong decision when I bought it - anyways...). There are two annoying issues when using both Fedora and Ubuntu on this laptop

Skype Dark Video Screen issue

Skype works on both Fedora and Ubuntu, however, there is this darn issue of dark video screen. This can be fixed by using guvcview and/or from command line tool uvcdynctrl as discussed by this guy in detail.

To ease up calling uvcdynctrl, you can create a launcher and add it to the dash. Follow this link to create desktop launcher in Ubuntu.

Fn keys Screen Brightness issue

The second issue is that screen brightness doesn't work, neither Fn Brightness (blue Fn - left right keys) nor from System Settings ... Brightness & Lock.

To fix the issue for System Settings, we need to add acpi_backlight=vendor to kernel command line parameter as part of grub config. For Fedora follow similar approach for grub2, following approach works in Ubuntu. Update GRUB_CMDLINE_LINUX in /etc/default/grub then run update-grub and restart.

To make the Fn key work again, try fixing /etc/acpi/asus-keyboard-backlight.sh and update KEYS_DIR to KEYS_DIR=/sys/class/backlight/intel_backlight. This will allow Fn scripts to call the correct scripts instead of default values (which doesn't work anymore after using acpi_backlight=vendor). Restart to test it.

P.S. Ubuntu seems to have become more user friendly than Fedora (shh...don't tell my former colleagues back at Red Hat ;-))

Added http://usman.id.au which also points to (via CNAME) this application hosted on OpenShift, similar to my existing domain, http://www.usmans.info.

Updated my blog software to provide blog sections. Ideally these are suppose to be "blog categories" while categories are suppose to be "tags", since I already had used "categories", I named then as "Blog Section". For now, there is Experiments section. In future I am planning to add Urdu only sections etc.

New browsers are capable of showing custom embedded fonts which can be specified by using @font-face css tag. This allows web designers to use custom fonts which users don't need to install on their machine.

With custom font (Hussaini Nastaleeq):

پروگرامنگ کی دنیا میں خوش آمدید . یہ ایک اردو فونٹ ٹیسٹ ہے

Without custom font (System default):

پروگرامنگ کی دنیا میں خوش آمدید . یہ ایک اردو فونٹ ٹیسٹ ہے

If font style is same in all above samples, you are probably not using most recent browser capable of using font-face css style.

The custom font `Hussaini Nastaleeq` is a fork of Nafees Nastaleeq and is available here. The font is quite small in size (~ 300K) and browser should only download them if they are used by the page.

Tested on Linux (Fedora 17) on Chrome Version 22.0.1229.94 and Firefox Version 16.0.1, Opera (Windows) and Chrome (Windows). The best rendering is on Firefox though.

Numerous efforts are made to make this font work on IE 8 (which uses eot), however, still not able to make it work on IE8 unfortunately. The font is converted from ttf to eot on Linux using ttf2eot eot-utilities.

On JBoss side (if using JSF), you probably need to specify correct mime types for the font types. Here are the implementation details:

- web.xml:



        ttf
        application/octet-stream
  
  
        eot
        application/vnd.ms-fontobject
  
- css file:

/* Required first for IE, no format */
@font-face
{
  font-family: u; 
  src:  url("#{resource['fonts:nafees_riqa.eot']}");
}

@font-face
{
  font-family: u;
  src: url("#{resource['fonts:nafees_riqa.ttf']}") format('opentype');
}

#nrfont {
  font-family: u;
  font-size: x-large;
}
- JSF template:

  <h:outputStylesheet name="uzi.css" library="css" />
- Applying font:

<div id="nrfont"> ... 

Just moved the datasource to use jta. Last time it was not working, looks like it started working now ... strange!
My blog project is now moved to maven build system from old Eclipse project. It is also now directly merged/synchronized with openshift git repository. In addition, I ended up writing my own RSS feed generator. Good stuff. Check out my github profile for the source code of this blog.

Time to jump openshift bandwagon, start using PaaS (platform as a service) and join Cloud. Why do I need it and what is Openshift?

My expertise area is JEE development, and I try to keep myself updated with the latest technologies by "getting my hands dirty" in coding. Some time ago, I implemented my own JEE based blogging implementation and decided to host it on resin and then followed by JBoss AS 7. The next step was to get a good, reliable and cheap JBoss hosting. I manage to get a cheap "VPS" host (around 10$/month), however, I wasn't happy with it. Too unreliable, too slow, much lesser resources. And I have to manage everything by hand, monitor JBoss, monitor my HSQLDB etc. Even though its raw power to control things as you please, but it gets too time consuming pretty soon.

Openshift comes to the rescue.

From offering perspective, at the moment, they provide free of cost developer preview (and I hope this will remain as it is). For a low volume site like mine, this was perfect. It provides me a ground to test with the latest and greatest technologies at no fraction of cost.

From technology perspective, I was able to setup one instance of JBoss AS 7 and PostgreSQL 8.4 within minutes, ready to push my changes via git. The main time spent was converting my blog data from hsqldb to PostgreSQL. Openshift provide hooks and access to manage all it with ease - a developer's dream. Pretty neat.

Now the scalability, assuming that my site becomes very popular, I can add another JBoss instance to scale my load (same goes for PostgreSQL instance), this is the true beauty of "PaaS".

So there you go, get yourself an Openshift account and start experimenting. Stay tuned for my further Openshift experiments :)

Are you looking for some really advanced Java discussions? then subscribe to The Java Specialists News letter manage by Java Champion Dr. Heinz Kabutz.

Of course, my all time favorite topic (which I always refer to my new class of Java students :-)) is Java programmers aren't born.
The other day I needed to write a C function which search and replace all tokens in a char * aka C strings. Searching on google doesn't returned too many promising results, hence I ended up writing my own function. Here it goes:
/*
* casr --- C based search and replace program in a char *
*
* Author: Usman Saleem - usman.saleem@gmail.com
*
* This code is released under The MIT License.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyrights (c) 2010, Usman Saleem.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
* The search and replace function attempts to replace
* 'token' with 'replacement' on a copy of 'line'.
* Returns:
* - NULL for invalid arguments or out of memory
* - 'line' reference if nothing to replace
* - char * with all tokens replaced.
*
* The caller should call free if the reference to 'line' and
* returned value is different
*/
char * csar(char *line, char *token, char *replacement)
{
    char *result, *finalresult; /* the return string */
    int token_length; /* length of token */
    int replacement_length; /* length of replacement */
    int count;  /* number of replacements */
    char *tmp;
    char *curr;
    int diff;
    /* Basic sanity of arguments */
    if (!line)
    return NULL;
    if (!token || !(token_length = strlen (token)))
    return NULL;
    if (!replacement || !(replacement_length = strlen (replacement)))
    return NULL;
    /*return same line if there is nothing to replace */
    if (!(strstr (line, token)))
    return line;
    curr = line;
    /*determine count of tokens */
    for(count = 0; tmp = strstr(curr,token); count++)
    {
        curr = tmp+token_length;
    }
    /*allocate memory*/
    finalresult = result = malloc(strlen(line) + (replacement_length*count) + 1 - (token_length*count));
    if(!result)
    {
        return NULL; /*out of memory?*/
    }
    /*move to beginning of line*/
    curr = line;
    for(;;)
    {
        /*determine next location of token */
        tmp = strstr(curr, token);
        if(!tmp) break;
        diff = tmp - curr;
        strncpy(result, curr, diff); /*copy the pre-token part*/
        strcpy(result+diff, replacement); /*copy replacement*/
        strcpy(result+diff+replacement_length, tmp+token_length); /*copy rest of stuff*/
        /*move to next token position*/
        curr = curr+diff+token_length;
        /*update result position to next replace position*/
        result = result+diff+replacement_length;
    }
    return finalresult;
}
int main(void)
{
    char *line1="";
    char *line2="abcdef";
    char *line3="abc@abc.txt@@def@";
    char *line4="@middle@";
    char *line5="@";
    char *line6="@@@";
    printf("line1: %s replaced with %s\n",line1, csar(line1, "@", "xxATxx"));
    printf("line2: %s replaced with %s\n",line2, csar(line2, "@", "xxATxx"));
    printf("line4: %s replaced with %s\n",line4, csar(line4, "@", "xxATxx"));
    printf("line5: %s replaced with %s\n",line5, csar(line5, "@", "xxATxx"));
    printf("line6: %s replaced with %s\n",line6, csar(line6, "@", "xxATxx"));
    char *temp = csar(line3, "@", "xxATxx");
    char *temp1 = csar(temp, ".", "xxDOTxx");
    printf("line3: %s replaced with %s\n",line3,temp1 );
}