Fetch all Languages of the World (ISO 639) as Java Array

Recently i needed a Java Array of all Languages, containing some unique id.

I found that ISO 639 is exactly what i needed. The list is offered by the Library of Congress in a CSV like Format (link).

So i parsed this data and thought that maybe someone can use this, either the Java Array or the Code as Example for parsing external data with JavaScript.

 Demo:

To fetch the list i used Ben Almans JSONP Proxy and Ben Nadels CSVToArray Function.
Continue reading


Remove certain item or clear whole OmniFaces cache

The Omnifaces o:cache Component is a useful Tool when trying to speed up you jsf powered website.

But in some situations you need to remove a certain item from the cache or you want to clear the whole cache, while there seems to be a way (Example 4) to remove single items by Key we couldn’t find a ‘official’ way to clear the whole cache.

 

Here is our Solution to the Problem:

public static boolean removeOmniCacheItem(String key) {    	
	Map<string , Object> applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
 
	if (applicationMap.containsKey(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME)) {
		synchronized (DefaultCacheProvider.class) {
			if (applicationMap.containsKey(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME)) {
				((Cache)applicationMap.get(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME)).remove(key);
				return true;
			}				
		}
	}
 
	return false;
}
 
public static boolean clearOmniCache() {    	
	Map</string><string , Object> applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
 
	if (applicationMap.containsKey(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME)) {
		synchronized (DefaultCacheProvider.class) {
			if (applicationMap.containsKey(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME)) {
				applicationMap.remove(DefaultCacheProvider.DEFAULT_CACHE_PARAM_NAME);
				return true;
			}				
		}
	}
 
	return false;
}
</string>

Continue reading


Center Youtube

These days Youtube was revamped (at least the update arrived in germany too) and i was instantly annoyed by the left aligned design.

I wrote a super small greasemonkey script to fix it, and thought maybe somebody wants it too.

Have fun with it:

Link: The script on Userscripts.com

The Code:

// ==UserScript==
// @name       Center that damn youtube (for 1920x1080)
// @namespace  /
// @version    0.1
// @description  centers youtube.com on screens with resolutin 1920x1080
// @match      *youtube.com*
// @copyright  2012+, You
// @require    http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
 
jQuery('#page-container').css('margin', '0 0 0 300px');

Android Wifi Hotspot Manager Class

Android has the great option to let you Tether your connection via wifi, but as developer you got little to none control over this mechanism.

Therefore i wrote a class to correct this: WifiApManager.

With this class you can check the current Status of the Hotspot, enable/disable it, get/set the current AP configuration and also get the list of currently connected clients.

I also made an example to demonstrate it’s capabilities:

Continue reading


Flexible Displays and Surfaces

We read everywhere about new tablets, new smartphones or new televisions. These gadgets get thinner and yet we still can’t transport our televisions in our pockets. One essential display technology still didn’t arrive: The Flexible Displays.

Flexible Displays are obviously the next level in the development of displays technologies. They will change our lives in many ways. To find out what flexible displays actually are and what concepts exist in this area (there are really some extraordinary ideas out there). You can take a look at our paper and the references. Its only available in german, at the moment:

You can download our Paper here: Flexible_Display_and_Surfaces.pdf

Continue reading


Download and Display Image in Android

When you want to download a Image from the Web and Display it in Android in a ImageView i encountered two different approaches:

1. Download the Image and Display it:

Drawable DownloadDrawable(String url, String src_name) throws java.io.IOException {
	return Drawable.createFromStream(((java.io.InputStream) new java.net.URL(url).getContent()), src_name);
}
 
[...]
 
try {
	Drawable drw = DownloadDrawable("http://www.google.de/intl/en_com/images/srpr/logo1w.png", "src")
	ImageView1.setImageDrawable(drw);
} catch (IOException e) {
	// Something went wrong here
}

Continue reading


Find File Snippet – Depth First And Breadth First Search

Two usefull snippets, if you need to do a quick file search, here a recursive and a breadth first implementation (ignored the not-authorized-exception):
(took me only 2 mins, love .Net 🙂

Depth First Implementation:

static string[] FindFile_DepthFirst(string directoryName, string fileName)
{
   return Directory.GetFiles(directoryName, fileName, SearchOption.AllDirectories);
}

Breadth First Implementation:
Continue reading


Update GUI Control From Non-GUI-Thread Without Marshalling

In .Net when you want to update a GUI Control, for example a ListView, you have to execute your update code in the GUI Thread which controls your Form and its child GUI Objects. While you are in another Thread, you call the Invoke or BeginInvoke (for async.) method of your GUI Control for this purpose. You pass this method a delegate of your method, which contains your update code, and the GUI Thread invokes the method that is passed. Well the whole story is infact much more complicated and this article gives you a nice in-depth view on this topic:
WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred

 

This is how Microsoft wants us to manage our GUI stuff, Continue reading