Friday, October 30, 2009

Force Quit on Mac Apps

Command + Option + Escape

Tuesday, October 13, 2009

Capturing Screenshots On Mac

Great tips for capturing screen shots on the Mac. I got this from..

http://www.techiecorner.com/138/how-to-do-print-screen-in-mac-os-x/

There are few ways to do screen capture in Mac OS X.
Follow the steps below and you will be able to do a screen capture in Mac OS X.

  • Switch to the screen that you wan to to do screen capture
  • Hold down Apple key ⌘ + Shift + 3 and release all
  • then use your mouse to click on the screen
  • Done. You will see a picture file in at your desktop. That’s the screen capture picture.

You can also do a screen capture for a portion of your screen.

  • Switch to the screen that you wan to to do screen capture
  • Hold down Apple key ⌘ + Shift + 4 and release all key
  • Now, You will see the mouse cursor will change to +
  • You can start to drag your mouse to select the portion you wish to capture.
  • Once finish, you will see a picture file in at your desktop. That’s the screen capture picture!

If you want to do a screen capture for a particular application window, you can follow this:-

  • Switch to the screen that you wan to to do screen capture
  • Hold down Apple key ⌘ + Shift + 4 and release all key
  • Now, You will see the mouse cursor will change to +
  • Press the space bar once
  • You will see the mouse cursor change to a camera
  • Now you can use the camera to select which application window to screen capture
  • Once finish, you will see a picture file in at your desktop. That’s the screen capture picture!

Friday, September 25, 2009

Character-set Encoding Issues

Great site for inspecting characters to troubleshoot character encoding issues.

Thursday, September 24, 2009

DBUnit and Foriegn Key Constraints


DB Unit is great, except for the FK constraint hell you go through until you learn to do..
1. IDataSet dataset = new FlatXmlDataSet(
ClassLoader.getSystemResourceAsStream(
datasetFilename));
2. dataset = new FilteredDataSet(
new DatabaseSequenceFilter(
getConnection()), dataset);
Line 2 there looks at the constraints and the dataset and determines the correct ordering for the SQL statements for your database, so that when they're run in the setup/teardown of your DBUnit tests you don't get FK constraint violations.

There are many blog postings that give all kinds of ways to disable or defer FK checks by the database, but this works better I think, for me since I have the test setup in Java. This came from the comments in a Matt Raible post from 2006.

Thursday, September 10, 2009

You're in Timeout

I recently had an issue with some code I wrote to connect to a service with a "rest like" interface that returns XML data given a simple query over a HTTP GET request.

I used that java.net.URL class to send the query and retrieve the results as follows..

private InputStream executeQuery(String query) {

InputStream rawResults = null;

try {
query = baseUrl + "?query=" + query;
if(LOG.isDebugEnabled()) {
LOG.debug("Full Query : " + query);
}
URL request = new URL(query);
rawResults = request.openStream();
}
catch (IOException e) {
LOG.warn(e.getMessage(), e);
}

return rawResults;
}

If the host on which this service runs is down (or doesn't exist) before URL.openStream() gets invoked, a java.net.UnknownHostException is quickly thrown (within about 4000 milliseconds), the catch block is executed, and the process goes on.

However, if the service goes down after the socket connection is made, but before the data is read back from the service, this method call to URL.openStream will block indefinitely by default.

Eric Burke has written a post defining this problem and a simple solution, which can be found here. The solution is to set the read timeout on the URLConnection so that you can break after so many milliseconds if you are't getting the data back.

For example:

private InputStream executeQuery(String query) {

InputStream rawResults = null;

try {
query = baseUrl + "?query=" + query;
if(LOG.isDebugEnabled()) {
LOG.debug("Full Query : " + query);
}
URL url = new URL(query);
URLConnection conn = url.openConnection();

// Seems set to 4000ms by default already.
conn.setConnectTimeout( 4000 );

// Set to 0 by default, T/O never occurs!
conn.setReadTimeout( 10000 );

rawResults = conn.getInputStream();

} catch (java.net.UnknownHostException e) {
LOG.warn("Could not make connection to
host within the allotted connectTimeout", e);
} catch (java.net.SocketTimeoutException e) {
LOG.warn("Could finish reading data from the
socket within the allotted readTimeout", e);
}

return rawResults;
}

Now as the catch blocks indicate, the host can go down, or the service can be unresponsive before or during the read, and we'll cut out after our chosen timeout.

Friday, August 28, 2009

JAX-WS / Maven / WSIMPORT

To use JAXB during your maven build use something similar to..

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>StaticDetailLogAccessServiceClient</groupId>
<artifactId>StaticDetailLogAccessServiceClient</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.yourco.schemas</groupId>
<artifactId>DetailLogAccess</artifactId>
<version>1.0.1</version>
<type>xsd</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.6.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.build.directory}/classes</schemaDirectory>
<includeSchemas>
<includeSchema>**/*.xsd</includeSchema>
<includeSchema>**/*.dtd</includeSchema>
</includeSchemas>
<excludeSchemas>
<excludeSchema>test*.xsd</excludeSchema>
</excludeSchemas>
<includeBindings>
<includeBinding>*.xjb</includeBinding>
</includeBindings>
<strict>false</strict>
<verbose>true</verbose>
<extension>true</extension>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Found at https://jax-ws-commons.dev.java.net/jaxws-maven-plugin/usage.html

Thursday, August 27, 2009

When downloading torrents...

Block any uploads/downloads from the URLs found here..
http://www.bluetack.co.uk/config/level1.gz

Good Torrent Sites :
  • isohunt
  • demonoid (requires you to sign up)
  • pirate bay
Good Torrent Clients :
  • Vuze (not sure if it works on Mac, saw it on linux)
Some Commonly Used Hacked Mac OSX Systems:
  • Kalyway
  • iAtkos

Tuesday, August 25, 2009

WGET Flags for Entire Website

From Prystash's blog, args to wget to grab an entire site cleanly.
$ wget --recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains somesite.org \
--no-parent \
www.somesite.org