tirsdag 13. august 2013

MarkDown Library Search

To no avail so far.

I would really like to use MultiMarkDown because Byword and Scrivener uses it and I like the dialect. Now, if I only could find a library that lets me generate a site from MarkDown files in my project... I searched libraries on the MarkDown library list. But none fit the bill (in june 2013).

This thread on Stack Overflow lists some options, mostly for PanDoc.

PanDoc is a nice runner-up, seems to have more utilities:
Pandoc-Extras lists editors, libraries, scripts, generators...

PegDown seemed OK, but turns out it picks extensions from different dialects.

Of the Java libraries: Markdown4j will implement PanDoc extensions, MarkdownJ seems deserted.

Maven uses TxtMark: com.github.rjeschke / txtmark / 0.10
Play uses Tatua: org.tautua.markdownpapers/markdownpapers-core /1.3.4 / (in play)
 

Groovy Ant

In case you cannot use Gradle, here is how to get Groovy task in Ant, and how to call a macro from Groovy.

   
       
               
               
       

   


   
       
            println "Hello World"
            def ant = new AntBuilder( project )
            ant.testmacro( dir: "qwerty" )
       

   


   
       
       
           
       

   



tirsdag 6. november 2012

Tidsklemt og faglig skjerpa

Notatene fra Open Space på Smidig 2012. Jeg skriver dem ned for jeg ønsker (!) å kunne formulere en bedre strategi for meg selv. Her er det:

Innledning

Jeg har utvikla profesjonelt i nesten 20 år. For 4 år siden ble jeg pappa, og har fått mye mindre tid til å holde meg oppdatert faglig, og tiden er mer oppstykka. Jeg er stadig på utkikk etter effektive læringsmetoder og -strategier, helst de som hjelper opp på høyere nivå (Dreyfus).

Stikkord

Ukeplan med ting man må gjøre, og ting man vil gjøre.
Forplikte seg til å gjøre noe
Gjøre noe ilag med andre.
Være aktiv i faggrupper, meetups - Hackeriet ble fremhevet.
Ha en strategi, langsiktige mål, unngå fragmentering
Velge prosjekt som passer strategien
Velge ting man kan lære eller trene på i prosjektene man gjør.
Tilpasse prosjekt man er i.
Gjøre Code Katas.
Open Sourcing: undertegnede skilte ut en utility fra et prosjekt. På den måten fikk jeg praktisert Scala, som er vanskelig å få gjort ellers på prosjekt, og drevet et prosjekt i flere iterasjoner (fordi det er brukt andre steder). Mer om dette her.

Depositum: investere selv for å få en fot innafor døra og kunne ta prosjekt som gir videreutvikling.

Vanskelig å finne og filtrere hva man bør oppdatere seg på. Nyttige ressurser er: JavaPosse (podcast), konferanser (JavaZone), diskutere med andre engasjerte.
Det fins en uendelighet av teknologi-nyheter.


Trening ser ut til å gi energi hos andre. Heller "trene på å sette seg ned ved arbeidsbordet hver kveld klokka 9".
Begynne tidlig på jobb - da får man stilletid. (Overtid er ikke så bra for det er ikke tidsbegrensa).

"The Hemingway Hack": Hemingway la ned pennen når han visste hva han skulle skrive videre, da fikk han en god start neste dag. Omtrent som å skrive en test som feiler før man gir seg for dagen.
TODO-lister har variabel verdi.

Ressurser:
Coursera ble likt: de gir online kurs med faste tider per uke som må følges opp.
MIT forelesninger er ofte interressante / annerledes.

Tillegg

Om man ser etter bøker så har man fx Jolt-awards på DrDobbs.
Inspireasjon: Pragmatic Magazine, blogs/rss.
Kode kata: cyber-dojo, Dave´s codekata, Oslo meetup, codingdojo.org.

Mer inspirasjon fra The ultimate Code Kata, Teach Yourself Programming in Ten Years. og hvorfor ikke blogge.


lørdag 18. august 2012

Publish! (JavaZone 2012)

