Studiebloggen: Udviklere samlet til kulturarvshackathon ved #hack4dk

Posted by & filed under In Danish, Studiebloggen.

Hvad sker der når man slipper tøjlerne og lader udviklere gå i kødet på danske kulturarvs institutionernes åbne webservices? Det var der ingen der vidste før Nationalmuseet, Det Kongelige Bibliotek og Kulturstyrelsen slog kræfterne sammen og arrangerede det første og bedste kulturarvs hackathon – nogensinde.

Vi startede fredag morgen med 8 lynhurtige og inspirerende ignite talks – et hæsblæsende format, hvor taleren gives 5 minutter, til at præsentere 20 slides der hver vises i 15 sekunder. Alle oplæg havde en forbindelse til åbne data eller open source udvikling.

Fredag kl. 13 blev arrangementet for alvor sparket i gang, da vi blev samlet i Den Sorte Diamant. Super god stemning og der blev snakket på tværs af både institutioner og fagområde. Rigtig inspirerende og thumbs up til arrangørerne for planlægningen, god mad og fine faciliteter – det eneste minus jeg kan komme i tanke om var den forholdsvis lange vej til toiletterne. Netop dette kan være et problem når man som udvikler sidder og laver noget så interessant at det var svært at slippe tastaturet.

Resultatet blev intet mindre end 10 unikke hacks og vinderne af årets hackathon var Maksim Sorokin and Kostas Rutkauskas, der havde bygget en native Android app som udpegede fredede og bevaringsværdige bygninger ved brug af augmented reality og Kulturstyrelsens dataset.

En ting er sikkert – jeg kommer igen næste år, så må vi håbe at de også afholder det igen.

  • Hvis du er udvikler, kommer du næste år og hvad vil du lave?
  • Hvis du ikke er udvikler: Hvad ville du lave – hvis du selv kunne programmere?
  • Hvis du var med til #hack4dk: Hvad var din oplevelse af arrangementet?

Skriv gerne dit svar i en kommentar og se flere billeder fra arrangementet på Jacob Wangs flickr-set.

Læs også indlægget om “Staten forærer CVR- og matrikelnumre væk i datafest” måske får vi endnu flere dataset vi kan hacke med næste år.

This article was originally posted on version2.dk

Click to read (please post and read comments there)

Building an HTML5/CSS3 website that demonstrates the “2 Egg Problem” problem

Posted by & filed under Games, In English, Tech.

To my knowledge this problem has been stated as a Google Interview Puzzle:

  • You are given 2 eggs.
  • You have access to a 100-storey building (in my implementation I have chosen to use a 20 story building, simply because it fits the screen).
  • Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100th floor. Both eggs are identical.
  • You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.
  • Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process.
A hint is that the optimal algorithm for a 20-storey (actually also 21-storey) building solves any configuration of the problem in at most 6 drops, can you find this? :)

So basically I have build a small website that enables a collaborative discussion around the problem. It was used at the open house event “åbenthus” at the Technical University of Denmark, in the beginning of this month. The website is a standalone web application which needs no special server, other than one that serves the static files. The website is hosted on my student account website at DTU and the source code can be found at a Github repository, where you can fork and build upon it.

Please let me know what you think about this tool and if you can find an optimal algorithm :)

My next Open Source adventure!

Posted by & filed under In English, Uncategorized.

Hi anyone (if anyone is out there) :)

I will be leading an open source project, named OpenARMS, developing an Audience Response Management System.
This will be a part of my academic studies, and it will involve ~10 days of intensive coding in the city of Kapfenberg, Austria!

For the purpose of sharing my experience I have decided to write a blog about it: http://openarms2012.blogspot.com/

Hope to get your comments on the project as it progresses :)

Mandelbrot meets HTML5 canvas, multi threads and local storage

Posted by & filed under In English, Tech.

Hello to anyone reading this.

