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


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


How to Upload a Folder Recursive to FTP and display the Progress

I found a nice open-source FTP-Library that can upload files, change the directory etc.  (ftpLib.cs was originally written by Jaimon Mathew and modified by Dan Rolander and others).

But it lacks the feature to upload a Directory recursiv, therefore i coded a class with some Extension Methods.

I also made up a small Example:

Continue reading


SaveProgress Example for DotNetZip

When i was coding Send2FTP i needed a ZIP-Library that would be able to notify me about the progress while the compression.

After a littlebit research i found DotNetZip a really impressive ZIP Libary for dotNet.

But what i couldn’t find was a good WinForms example for the Save Progress Event. I Also don’t like to deliver my application with alot of dll’s therefore i packed the sources of DotNetZip into the Example.

So i made a small WinForms Example for implementing the SaveProgress Event of the DotNetZip Library and want to share it with you:

Continue reading