Lightning talk from JavaZone 2012. As promised here are the notes, with pointers to more information.

Links to more information

Google code hosting: Getting started.
Example pom for Google hosted projects.
GitHub (getting started on front page).
Example project / pom for GitHub hosted projects.

Sonatype OSS Repository Hosting Service: Usage guide.
Blog post with more details than the above (but not up to date)
Guide from Apache.

About Open Source Licenses.

Script

Welcome to this talk titled Publish! It is about publishing an Open Source project.
I will try to convince you that this is not hard to do, and that you stand to benefit from doing such a thing.
My name is Tommy Skodje
I work for the consultancy Antares, we have a stand out in the hall.
I have programmed for some years now, but only yesteryear I opensourced my first project, test-data-control. A tool for exporting / importing data from database.
That was a good experience, and I want to share this with you.

First version

Now for the 9 steps I took to publish the project.






I created the project on Google Code Hosting and used project information to fill in Jira ticket on Sonatype OSS Repository Hosting Service
That´s how I asked Sonatype to create Maven repositories for me.
There was not much to the creation forms - Googles is the big one with 6 fields (you have to select vcs and license).



Jira ticket needs the same information, plus urls to the project hosting, and groupId
I got a reply on the ticket, asking me to change groupId.
So I did, and the next day my ticket was resolved and I could code and deploy my project to Maven repositories on Sonatype.
With this formalities around the project were done.

Releasing

After a while I was ready to stage a release - I did it using normal maven release procedure, which put my artifacts into Sonatypes Nexus.
I then logged in to Sonatypes Nexus, found my repository and pushed 4 buttons to release my staging repository.
The first time I released I commented my Jira ticket to let them know they should verify my project and turn on Maven Central synchronization if OK.
The next day Jira mailed me the reply and I found my artifacts in Maven Central.

Central Sync requirements

Before I could stage the first release, my pom needed at least the 12 lines on the left.
Javadoc and source artifacts has to be produced.
Artifacts signed using GPG.
Sonatype helps by providing oss-parent pom that defines tasks related to releasing, and they give nice instructions about how to install and set up GPG signing.
Project does not need to be Mavenized, but it needs a pom.

Licensing

I chose Apache v2. Applying it is easy - added LICENSE and NOTICE files on top level, and comment all source files.
NOTICE is for honoring inclusions - now that I published I needed to track licensing of libraries and code I include.

Subsequent versions

After the first release, it got a lot easier.

I should have

Project was almost coded ready when I took out the Jira ticket.
Then I refactored package structure and pasted in Copyright all over.
And then a complete rewrite in Scala…
I would have been better off starting with the formalities and no code.
I chose a poor name - what a pity - project name is final. The other stuff is mutable.

Why

Curiousity and ambition got me started.
I wanted to learn more about opensourcing, and show off me and Antares.
But I soon realized that Open Source programming differs from inhouse-projects in many respects.
Theres was no restrictive firewall or policies. I could cod and commit whenever I had internet. I even submitted work from my iPhone.
Schedules and pressures were not the same either. I felt more pressure to code cleanly than quickly.

And with myself at the helm I could pursue my own agenda.

So I ported it to Scala.
I had just read the book and wanted some practice.
Clients would not mind implementation details.
That was a big job, I have done several other small stunts.
I now want to make a command-line utility of it that interpretes an external DSL.
There was a nice article in PragPub magazine that I am keen to follow up on, and I have also read too much about DSLs that I haven´t practiced yet.
And both should be a nice fit here.
I rarely get to do such things otherwise.
A Young Girl Reading, Jean-Honoré Fragonard
Normally, on daytime projects, I stop and do research when there is a need.
Now, I can read stuff from the stream that may fit nicely, or that I really would like to try.
And I can! Even if the project was «done» 2 months ago…

Having a side project facilitated deeper learning.
I tried to practice TDD from the start.
Many a time I gave thanks to my former self for doing that! Automated tests made it a lot easier to code a little now and then.
And also release quick changes that I needed on my daytime project.
That helped TDD click with me!