I would like to publish my results from playing around with HTML5 canvas, multi threads and local storage.
Zoom into or out from the fractal using the mouse wheel while pointing to the point you would like to become the new center.
I have implemented a few keyboard shortcuts:

  • space: Redraws
  • PgUp: Increments the color resolution
  • PgDn: Decrements the color resolution

The fractal automatically redraws when the window gets resized.


Visit http://xfiles.creen.dk/mandelbrot/ to see my results.

Collabedit Java compiler and runner

Posted by & filed under How I solved my problem, In English, Tech.

I have an interview tonight, where I am told that I am supposed to do Java coding on a shared document via the collabedit.com platform.
As I am checked on both speed and correctness I figured that it would be nice to know when I did obvious syntax errors, but as far as I can see, collabedit supports syntax highlighting but does not support any error detecting or running of the actual program.
But it is possible to download your shared document, with the click of a mouse.
This is why I have just hacked together a small python script that listens for a file to be downloaded, and then runs the javac and java tools on it.
I call the script collabedit-java-compiler.py, and it is created to be used on a linux environment, you might be able to use it on other platforms by fx changing the os.system("clear") to os.system("cls") or likewise.

If you have any suggestions, feel free to comment.

#!/usr/bin/python
# Author: Kraen Hansen (www.creen.dk)
# Date: November 2011
import sys
import os.path
from time import sleep
 
def compile_java(filename, classname, autorun):
	print "Compiling "+filename
	result = os.system("javac "+filename)
	if result == 0:
		print "Compiled successfully!"
		should_run = autorun
		if not should_run:
			run = raw_input("Would you like to run it? [Y/n]")
			if(run != "n" and run != "N"):
				should_run = True
		if should_run:
			os.system("clear")
			folder = os.path.split(filename)[0]
			runcommand = "java -cp ""+folder+"" "+classname
			print "Running the program! ("+runcommand+")"
			print "------------------------------"
			print ""
			result = os.system(runcommand)
			print ""
			print "------------------------------"
			print "Program terminated with the signal:", result
			raw_input("Press any key to continue.")
	else:
		raw_input("Press any key to continue.")
 
def collabedit_java_compiler(filename, classname, autorun):
	running = True
	while(running):
		os.system("clear")
		if(os.path.isfile(filename)):
			print "Found the source file!"
			compile_java(filename, classname, autorun)
			print "Removing the file ..."
			os.remove(filename)
		else:
			print "Didn't find a file ... waiting 1 sec"
		sleep(1)
 
if __name__ == "__main__":
	print "Started the collabedit java compiler."
	if len(sys.argv) == 3:
		filename = sys.argv[1]
		classname = sys.argv[2]
		collabedit_java_compiler(filename, classname, True)
	else:
		print """Usage: "path to downloaded file" "Main java class":"""
		print """Example: ./collabedit-java-compiler.py /home/creen/Downloads/n6qp8.java Test"""

How I made Gmail my default email client (on linux)

Posted by & filed under How I solved my problem, In English, Tech.

So there I was. I just signed up for yet another membership in an organisation an I got myself yet another email to check. So I decided to add the 5th email inbox on my Thunderbird (2.0.0.24) desktop email client. But I quickly realized that 5 inboxes and lots of separate calendar feeds was causing Thunderbird a dramatic loadtime and with the GUI and data fetching running in the same thread, this caused the application to hang more than 30+ seconds every time I just wanted to open my email client to check my mail.

So I decided to do something that I should have done a long time ago: Use Google products as primary tools for managing my communications.

In this process I used a fair amount of time on adjusting the products to fit my needs, which included:

  • Adding all my different inboxes on different mailservers. (Using the “check mail using POP3” feature of Gmail).
  • Sending mail through my webhost’s SMTP server, which removed the “send on behalf of …@gmail.com” field on the e-mail header of the messages I sent out.
  • Creating a lot of filters for automatic categorization of my incoming e-mails.
  • Enabled IMAP support, so I could fetch my mail from a (Android) smartphone.
  • Added some lab stuff:
    • Custom date formats: 24-hour clock (14:57) or show dates with the day first (31/12/07).
    • Refresh POP accounts: Fetch messages from your POP accounts on demand by using the refresh link on top of the inbox.

