Development

Image previewer for Java

Posted in Development, Java on January 8th, 2011 by admin – Be the first to comment

At the moment I’m processing images in a CLI-Java-application. For debugging puposes it’s sometimes nice to have a way to display Image objects, like some kind of visual replacement for System.out.println(xyz).

This small method might be helpful in such cases:

public static void preview(Image image) {
	JFrame frame = new JFrame();
	JLabel label = new JLabel(new ImageIcon(image));
	frame.getContentPane().add(label, BorderLayout.CENTER);
	frame.pack();
	frame.setVisible(true);
}

Use Notifo’s API with Java

Posted in Development, Java, iPhone on January 8th, 2011 by admin – Be the first to comment

This is just a small hack to use Notifo’s API with Java:

URL url = new URL("https://api.notifo.com/v1/send_notification");
URLConnection connection = url.openConnection();
String authorizationString = "Basic " + new String(Base64.encodeBase64((username + ":" + apiSecret).getBytes()));
connection.setRequestProperty("Authorization", authorizationString);
connection.setDoOutput(true);
OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream());
output.write("to=m");
output.write("&msg="+URLEncoder.encode(msg,"UTF8"));
output.write("&uri="+URLEncoder.encode(uri,"UTF8"));
output.write("&label="+URLEncoder.encode(label,"UTF8"));
output.write("&title="+URLEncoder.encode(title,"UTF8"));
output.flush();
output.close();
connection.getInputStream().close();

(Remember: This is just a quick’n'dirty solution. It just works for me and is not especially beautiful)

This code depends on Apache Commons for base64-encoding.

Feel free to drop me a line, if this was helpful. The code is released under WTFPL ;-)

DHBW Connect – Autologin für das WLan der DHBW Mannheim

Posted in DHBW, Development, Java on December 5th, 2010 by admin – Be the first to comment

Letztes Woche ist es fertig geworden: “DHBW Connect” ist ein kleines Java-Programm, welches dich bei existierender WLan-Verbindung automatisch anmeldet. Du musst also nur noch ein einziges Mal deinen Benutzernamen und dein Passwort eingeben. (Wichtig: Nach Start der Datei passiert nicht viel – Es wird nur ein Trayicon neben der Uhr angezeigt. Um euer Passwort einzustellen genügt ein Rechtsklick|Konfigurieren auf dieses Icon.)

Netter Nebeneffekt: Durch den Verbindungscheck alle 10 Sekunden ist die Verbindung gefühlt ein wenig stabiler. Vielleicht ist das aber auch nur Einbildung… ;-)

Hier ist der Download. Wer mitentwickeln will oder eine intelligente Erweiterung hat, kann das Programm gerne bei Github forken.

Animierte Favicons

Posted in Development, Icons, Tutorial, Webdevelopment on October 7th, 2010 by admin – Be the first to comment

Es gibt nichts schlimmeres als nervige Gif-Animationen. Es sei, ich setzte sie ein.

Daher habe ich mir überlegt, statt einem langweiligen Favicon mal was bewegtes zu verwenden. Leider musste ich mir sagen lassen, dass nur Opera und Firefox diese unterstützen. Google und Apple meinen es wohl gut mit unserem Sehnerv und akzeptieren nur unbewegte Bilder.

So dachte ich auf jeden Fall, bis ich auf “Defender of the Favicon” stieß. Dort hat jemand wirklich Defender in einem Favicon spielbar gemacht – was sowohl in Chrome und Opera funktioniert.

Die Idee ist eigentlich relativ einfach: Man nehme ein 16x16px Canvas, male beliebigen Inhalt darauf, lese das PNG als Data-URL aus und weise es dem passenden <link>-tag zu.

Auf HTML-Seite sieht das ganze so aus:

<head>
...
<link rel="shortcut icon" href="favicon.png" id="favicon" type="image/png" />
...
</head>
<body>
...
<canvas id="favicon_canvas" width="16" height="16" style="display: none;"></canvas>
</body>

Das Javascript sieht folgendermaßen aus:

var ctx = document.getElementById('favicon_canvas').getContext('2d'); 
var icon = document.getElementById('favicon');
 
 
function setFavicon() {
	ctx.fillStyle = 'blue';  
	ctx.fillRect (0, 0, 16, 16);
	// Die Ecken "abrunden"
	ctx.clearRect(0,0,1,1); 
	ctx.clearRect(15,0,1,1);
	ctx.clearRect(0,15,1,1);
	ctx.clearRect(15,15,1,1);
	icon = document.getElementById('favicon');
	(newIcon = icon.cloneNode(true)).setAttribute('href',ctx.canvas.toDataURL());
	icon.parentNode.replaceChild(newIcon,icon);
}

Und schon hat man ein blaues Favicon mit leicht abgerundeten Ecken. Packt man das ganze jetzt noch in ein setInterval() hat man ein ähnlichen Effekt wie bei dem animierten GIF im Firefox.