Going public was scary.
More than once I pondered my craftsmanship.
I did more beautifying, simplification, refactoring and testing than earlier.
Slowed me first, but I improved.
One day at work I realized I could do it, efficiently and confidently.
Publishing my work has driven me to evolve.
El Afilador, Francisco de Goya

Being my own client has been wonderful.
I could sharpen my own tool and skills at the same time.
API cumbersome or lacking? I improved it. More usable with each reuse.

Many revisits makes this feel like growing SW.
And I gradually learned more about design, documentation and testing.
Also because I forget stuff between iterations, and I can see better when I start with fresh eyes.




Thank you

I really enjoy the project, tinkering with it, making it better every now and then, and learning by practicing. I would like to say thank you to Sonatype, Google, GitHub and all the other hosting sites for making this so convenient. And to Øystein Pettersen at Evry for telling me where I could get synchronization to Maven Central.

fredag 16. september 2011

JavaZone: introducing Apache Wicket

Presentation from JavaZone 2011: http://javazone.no/incogito10/events/JavaZone%202011/sessions/Introducing%20Apache%20Wicket

Video posted to http://vimeo.com/28791557

Notes:

7 years old framework, Wicket 1.5 just released

Component oriented, using just java+html

Used by: AdScale, WalMart, MeetMoi, fabulous40...

Just html: elements linked to wicket by attributes: <p wicket:id="foo">, no imperative markup in view.

Just Java: no logic in markup, Components are POJOs, No xml

Components: Manipulate markup, Render content, Receive events (onClick)

Models: data to / from Components, transform data

Behaviors: Decorator / Adapter for Component, manipulate markup of Component, can receive events (onClick), Add Ajax unctionality to Components

Wicket projects: Apache Wicket (core, integration to Spring...), Wicket stuff (components), Seam for Apache Wicket, WiQuery (jQuery), Leg before Wicket (archetypes), Apache Isis (DDD framework), Jolira Tools, Visural Wicket (components)...

Quick start: use Maven, http://wicket.apache.org/start/quickstart.html

Some examples: Hello World, click-counter, sign-up

Navigation: Overview and some detail on: External link, Bookmarkable link, Action

Validators: Overview, simple example and list of provided validators

jQuery integration: WiQuery overview and example

JqZoom: Example, zoom on image, how to integrate

Development / Deployment mode: List differences and show some features

WicketTester: Tests components, UI, Ajax, without starting server, runs in IDE, ant, maven

New in 1.5: Html5 input types, component event bus, some new components, improved internals, simpler request cycle, and more

Component event bus: pre/post example

Wicket 6: next version, preliminary list of features. Shorter release cycle.

Q&A: How do components handle history button? Do you endorse Wicket WebBeans for rapid development?

torsdag 16. juni 2011

OpenSourcing

I recently published my project, test-data-control, on googlecode, and want to jot down some stuff before I forget.

I wanted a subversion-enabled hosting, and chose Google because I have the impression they're fast and convenient pluss I like their philosophy.

At first, I found that I had to choose a license and structure the project so that it goes nicely into Google. I had a little ponder, but chose Apache license to go easy.

Filling in the form was straight forward, but I should have drafted it before I started on the web, these fields were filed:

Project name, summary, description. version control system, license and label(s)

Gotcha: Project name and version control system can not be changed later.

 

I then proceeded to apply for Sonatype OSS Maven Repository access, so that other projects can get to this library (they even push to Maven Central). Following the Usage guide, I found I needed some more stuff, mainly in pom, and should change my groupId.

Wisdom: I should have known what it took before I first comitted project to Google, but it wasn't a big sweat.

 