But using a web application as an email client adds some problems. One which I made a solution for.

Clicking a mailto: link on a webpage or pressing your e-mail hotkey on your keyboard doesn’t bring you to your Gmail client. But this I fixed with a small python script (I called it gmail.py).

#!/usr/bin/python
# Author: Kraen Hansen (www.creen.dk)
# Date: February 2011
import sys
import os
import urlparse
 
if __name__ == '__main__':
	command = ""
	if len(sys.argv) == 2 and sys.argv[1] != "":
		argument = urlparse.urlparse(sys.argv[1])
		if(argument.scheme == 'mailto'):
			mailoptionsSplitted = argument.path.replace("?","&").split("&")
			options = {}
			if(len(mailoptionsSplitted) >= 1):
				options['to'] = mailoptionsSplitted[0]
			for option in mailoptionsSplitted:
				temp = option.split("=")
				if(len(temp) == 2):
					options[temp[0]] = temp[1]
			#print options
			command += "google-chrome --app='https://mail.google.com/mail?view=cm&tf=0"
			if 'to' in options.keys():
				command += "&to="+options['to']
			if 'cc' in options.keys():
				command += "&cc="+options['cc']
			if 'bcc' in options.keys():
				command += "&bcc="+options['bcc']
			if 'subject' in options.keys():
				command += "&su="+options['subject']
			if 'body' in options.keys():
				command += "&body="+options['body']
			command += "'";
		else:
			print "Unknown scheme:",argument.scheme
	else:
		command = "google-chrome 'https://mail.google.com/mail/#inbox'"
	os.system(command);

I saved this in my home folder of my linux machine (Linux Mint 8 / Helena with Gnome desktop environment and the Google Chrome webbrowser) and made sure that I had it had permissions for execution. Then I opened my “Preferred Applications” settings from the applications menu, where I specified that I would like to use my new script as my “Mail Reader”. (See the update below, if you cannot find the “Custom” option in the list for Mail Readers)
Now my keyboard pops up Gmail in a chrome browser (you can change this for any preferred browser) if I hit the hotkey on the keyboard and it opens the gmail compose dialog if I click a mailto: link on a webpage. It is worth noticing that the script supports the “to”, “cc”, “bcc”, “subject” and “body” fields of the mailto: querystring.

I hope this gives some inspiration to how you could set up your gmail and please let me know if you have done anything smart on your setup.

Update 22/9:

So I just installed Linux Mint 11 (derived from Ubuntu 11.04) and I wished to reproduce my solution, but sadly the Preferred Applications have been given redesigned, so I didn’t have the Customs option in the dropdown menu.

This is simply because it is removed. So I looked into how to get it there.
I realised that this was controlled by the MimeType value of .desktop elements in the
~/.local/share/applications folder.

So here is how to fix it:

Create a new file called gmail.desktop in the ~/.local/share/applications folder (~ being your /home/[username]/ folder of course).
Past into this file, something like this:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/home/[username]/gmail_logo.png
Name=Gmail
Exec=/home/[username]/gmail.py %u
Comment=Launch the gmail web application
Categories=Application;Network;Email;
MimeType=x-scheme-handler/mailto;

You have to change two things:

  1. Change the Icon variable to point to an image of the gmail logo. I have created one, with transparent background. You will have to download this and change the Icon variable to point to this.
  2. Change the Exec to option to match the location of your gmail.py script (pasted above). Remember to leave in the %u.

Take notice of the last line, stating the MimeType, as being x-scheme-handler/mailto, this makes it show up as a valid email reader in the preferred applications dialog.