Thursday, November 10, 2005

Det er svært at finde kommunal-kandidater

Jeg læste en artikel om at de kommunale kandidater er næsten usynlige på nettet. Det kunne jeg ikke helt forstå for den første jeg søgte på "Anne Vang" ligger øvers på google og har en glimrende hjemmeside.

http://www.annevang.dk/

Da jeg lidt senere søgte på "Morten Westergaard" fik jeg til gengæld syn for sagn. Ingen relevante hits på mine søgninger. Ak! Til sidst fik jeg dog at vide (via "word of mouth") at det var her jeg skulle lede

http://mortenw.dk

http://socialdemokraterne.dk/default.aspx?site=koebenhavn/mortenwestergaard&

Friday, October 07, 2005

Another piece of code to walk something - guess what...

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SFCrawler {

public void dlFile(String fileName) throws IOException, InterruptedException{

String base = "http://cvs.sourceforge.net/viewcvs.py/*checkout*/hartmath/hartmath2/";

URL url = new URL(base + fileName);
HttpURLConnection conn = null;
Scanner s;

try {
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(60000);
s = new Scanner(conn.getInputStream());
} catch (IOException e) {
System.err.println(e.getMessage());
Thread.sleep(5000);
if(conn != null)conn.disconnect();
dlFile(fileName); // risky strategy
return;
}

BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
System.out.println("Writing: " + fileName);
while(s.hasNextLine()){
String line = s.nextLine();
bw.write(line);
bw.newLine();
}
bw.flush();
bw.close();
}

public void crawl(String sUrl, String pdir) throws IOException, InterruptedException{

System.out.println("Crawling - " + sUrl + pdir);
URL url = new URL(sUrl + pdir);

HttpURLConnection conn = null;
Scanner s;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(60000);
s = new Scanner(conn.getInputStream());
} catch (IOException e) {
System.out.println(e.getMessage());
Thread.sleep(2000);
if(conn != null)conn.disconnect();
crawl(sUrl,pdir); // risky strategy
return;
}


Pattern dirPattern = Pattern.compile("< a name=.*href=\"/viewcvs.py/hartmath/hartmath2/" + pdir + "(.*)/\">");
Pattern filePattern = Pattern.compile("<td><a name=.* href=\"/viewcvs.py/hartmath/hartmath2/" + pdir + "(.*).rev=.*\">");

ArrayList dirs = new ArrayList();

while(s.hasNextLine()){
String line = s.nextLine();

Matcher dirMatcher = dirPattern.matcher(line);
Matcher fileMatcher = filePattern.matcher(line);

if(fileMatcher.matches()){
String file = fileMatcher.group(1);
System.out.println(file);
dlFile(pdir + file);
}else if(dirMatcher.matches()){
String dir = dirMatcher.group(1);
System.out.println(dir);
dirs.add(dir);
}
}


for (String dir : dirs) {
File f = new File(pdir + dir);
if(f.mkdirs()){
System.out.println("Successfully created: " + f.getAbsolutePath());
}else{
System.err.println("Faliure in creating " + f.getAbsolutePath());
}
crawl(sUrl, pdir + dir);
}
}


public static void main(String[] args) {

SFCrawler c = new SFCrawler();

try {
c.crawl("http://cvs.sourceforge.net/viewcvs.py/hartmath/hartmath2/", "src/");
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

Saturday, September 17, 2005

What's happned the last week?

1. I've started my masters thesis. Well - I haven't coded a single line yet - or run a simulation yet. But I've written down a description of the project - and I now have an ok grip on what to do.

2. I've almost finished the administrative tasks related to moving in with Lise. Got myself a "digital signatur" so I could log into the administrative system of Copenhagen and register my change of address. Reactivated my account at Skandiabanken so Lise and I can share an account.

Any opinions on Skandiabanken? It seems to have significantly better deals than the two large banks in Denmark (Nordea, Danske Bank).

3. I attended a meeting in Frit forum (warning - exceptionally buggy page) and forgot about another appointment I had. Sigh!

Sunday, September 11, 2005

Ok - gotta get blogging

I might as well record the general state of my life - and new events here, so I can just point folks here, if I think they might be interested in what I do and think.

Ok.

After having lived 2 years at Rigshospitalets Kollegium - RHK I moved in with my girlfriend Lise in the week of august 19.

The next week we went to Marbella on a "do nothing at all in the sun and warmth" holliday.

And in the week after Lise went back to Denmark to work, but I stayed in Malaga to attend the KDE users and developers conference.

That was a great experience - sort of when you go to a farm as a kid and see where the carrots and steaks come from. I saw where my favorite apps (eg amaroK come from.

Monday, August 01, 2005

A piece of Java code to walk a JNDI tree in a Servlet

public void doGet(...){
...

InitialContext initialContext;
StringBuffer sb
try {
sb = new StringBuffer();
initialContext = new InitialContext();

loopLevel(sb, initialContext, "java:comp");

} catch (NamingException e) {
writer.println("<html><body>");
e.printStackTrace(writer);
writer.println("</html></body>");
} catch (Exception e) {
}
writer.println("<html><body>" + sb.toString() + "</html></body>");

}

private void loopLevel(StringBuffer sb, InitialContext initialContext, String name){
try {
NamingEnumeration ne = initialContext.list(name);

sb.append("<ul>");

while (ne.hasMoreElements()) {
NameClassPair ncp = (NameClassPair) ne.nextElement();
sb.append("<li> " + ncp.getName());
loopLevel(sb, initialContext, name + "/" + ncp.getName());
}
sb.append("</ul>");
} catch (NamingException e) {
e.printStackTrace();
}
}

Thursday, March 17, 2005

Gotta buy these

C++ Unleashed and Effective C++.

to get on with my dreams of world domination through cool KDE apps...maybe I should just start with making a KDE controlcenter page for the nvidia settings app, and maybe port DVD Jons iTunes front end (pyGTK now)

Wiiieh, Pirates!

Finally I got my Pirates! game, 6 days later than promised, but still in time so that I can bring it on vaccation.

My first attempts at installing failed - so I guess I have to post to some wine-list to ask what the error traces mean.


Poor Oliver - who sparked my interest - seems in need of money - but I guess he can have what I save by not needing to subscribe to Cedega.

http://www.oliverthered.f2s.com/projects/wine/

Tuesday, March 01, 2005

First post

well - let's see when the next comes...