All in all, the application processes were smooth and pleasan. Google project hosting was available immediately, Sonatype OSS Maven Repository access was ready for me over night (I'm on European timezone, so I guess they work when I sleep, which is a nice thought).

 

I was also surprised to experience a period of euphoria, having published something for the first time. I'd say it's worth the extra effort of preparing it and publishing it just for that feeling. Another nice thing I have experienced since I started sharing my ambitions with coworkers is that my status have increased so that I'm being used as an authority and pulled into discussions about related issues. I also get all kinds of tips now that they know I'm working on this thing. It feels like the project is starting to pull it's own weight.

The authority stamp feels a bit premature, because I feel that I need to produce a fully working system and prove it before I can claim that. I'm only glad that I did a fair bit of literature research before I came to this, so I'm usually able to answer and give some advise without making a fool of myself.

tirsdag 24. mai 2011

Meetup om testing i Framsia

Det handler om å kjøre (all) koden din, så ofte som mulig, med så gode tilbakemeldinger som mulig.

Buster.js ble presentert.

OperaDriver og ChromeDriver kommer sannsynligvis til Selenium 2 beta 4

Mange tester for html5 er skrevet i WebDriver

onsdag 18. mai 2011

Doing SW Architecture / Research Project

When researching a new tool or a framework API for use I find myself getting tired or bored after spending time doing work that will not be directly productive, and previously I have made rush decisions or didn't "go all the way", thinking that "barely sufficient" = enough.

The other day, I started thinking that different ways of revisiting such projects should add real value. preferably, there should be (at least) 1 more person with a fresh attitude who can continue from where I left, and/or do:

  • review / inspection
  • come up with new ideas
  • bring more involvement / acceptance from the whole group

If it is too hard to get 1 more person, it may be wise to simulate him by taking a break from this project and revisiting it later.

 

fredag 1. april 2011

SiteMesh

SiteMesh

From OpenSymphony.

Code can be downloaded here.

 

Overview

Web-page layout and decoration.

Aids generating consistent look/feel, navigation and layout scheme.

Can include other pages (server-side include).

J2EE, but can be used outside as well (PHP, CGI...).

Extensible.

 

 

Setting up

 

pom.xml:

<dependency>

<groupId>opensymphony</groupId>

<artifactId>sitemesh</artifactId>

<version>2.4.2</version>

</dependency>

web.xml:

<filter>

<filter-name>sitemesh</filter-name>

<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>sitemesh</filter-name>

<url-pattern>*.jsp</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>sitemesh</filter-name>

<url-pattern>*.do</url-pattern>

</filter-mapping>

<jsp-config>

<taglib>

<taglib-uri>sitemesh-page</taglib-uri>

<taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>sitemesh-decorator</taglib-uri>

<taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>

</taglib>

</jsp-config>

Copy in mentioned files (tld)

decorators.xml:

<decoratorsdefaultdir="/decorators">

<decorator name="main" page="main.jsp">

<pattern>*</pattern>

</decorator>

 

<decorator name="printable" page="printable.jsp"/>

</decorators>

 

Default logic to determine what decorator to apply, first match:

  1. Meta decorator tag in page
  2. Don't apply a decorator to frame set
  3. Url with printable=true parameter (If so, use the printable decorator.)
  4. Does the page specifically request a decorator by the decorator file name?
  5. Does the page url match a pattern in the decorators.xml file?

Can be overridden.

Decorator example

<%@taglib uri="sitemesh-decorator" prefix="decorator"%>

 

<decorator:usePageid="myPage"/>

<html>

<head>

<title>SiteMesh main - <decorator:title default="Welcome!"/></title>

 

<decorator:head/>

</head>

 

<body>

<h1>SiteMesh main <decorator:title default="Welcome!"/></h1>

<h3><a

href="mailto:<decorator:getProperty property="meta.author"

default="staff@example.com"/>">

<decorator:getProperty property="meta.author"

default="staff@example.com"/>

</a>

</h3>

<hr/>

 

<decorator:body/>

 

<p><small> (<a href="?printable=true">printable version</a>)</small></p>

</body>

</html>

torsdag 10. juni 2010

BluKbapp

Bluetooth keyboard

Plan

Details in ReadMe file.

Maybe also (books code):

User-Space Java Bluetooth (JSR-82) Keyboard Driver.

BlueCove

JSR-82 implementation on Java Standard Edition (J2SE). I had some problems making it work on Mac OSX 10.6, but this seems to be fixed by a beta version 2.1.1-SNAPSHOT (cf. BlueCove does not work with Mac OS 10.5.x, Java 1.6.0 - 64 Bit).

To get tester running I had to use 32-bit mode from command-line:

  • java -jar bluecove-tester-app.jar -cp bluecove-2.1.1-SNAPSHOT.jar -d32

 

Research

Put in deli tag bluekey.

Java bluetooth home.

jsr82.com.

Palo Wireless has som l2cap details.

torsdag 26. november 2009

Scala - learning notes

Plan

Do it standing, about same mix of slides and coding as before, handouts.

Slide: Tom Waits + install
Slide/Code: fire up scala and show off syntax (REPL)
Slide: motivation
Slide: My verdict + References
Slide/Code: Bonus section

Presentation

“Your hands are like dogs, going to the same places they’ve been. You have to be careful when playing is no longer in the mind but in the fingers, going to happy places. You have to break them of their habits or you don’t explore; you only play what is confident and pleasing. I’m learning to break those habits by playing instruments I know absolutely nothing about, like a bassoon or a waterphone.”—Tom Waits

(Picture from flickr / Conor Lawless).

Install

Download zip-file, unzip, set SCALA_HOME and add to PATH.
Then: install plugins for NetBeans (6.7+, prefer 6.8) and eclipse (3.5+).
I did best letting NetBeans handle project (not Maven).

Syntax / REPL

scala.bat: Quick Read Evaluate Print Loop



































Code Points
to make

class PhoneNumber( val kind: String, var no: String ) {

override def toString(): String = {
no + " (" + kind + ")"
}
}

switch to name: type

val / var / def

primary constructor

Concise

object PhoneNumber{

def apply( kind: String, no: String ) : PhoneNumber = {
new PhoneNumber( kind, no )
}
}

object, no statics

apply is "default method"

val phonebook = Map(

"Tommy mobil" -> PhoneNumber( "cell", "92012201" ),
"ICE Medisinsk" -> PhoneNumber( "work", "113" )
)

Expressive
println( phonebook("Tommy mobil" ).no ) Concise
phonebook.foreach(tuple => println( tuple._1 + ":" + tuple._2 )) High-level

functional iteration
1.1.+(2.2)

1 until 10
Pure OO

operator mode for methods

val xmlE = <a href="index.html"> {3 + 4} </a>

(xmlE \ "@href").text

Pragmatic

.

Motivation

Evolution, not revolution: Java-like, interoperates with java (seamlessly).
  • can extend java classes
  • can implement java interfaces
  • understands java generics
  • uses java primitives
Leads you into functional programming.
Easy to do easy stuff, AND facilitates the hard stuff.
More up2date language - builds on java lessons, adds:
  • Facilitates DSL with several short-hand notations
  • Traits (~multiple inheritance)
  • ++
One vision (Martin Odersky), not designed by comitee
Pragmatic



"I can honestly say if someone had shown me the Programming Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I’d probably have never created Groovy." — James Strachan

"If I were to pick a language to use today other than java, it would be Scala" — James Gosling (from before he left Oracle)

My verdict: lead me into...

Wonderful way of coming from Java to Functional programming. I started out writing java-like OO, but wolfed out by the end of my second 3-hour session.
The book fuelled this transformation.
Scala feels very good so far, I now like Java less...

References

Scala site.

Book "Programming in Scala" (Odersky++) is very good for learning, not so for reference.

The busy Java developer's guide to Scala: articles on DeveloperWorks

From JavaZone 09:

Bonus section

Start with Java Discovery and refactor a suitable class:
  • common.ServiceDescription (for properties and basics) NB! keep scala-code for equals / canEqual
Show off in code
Code Points to make
TestServer object and main
client.v2.Notifier operators
client.ServiceBrowser:
  • class extends with
  • tryto
  • getReplyDescriptor
traits
Function is first-class object
Option + match
sclanb.Main.recurse2 Closures, and how crazy I got
sclanb.Main
client.ServiceBrowserListener abstract, no interface
FirstSwingApp. DSL, Swing
Code from ch30 Actors


fredag 30. oktober 2009

Grails - learning notes

Hello Grails!

Trailer.
Download and unpack Grails, set GRAILS_HOME environment variable and update PATH. It works

grails create-app mapp
cd mapp
grails create-domain-class mapp.site.Site
grails create-controller mapp.site.Site

Import project into Eclipse or NetBeans (Grails creates Eclipse project)
Add fields and toString() to model
Add dynamic scaffold property to controller (def scaffold=Site)
grails run-app
Run and show off dynamicity by adding fields to model, and index-method.

grails generate-all mapp.site.Site

Step back and explain:
  • CoC: Show mapping url -> controller+view
  • MVC: Jump to "Domain Model", "Controller", "GSP"
  • Configuration: Set up database: store and update
Code a test

Why?
No configuration, zero overhead, immediate turnaround.
High-productivity web MVC framework for the Java platform
  • CoC: easy to find your way to domain-objects, controllers, services, views
  • Ready-to-use development environment (+test and production)
  • Scaffolding (even dynamic): quick-start
  • Familiar: On the shoulders of Java eco-system, Hibernate, Spring, Groovy, SiteMesh
  • GORM: DAO-layer implemented by MOPing
  • Good Ajax-support
  • Small stuff: test support, generating (web-)services. flash-scope, Web-flow, filters
  • Easily extensible, 312 Plugins at last count. Grails main function is plugin management.

Domain Model
You write POGOs, GORM provides DAO-functionality through mixins:
  • get, list, save, delete
  • findByName, findBy...And...
Validation provided.
Error container provided: siteInstance.errors
Command Object: domain object that is not persisted

Controllers
Scaffolding: CRUD generated. Provides a nice starting point.
Comment on first Controller generated:
  • list(): where did Site.list() come from?
  • list(): return statement optional.
  • show(): what is flash-scope?
  • show(): Model passed to view: Controller properties or returned map [key:value].
  • edit(): same as show() but different view (by convention)
  • update(): siteInstance.properties = params
  • index(): will be default action if not overridden by eg. defaultAction = 'list';

View (GSP)
JSP works, but GSP takes advantage of Groovy, and is remarkably similar
GSP taglib similar to Struts2 + jstl

Services
Transactional boundaries, automagicaly injected.

Google app-engine
Fra http://grails.org/plugin/app-engine og http://www.morkeleb.com/tag/grails/
sørge for at domeneklasser ligger under en pakke
grails install-plugin app-engine
(valgte jpa)
grails install-plugin gorm-jpa
La til annotasjoner (@Entity)

grails app-engine run
grails set-version 1
grails app-engine package

(første gang $APPENGINE_HOME/bin/appcfg.sh update ./target/war)

grails app-engine deploy

Go 2 http://nerdetom.appspot.com/

IDE Support
Approaching acceptable, maybe good if my PC was working fine.
NetBeans: syntax colored, some autocomplete, access to grails-commands, direct junit debug
Eclipse: some syntax colored, some autocomplete, debug of junit-tests.
IDEA: supposedly best-of-breed.
Debugging: remote (grails-debug run-app) on port 5005

Recommended reading
http://grails.org
http://www.morkeleb.com/tag/grails/
Book: "The Definitive Guide To Grails" 2nd edition by Graeme Rocher and Jeff Brown. Comprehensive and readable guide, details Enterprise integration issues.
Mastering Grails on DeveloperWorks.
Agile Enterprise Development with Groovy and Grails: From JavaZone 09

Outro.

søndag 7. juni 2009

OSX Java


Apple provides different integration code for different Java versions, see OSXAdapter or integration guide for Java >= 1.4.

MRJAdapter provides OSX-integration for several Java-versions

torsdag 14. mai 2009

Struts2: Quick and easy Wizard

Use a wizard to fill in data piecewise. Spring web-flow (plugin) is recommended. An alternative is to use scope and ModelDriven interceptors together and have them use the same object. Here's the idea coded:




public class SomeAction extends ActionSupport implements ModelDriven<somemodel> {
private SomeModel model;
public SomeAction ( ... ) {
model = new SomeModel( ... );
}
/** @see ModelDriven */
public SomeModel getModel() {
return model;
}
/** for scope interceptor */
public SomeModel getSessionModel() {
if ( ! clearSession )
return model;
clearSession = false;
return null;
}
public void setSessionModel( SomeModel newValue ) {
if ( newValue == null )
model.reset();
else
model.copyFrom( newValue );
}

}

NB! we're stuck with the object returned by getModel(), so we should only change it's content, not the object reference.

Action setup:

<action name="someAction" class="SomeAction">
<interceptor-ref name="scope">
<param name="session">sessionModel</param>
<interceptor-ref name="defaultStack" />

<result name="page1">/WEB-INF/jsp/page1.jsp</result>
<result name="page2">/WEB-INF/jsp/page2.jsp</result>

</action>


Scope-interceptor will call setSessionModel() with session data before other calls to Action (getModel, execute, validate), and after execute() returns getSessionModel() is called to get a new value to put in session.

fredag 24. april 2009

JZ08

Exception handling

Se foredrag her.


























TypeHandleFix and update appTry again?
Application ExceptionPossibleNoNo
System ExceptionNoNoPossible
Programming ExceptionNoyesNo


Rammeverk: distribuert Exceptionhierarki (mange klasser)
Applikasjon: sentralisert Exceptionhierarki (1 klasse med felt for id og map for kontekstuell info).

tirsdag 21. april 2009

Google App Engine

Java on App Engine
See App Engine Java Overview.

SDK (ref Google):
I downloaded the SDK, unzipped it and added to my PATH.
I used Ant to build the app in demos\guestbook
I then ran the local test-server with command (path from demos dir):
dev_appserver.cmd guestbook\war

I must wait for activation before I can upload app

Dashboard.

Groovy on App Engine
I impported the code for the Groovy AppEngine HelloWorld, but that does not run locally due to a bug in the SDK. I commented out the line that tries GroovyShell().evaluate("3*4"), and it ran, but it seems that Groovlets are based on being able to evaluate scripts.

Next up: get rss from Blogger and delicio.us.


mandag 15. desember 2008

Regexp for logging of method calls

BeanShell macros (May be run in jEdit)
Copy and paste auto-generated method signature, and run this macro

// rid of tabs, newlines and double spaces
strippSpace( String text ) {
text = text.replaceAll( "\\t" , " " );
text = text.replaceAll( "\\n?" , "" );
do {
text = text.replaceAll( " " , " " );
} while ( text.indexOf( " " ) > -1 );
return text;
}

// tidy up method call
cleanCall( String text ) {
text = text.replaceAll( "\\(\\s*" , "(\n\t" );
text = text.replaceAll( ",\\s*" , ",\n\t" );
text = text.replaceAll( "\\s*\\)\\s*" , "\n)" );
return text;
}

convertMethodSignature2SuperCall( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "$1 );" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "$1, " );
// 3 strings before (
text = text.replaceAll( "\\A\\s*\\w*\\s?void\\s?(\\w*)\\s*\\(" , "super.$1(" );
text = text.replaceAll( "\\A\\s*\\w*\\s?\\w*\\s?(\\w*)\\s*\\(" , "return super.$1(" );
return text;
}

