Posts

Showing posts from February, 2009

Funny error with Java’s extended for-loop

Java 5 introduced the enhanced for-loop – or for-each loop – which simplifies iterating over many types of collections. Have a look at this simple piece of code and tell me what’s wrong:package de.danielschneller.blog.iterator; import java.util.HashSet; import java.util.Set; public class Demo { public static void main(String[] args) { Set set = new HashSet(); set.add("Value 1"); set.add("Value 2"); set.add("Value 3"); set.add("Value 4"); set.add("Value 5"); synchronized (set) { for (String tEntry : set) { if (tEntry.endsWith("3")) { System.out.println("3 has to go"); set.remove(tEntry); } else { System.out.println(tEntry + " may stay"); } } } } }When I wrote this I naively expected something like this to be written out(the order of the iteration is undefined for a HashSet, but bear with me:Value 5 may stay
Value 2 may stay
3 has to go
Value 4…

Disable drop shadow on OS X screen shots

Recently I found myself doing numerous screenshots on OS X. While the drop-shadow effect that gets included in the resulting PNG files looks nice on screen, it tends to come out rather bad on black and white printouts. As there is no GUI setting for this one has to use the "defaults" command on a terminal:defaults write com.apple.screencapture disable-shadow -bool true killall SystemUIServerInstead of killing the SystemUIServer process you could also log out and back in. To restore the shadow, just delete this property again:defaults delete com.apple.screencapture disable-shadow killall SystemUIServerOh, and just in case you did not know: These are the keyboard shortcuts to take screen shots in the first place:Fullscreen: Shift-Cmd-3 Rahmen: Shift-Cmd-4 Fenster: Shift-Cmd-4, Space Technorati Tags: ,