Auf marekventur.de habe ich jetzt alle drei Favicon-Arten kombiniert: Der IE sieht nur ein statisches Bild, Firefox spielt ein animiertes GIF und Opera und Chrome zeigen eine Welle, die wie der Schriftzug die Farbe und den “Wasserstand” wechselt. Safari macht leider gar nichts. C’est la vie.

Tutorial: Color changing liquid effect with jQuery

Posted in Development, Tutorial, Webdevelopment, jQuery on October 4th, 2010 by admin – 2 Comments

This tutorial is on how to archieve a color changing liquid effect (like this one) with jQuery. It’s actually quite easy to implement, altough there is a small trap. It’s made with plain CSS2 and will run in every modern browser (note: I don’t consider IE6 as a “modern browser”).

LayersThe trick is to use three layers: The first is the symbol or the text, with the essential parts left transparent, the second is a gray layer with a transparent wave at the bottom an the last is a solid CSS-background-color. With some jQuery-magic to animate the second layer you can create an effect of wavy liquid.
read more »

marekventur.de geupdadet

Posted in Development, Webdevelopment, jQuery on October 3rd, 2010 by admin – 1 Comment

Screenshot marekventur.de

Nachdem meine erste Version für marekventur.de ziemlich überladen war (und irgendwann durch ein falschen “rm -R” ins Daten-Nirvana ging) war bis letzte Woche noch eine schnell erstellte 30-Minuten Seite online. Nun hab ich mir mal die Zeit genommen, ein bisschen zu basteln und habe eine neue Version online gestellt.

Über das technische werde ich später noch ein wenig bloggen, bis dahin muss es reichen in den Raum zu werfen, dass die Seite auf CSS2 und jQuery basiert und im IE6 richtig schön gegen die Wand fährt…

Btw: Es gibt jetzt auch kein de.marekventur.de bzw. en.marekventur.de, sondern die Second-Level-Domain ist jetzt standartmäßig englisch – die Zahl derer, die die Halbsätze auf so einer Seite nicht verstehen geht wohl so ziemlich gegen null.

jQuery animation easing

Posted in Development, Webdevelopment, jQuery on September 30th, 2010 by admin – Be the first to comment

“Animation easing” makes animating with jQuery much nicer. Instead of just changing an attribute linearly from x to y you can use build-in easing-functions to make make your animation acelerate, bounce and much more – they often look more convincing this way (at least I think so).

To get a glance at the graphs of the functions you can have a look here. You can find everything on how to use them in the jQuery manual.

DHBW Mannheim Notenabfrage

Posted in DHBW, Development, Webdevelopment on September 30th, 2010 by admin – Be the first to comment

Für alle DHBWler aus Mannheim hier der Link zu einem Webtool von mir, welches das regelmäßige Abrufen der Noten von diesem Groupware-Dings erspart. Da das Tool nur die Groupware abfragt funktioniert dies also nur für die 08er-Jahrgängen vor der Umstellung auf das Dualis-System:

Weiter zu DHBW Mannheim Notenabfrage

Disclaimer: Die Daten (inklusive eures Groupwarepassworts und euren Noten) müssen prinzipbedingt auf meinem Server liegen, sonst kann das mit der automatisierten Kontrolle nicht funktionieren. Ihr müsst mir also ein gewissen Vertrauen entgegenbringen, dass ich die Daten ordentlich behandle und keiner (auch nicht ich!) sich die Noten anderer angucken wird. Wer Fragen dazu hat kann mir gerne eine Mail schreiben.

SWFUpload mit jQuery

Posted in Development, Resourcen, Webdevelopment, jQuery on September 28th, 2010 by admin – Be the first to comment

Eine der letzten konzeptionellen Daseinsberechtigungen für Flash: Fileupload mit Fortschrittsanzeige.

Wer -wie ich- keine Ahnung von Flashprogrammierung an sich hat, für den bietet sich SWFUpload an. Das “offizielle” Javascript ist ziemlich unschön, umso besser also dass sich schon jemand die Arbeit gemacht hat, ein jQuery-Plugin dafür zu schreiben.

Hier könnt ihr es in Action erleben.

Using the command line with java

Posted in Development, Java, Linux, Resourcen on September 20th, 2010 by admin – Be the first to comment

If you are looking for a simple way to use the command line via Java use this wrapper class. It offers a simple solution for a simple task. KISS!

How to use it:

System.out.println(new CommandLine("/var").exec("ls"));

And here is the class:

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
 
public class CommandLine {
 
	private String path ;
 
	public CommandLine() {
		path = "/";
	}
 
	public CommandLine(String path) {
		this.path = path;
	}
 
	public String getPath() {
		return path;
	}
 
	public void setPath(String path) {
		this.path = path;
	}
 
	public String exec(String cmd) {
		String s = null;
		String ret = "";
		File workDir = new File(path);
		try {
			Process p = Runtime.getRuntime().exec(cmd, null, workDir);
			int i = p.waitFor();
			if (i == 0){
				BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
				while ((s = stdInput.readLine()) != null) {
					ret = ret + s + "\n";
				}
			}
			else {
				BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
				while ((s = stdErr.readLine()) != null) {
					ret = ret + s + "\n";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}
 
}