convertMethodSignature2SillyReturn( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "$1 );" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "$1, " );
// 3 strings before (
text = text.replaceAll( "\\A\\s*\\w*\\s?void\\s?(\\w*)\\s*\\(" , "" );
text = text.replaceAll( "\\A\\s*\\w*\\s?(\\w*)\\s?(\\w*)\\s*\\(" , "return new $1();" );
return text;
}

convertMethodSignature2LogStatement( String text ){
// 2 strings before )
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*\\)\\W*" , "\n\t\tSEMAFOR_CALL \"$1\" SEMAFOR_COMMA $1 )\n\t);" );
// 2 strings before comma
text = text.replaceAll( "\\w*\\W?(\\w*)\\W*,\\W*" , "\n\t\tSEMAFOR_CALL \"$1\" SEMAFOR_COMMA $1 )," );
// 3 strings before parenthesis
text = text.replaceAll( "\\A\\s*\\w*\\s?\\w*\\s?(\\w*)\\(" , "\tSEMAFOR_CALL \"$1\" ," );
// semafors
text = text.replaceAll( "SEMAFOR_COMMA" , "," );
text = text.replaceAll( "SEMAFOR_CALL" , "toXml(" );
return text;
}

String text = Macros.input(view,"Method call:");
if(text == null || "".equals(text))
return;

