Posted by Nikolaus Gradwohl
Tue, 15 Jan 2008 05:45:00 GMT
i have a new version of my "detect where i am" script that workes absolutly hands free. i rarely turn my mac off, most of the times it stayes in sleep mode when im traveling from one site to another.
so i use "SleepWatcher" a great tool from Bernhard Baehr to trigger a script that scanns for known wlans and changes my proxy settings
Tags sleepwatcher | no comments
Tweet This!
Posted by Nikolaus Gradwohl
Wed, 12 Dec 2007 21:38:00 GMT
I got my RFID-Reader 2 plus from conrad running!!!
it took me just 5 months to find out what "stabilized 5V+" means :-)
the reader can be configured to send all the id strings it reads. but unless a barcode reader, it isnt triggerd by the user but sends the strings it finds all the time like crazy - looks cool in a terminal program :-)
is also fun to see which tags are read if more than one
is in the reading distance - maybe i make a game out of that :-)
Tags rfid | 1 comment
Tweet This!
Posted by Nikolaus Gradwohl
Fri, 07 Dec 2007 05:42:00 GMT
I own a Nokia 770 which i use to read pdf-files in the subway. i realy like it, but it has one downside - it is extreamly slow in changing the page if the page has to be zoomed or scrolled.
the solution i found was to define a custom papersize for my "print-to-pdf" dialog, which fits into my N770 screen without the need to scroll or zoom.
if i want to read some website-content offline in the subway,
i just have to print it to pdf using my custom page-format and copy it to my device using bluetooth.
Tags N770, pdf | no comments
Tweet This!
Posted by Nikolaus Gradwohl
Sat, 03 Nov 2007 14:43:00 GMT
In an erlier article i describe how to switch between the network environments i am
using, but there was one programm i could not convince to let me change the proxy
settings via apple script - firefox.
i still needet to switch the firefox settings per hand - something i didnt like at all.
one day the little "fetch proxy settings for url" dialog part from the
firefox proxysettigns made me courious and i found out, that firefox
expects a javascript file on this url, which tells firefox what proxy to use.
function FindProxyForURL(url, host) {
if ( dnsResolve( host ) == "127.0.0.1" ) {
return "DIRECT";
} else {
return "PROXY proxyhost:8080";
}
}
this script can use some predefined functions like "isInNet" or "dnsResolve" to
determine which network Im in and use the appropriate proxy. the file doesnt
even have to live on a http server, a file:// url is sufficient.
e voila - no more manual proxy switching
Tags firefox, javascript, proxy | 1 comment
Tweet This!
Posted by Nikolaus Gradwohl
Wed, 26 Sep 2007 18:40:00 GMT
When I use jdbc to develop a small tool, where using a OR-Mapper
like Hibernate is overkill, I always dislike that i have to dublicate
all the "getStatement" "execQuery" "while (resultSet.next())" stuff.
i dont like to repeat stuff in my code. It would be very easy if
java had closures, but i dont want to wait until java7 to simplify
my code so I needet another idea.
java has no closures but it has something that can be used in a similar
manner - Anonymous inner classes.
so to simplify the following class
Connection con = getConnection()
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "sqlstring");
List<Foo> result = new ArrayList<Foo>();
while (rs.next()) {
Foo f = new Foo();
f.setProperty1( rs.getString( "property1" ));
f.setProperty2( rs.getString( "property2" ));
result.add( f );
}
// imagine catch/finaly block here
st.close();
con.close();
i define a interface called Function
interface Function<T> {
public T valueOf( ResultSet rs ) throws SQLException;
}
Then i define a QueryMapper like this
public class QueryMapper<T> {
private Database db;
public QueryMapper( Database db ) {
this.db = db;
}
List<T> listOf( Function<T> f, String query ) {
List<T> res = new ArrayList<T>();
Resultset rs = ... get resultset for query ..
while ( rs.next() ) {
res.add( f.valueOf( rs ));
}
// catch/finaly block here
return res;
}
}
So all i have to do in my code now is calling
Function<Foo> fn = new Function<Foo>() {
public Foo valueOf( ResultSet rs) throws SQLException {
Foo res = new Foo();
res.setPropery1( rs.getString( "property1" ));
res.setPropery2( rs.getString( "property2" ));
return res;
}
}
QueryMapper<Foo> qm = QueryMapper<Foo>( db );
List<Foo> res = qm.listOf( fn, "select * from foo");
I can even recycle the Function objects ( if i query different object of the same type but with different ids for example )
thats more how i like it
Tags java | 2 comments
Tweet This!
Posted by Nikolaus Gradwohl
Sun, 16 Sep 2007 15:40:00 GMT
Halve of my time i'm working at a costomers office, everyone has
a different network environment, some usuale proxies some don't.
in some environments i can use my mailclient, in some i have to use
my webmail account.
so i usualy spent the first 5 to 10 minutes of my workday switching
network profiles, configuring proxies, changing my subversion configurations,
stopping and starting various propgramms, etc
doing repetitive stupid work is something i dont like. im a computer programmer and
these are exactly the ones that sould be automated in my oppinion.
so i startet to create a little applescipt for every environment im in. it switches to
the correct network profile stops my mailclient where nessesery and
changes my current subversion profile, if a proxy is required.
changing the subversion config was the easiest part. i just fired up
iterm and changed the config by setting a symlink using a shellscript
so i have two copies of my .subversion/servers file one for using the proxy
and one for direct connections, and the 'servers' file is a symlink to one of those
well at least i thought it woult be easy ...
the tricky part starts when iTerm is running but has no open windows. then i have
to start a Termintal before i can call the shellscript so this is what the shellscript-starting
part looks like
tell application "iTerm"
activate
delay 1
if (count of windows) is 1 then
set myterm to (current terminal)
else
set myterm to (make terminal)
end if
tell myterm
set mysession to (launch session "Default Session")
tell the last session
write text "/Users/nikki/tools/switchsvn2 default"
end tell
end tell
end tell
and the corresponding shell script is
#!/bin/bash
cd ~/.subversion
rm servers
ln -s servers.$1 servers
to switch the current network profile applescript UI events need to be activated. Then applescript can be told to click on various menu items like this
tell application "Finder"
activate
end tell
tell application "System Events"
click menu item "networkprofilename" of menu "Location"
of menu item "Location" of menu "Apple" of menu bar 1 of process "Finder"
end tell
to start the applescript files i use quicksilver. So all i have to do now when starting my working
day in a different environment is fire up quicksilver using - and entering the name of
the environment
thats how i like it :-)
Tags applescript | no comments
Tweet This!
Posted by Nikolaus Gradwohl
Thu, 26 Apr 2007 09:25:00 GMT
Im currently sitting in Wiesbaden at the Jax2007 (missing a keynote from SAP :-) )
i've seen a lot of new interessting tools and techniques which will keep me busy some
times.
webtest from canoo, for example has evolved in a very interesting way since i gave it
the last try,
one thing that many of the speakers are showing ist the tendency to use more languages
on the JVM and choose the right tool for the problem. and not let the language shape the
solution.
there were some nice sessions showning how to generate textual DSL with ruby or
open architecture ware.
this time there were some netbeans sessions where new features from the upcoming
netbeans 6 release where shown - realy nice
and i heard abount ApacheDS a ldap server which is completely written in java
and can be embedded into other applications.
ok the sap keynote is comming to an end - i will go to the next session now ...
Tags java, jax2007 | no comments
Tweet This!
Posted by Nikolaus Gradwohl
Sat, 27 Jan 2007 19:23:00 GMT
Category:
I have used macos X for some time now and resently switched my main console back
to linux.
No problem so far because most of the tools ive used in macos X where unix tools i knew
from conding on linux - the only thing I realy missed was exposeè.
For this reason I gave compiz a try now
Installation was realy simple on my gentoo box all I had to do was
emerge compiz and reemerge kde with the useflag "xcomposite" acvite
then add a
Section "Extensions"
Option "Composite" "Enable"
EndSection
at the end of xorg.conf and add
Option "AddARGBGLXVisuals" "True"
to the "Device" Section. This option is very important, because wihout it the kde-window-decorator
doesnt draw any window headers.
after restarting X11 compiz can be started with
compiz-start
in a shell. To let it start automatically i have put a little shellscript in my .kde/Autostart folder. I also have deactivated the wobbly plugin. This is realy funny in the beginning but start
getting REALY annoing very fast :-)
Compiz can be downloaded on their website (http://www.go-compiz.org). They also have some very nice
tutorials showing how to install it on various systems
no comments
Tweet This!
Posted by Nikolaus Gradwohl
Sun, 21 Jan 2007 10:09:00 GMT
Java 1.5 introduced a bunch of new classes for handling multithreaded programming.
The one I realy like the most is Future.
With future its possible to start the calculation of something you know you will need
at a later point in yout programm. When you reach that point you can call Future.get()
to fetch the result of the calculation. If it is already avaliable the result is returned
immediately, if the calculation is still running or has not started yet Future.get()
blocks until the results are here.
one gets a future by submitting an object implementing Runnable or Callable to an ExecutorService.
This is an interface that is implemented by ThreadPoolExecutor.
ExecutorService e = Executors.newSingleThreadExecutor();
Future<String> future = e.submit(callable);
...
String result = future.get();
This Class implements a queue and a threadpool. using ExecutorService.submit() you can put some
Workload in an queue, from where the threads of the pool will fetch and execute them. the submit method returns an Future which can be used to fetch the results of the workload.
There are various preconfigured Threadpools available from Executors Class. For example
ExecutorService e = Executors.newSingleThreadExecutor();
creates a degenerated Threadpool using just one thread. This is very usefull if one has to garantee
that no two instances of the submitted callable are executed at the same time. If you have to use an external service that is implemented by offering an api via webservice thats not threadsave beacause of a missing transaction handling, this SingleThreadExecutor can be used to serialize the requests comming from a webapplication.
All the clientrequests can be spooled in the executor service but all the calls to the service api are strictly searialized.
Another very usefull class is
ExecutorService e = Executors.newCachedThreadPool()
this is what most people think of when they refere to a threadpool. The class generatets new
threads if needed but reuses existing ones if they do idle. Threads that are not used for 60 seconds are removed from the pool.
ExecutorService e = Executors.newFixedThreadPool(n)
creates a Threadpool containing n threads. No new threads are generated an there also is no timeout.
SingleThreadExecutor is an fixedThreadPool with n = 1.
I think the java.util.concurrent package is the one of the best things that got introduced with java 1.5.
Tags java, threadpool | 1 comment
Tweet This!
Posted by Nikolaus Gradwohl
Sat, 16 Sep 2006 16:40:00 GMT
so i have done it - ive started another blog :-)
Tweet This!