String text = strippSpace( text );
String superCall = convertMethodSignature2SuperCall( text );
String logCall = convertMethodSignature2LogStatement( text );
String call = cleanCall( text );
String res = call + "{\n" + logCall + "\n\t" + superCall + "\n}";

Registers.setRegister('HistoryModel.getModel("clipboard").addItem(res);
view.getStatus().setMessageAndClear("OK - result on clipboard");


Logging methods

public static String toXml( String name, Object value ) {
// FixMe: escape xml special characters
if ( value == null )
value = "";
return "\t<" + name + ">" + value.toString() + "";
}
/** */
public static String toXml( String method, String... items ) {
String msg = "";
if ( items != null && 0 < msg = "<">" + msg + "";
System.out.println( msg );
return msg;
},res);
HistoryModel.getModel("clipboard").addItem(res);
view.getStatus().setMessageAndClear("OK - result on clipboard");

Logging methods
public static String toXml( String name, Object value ) {
// FixMe: escape xml special characters
if ( value == null )
value = "";
return "\t<" + name + ">" + value.toString() + "";
}
/** */
public static String toXml( String method, String... items ) {
String msg = "";
if ( items != null && 0 < msg = "<">" + msg + "";
System.out.println( msg );
return msg;
}

fredag 17. oktober 2008

GeoCoding and maps in Swing

Maps


Started with article from java.net., which details how to use the JxMapViewer from SwingLabs.

Web-based maps
Use OpenLayers to wrap service provider.
For Ajax-maps, check this article, or Tap into the Google Geocoder Web service. or even Overlay data on maps using XSLT, KML, and the Google Maps API, Part 2.

GeoCoding

Første søk var oppløftende, sjekk irb.no : Postnummer => geodata.
Statkart er grei å sjekke, men dataene nås først og fremst gjennom NorKart, Ugland IT...
Ugland IT, FlexiMap Online, FlexiMap Locator.
Foretrekker GeoData. (ESRI-baserte tjenester)
NorKart: FixMe.
geoNorge: FixMe.

Coordinate conversion

This article explains the works. Try libraries: GeoTools, JCoord (cf. this message).

EPSG:32633 = WGS_1984_UTM_Zone_33N: 6648970N 255101E
EPSG:4326 = Lat/lon (GCS_WGS_1984): 59.90530N 10.61976E
900913 = Google special projection (is Mercator): 8378684N 1182185E
epsg:54004 = Mercator (World_Mercator)

A degree of longitude at the equator is 111.2 kilometers. A minute is 1853 meters.
A second is 30.9 meters. For other latitudes multiply by cos(lat).
cos((2 * PI * 66) / 360) = 0.406736643

For reference systems / epsg codes, see: GIServer or spatialreference.
http://www.radicalcartography.net

Gratis-tjenester:

Norsk openstreetmap prosjekt, men det ser ut til å være mangelfullt.

Posten sin nedlastingsside (gir kommunenr fra postnr, 1 skritt til for posisjon, men det blir veldig unøyaktig).

Geonames funker sånn noenlunde med postnummer, de har webservice og egen norge-side. Mulig vi må betale for tjenesten.

Google: read this chapter in the Google Maps Hack book. Adding a Google Map to the Sample JSF Catalog Application + How to Use the Map Viewer and GeoCoder Components. Best match: Lightweight Google Geocoder with Java?
Freebase har tripleter (subjekt+verb+objekt) som mapper postnumre til geolokasjoner, ikke mange norske. eksempel.

Google laget en liste med Geocoders.