The White Blog

A blog for technology, life, and food

  • Home
  • Photos
  • About
  • General
  • Life & Family
  • Programming
  • Gadgets & Toys
  • Food
  • Pictures

    • The White Pets
    • Western Carribean
    • Eastern Carribean
    • St. Louis
  • Other Pages

    • Side Projects
    • GeoCaching
    • Andrew's Wishlist
    • Christina's Wishlist
  • Across the Web

    View Andrew White's profile on LinkedIn profile for Andrew White on Stack Exchange, a network of free, community-driven Q&A sites
  • Gallery

                                  DSC00400
  • Recent Posts

    • Remembering Merlin
    • Returning and Accepting Interfaces with CXF/JAX-WS
    • LEGO Dice Tower
    • Truthfulness of the 2012 Presidential Political Candidates
    • Slider Solver for Klotski Puzzles
  • Older Posts

    • March 2013 (1)
    • June 2012 (1)
    • May 2012 (1)
    • March 2012 (2)
    • February 2012 (1)
    • January 2012 (2)
    • March 2011 (2)
    • November 2010 (2)
    • September 2010 (2)
    • July 2010 (1)
    • June 2010 (3)
    • May 2010 (5)
    • April 2010 (4)
    • March 2010 (6)
    • February 2010 (1)
    • January 2010 (1)
    • December 2009 (1)
    • November 2009 (1)
    • September 2009 (1)
    • August 2009 (1)
    • July 2009 (2)
    • May 2009 (2)
    • March 2009 (2)
    • February 2009 (1)
    • January 2009 (1)
    • November 2008 (1)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (1)
    • July 2008 (1)
    • June 2008 (2)
    • April 2008 (2)
    • February 2008 (2)
    • January 2008 (1)
    • December 2007 (3)
    • November 2007 (2)
    • October 2007 (2)
    • September 2007 (1)
    • August 2007 (6)
    • July 2007 (8)
    • June 2007 (7)
  • Site Tools

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Switch site

    • Switch to our mobile site

Remembering Merlin

The loss of a pet is one of the most difficult topics for me to write about. Yet, I feel it is necessary to help capture the memory. Merlin certainly deserves at least that much. There is so much worth remembering. Certainly more than I can fit into a single post.

Merlin was a rescue kitten that was supposed to stay around until he got better. The running joke is that he never did get better since he stayed around anyway. His sneezing fits where certainly something to see. Later we discovered Merlin also had asthma and needed a daily inhaler.  Most people can’t imagine giving a cat an inhaler, but he took it very well.

Merlin had a pretty unique personality, but he was still a cat. I think it took him a while to figure that out though. Not many kittens will chase a dog around the house. At some point, the idea of being a cat settle in and he acquired an obsession with cat nip and cardboard boxes. He even went as far as creating hidden stashes of his favorite Nepeta.

A friend of our described the loss the best when he said “[we] had a loss in the family.”  Merlin was part of our daily routine.  Just like with the loss of Rose, this loss left a large gap in our lives. Merlin was well loved cat and we will never forget him. You will be missed Merlin.

img_0175

Mar 9, 2013aewhiteCategory: General, Life & Family Read more No Comments

Returning and Accepting Interfaces with CXF/JAX-WS

JAXB doesn’t support interfaces directly, plain and simple. Why? Interfaces are method level contracts and JAXB is designed around data level contracts. The most common source for working around these limitations is documented on the Unofficial JAXB Guide. While these techniques work most of time, they fail to cover certain edge cases in CXF with JAX-WS.

In short I recommend a combination of two tricks: use of an XmlAdapter and setting the jaxb.additionalContextClasses property. The second half of this post points out pitfalls and problems I ran into along with some general advice.

The XmlAdapter Trick

If you have an interface that is only implemented by one class, you can use the XmlAdapter as outlined in the Unofficial Guide with one exception. I do NOT recommend using the AnyTypeAdapter that comes with JAXB (see pitfalls section for more on why).

Here is the GenericAdapter class I use.

@SuppressWarnings("unchecked")
public class GenericAdapter<ValueType, BoundType> extends XmlAdapter{
    @Override
    public BoundType unmarshal(ValueType valueType) throws Exception {
        return (BoundType) valueType;
    }
 
    @Override
    public ValueType marshal(BoundType boundType) throws Exception {
        return (ValueType) boundType;
    }
}

To use this adapter correctly, create a public static inner class in the implementation that extends the GenericAdapter and provides the appropriate generic types. Then point the interface’s @XmlTypeAdapter to the static inner adapter.

Add Classes to the ‘jaxb.additionalContextClasses’ Property

If you are using Spring  then you need to setup your server like so, noting the properties tag…

    <jaxws:server id="myServiceId"
                  serviceBean="#myImplementationId"
                  serviceClass="com.mycompany.ServiceImpl"
                  address="/Service">
        <jaxws:properties>
            <entry key="jaxb.additionalContextClasses">
                <bean class="com.mycompany.ServiceImpl.ClassArrayFactoryBean">
                    <property name="classNames">
                        <list>
                            <value>com.mycompany.model.ClassA</value>
                            <value>com.mycompany.model.ClassB</value>
                        </list>
                    </property>
                </bean>
            </entry>
        </jaxws:properties>

I also needed to build a ClassArrayFactoryBean since one didn’t seem to be shipped by default…

public class ClassArrayFactoryBean implements FactoryBean<Object> {
 
    private List<String> classNames;
 
    public Object getObject() throws Exception {
 
        final Class<?>[] classes = new Class<?>[classNames.size()];
        for (int i = 0; i < classNames.size(); i++) {
            classes[i] = Class.forName(classNames.get(i));
        }
        return classes;
    }
 
    public Class<?> getObjectType() {
        return Class[].class;
    }
 
    public boolean isSingleton() {
        return true;
    }
 
    public List<String> getClassNames() {
        return classNames;
    }
 
    public void setClassNames(List<String> classNames) {
        this.classNames = classNames;
    }
}

You may be able to get away with creating a jaxb.index file but I never did get this to work as expected.

Avoid Interfaces on @WebService Classes

One could argue pretty strongly that the WSDL provides the interface contract and that your web service class need not worry about interface contracts at the Java level. In many cases an abstract class can provide the one-to-many polymorphic design needed without having to jump through hoops to make JAXB work with interfaces.

Pitfalls and Traps

This is a collections of things I tried and they failed at the time. These techniques may work just fine with newer versions of CXF and JAXB or under difference conditions. Your mileage may very.

  • Using the AnyTypeAdapter caused CXF to generate a WSDL that accepted an xs:anyType which got transformed into just a plain Object by WSDL2java on the client side.
  • Using @XmlSeeAlso never seems to do what I expected. In particular, it seems to always be ignored.
  • Do not expect JAXB annotations on the @WebService interface to work as you would normally. Most of those annotations are for giving JAXB directions on serializing the class that they are in, and you are not serializing your web service implementation.

Summary

You may be better off avoiding interfaces on the actual web service interface and implementation. If you must use them then be aware that it’s tricky to get right and I hope the notes above are of some use.

Jun 2, 2012aewhiteCategory: General, Programming Read more No Comments

LEGO Dice Tower

I play lots of board games. Some of these games are quite complex and have very large and intricate setups with lots of dice. One of the more frustrating side effects of these games is trying roll dice without disrupting the game pieces. So, I built a dice tower.

The tower is mostly made from pieces from the Harry Potter Hogwart’s Castle.  It uses three main tumblers and a series of smaller tumblers to ensure randomness. The bottom tray detaches and can be mounted to the front for portability.  The design is simple and meant to be aesthetically pleasing while still functional. I have been fairly impressed with its performance, and so I thought I would share the concept. Enjoy.

May 29, 2012aewhiteCategory: Gadgets & Toys, General Read more No Comments

Truthfulness of the 2012 Presidential Political Candidates

I recently became interested in certain claims made by politicians and their perception among the public. In particular, I want to know how trustworthy a candidate is. Furthermore, I want to be able to back up or refute claims made by people about one candidate being more “honest” or “trustworthy”.

Methods and Bias

My methods are simple. I compiled statistics based on each candidate from PolitiFact and graphed the results below while also calculating a Trustworthiness Grade Point Average (TGPA). The pie chart is a simple breakdown of each category that Politfact assigned to a particular statement. The TGPA is a simple weighted average of each statement on a standard academic 4.0 scale system where “true” was assigned a value of 4.0 and “Pants On Fire” got a 0.0 and all other values where equally distributed in the range [0.0-4.0].

There is also the chance of bias from PolitiFact. For that I refer you to the PolitiFact Bias Blog where you can form your own opinion. This data also represents a rather small sample size, in particular for Ron Paul who does not receive nearly as much press coverage as other candidates. It should also be noted that PolitiFact does not rate every statement but rather statements that can be fact checked and that have some “boldness” or public interest. Therefore, I wouldn’t use this as a measurement of their personal character but rather how well they present themselves relative to known or verifiable facts in a political landscape.

Ron Paul TPGA 2.33 (C+)

Mitt Romney TPGA 2.21 (C+)

Rick Santorum TPGA 1.89 (C-)

Newt Gingrich TPGA 1.73 (C-)

Barack Obama TPGA 2.58 (B-)

Conclusions

Being a Ron Paul supporter, I was not too surprised to see he ranked among the top of the field. Newt’s record was anticipated, but I did expect Romney and Satorum to be reversed. Obama’s record was not what I predicted until I realized that he doesn’t make bold claims of fact as much as bold promises. In particular, Obama seems very good at avoiding outlandish remarks that would earn him a “Pants On Fire” ruling. Overall I was disappointed that the best republican rating was a C+ and best overall was a B-.

Mar 31, 2012aewhiteCategory: General Read more No Comments

Slider Solver for Klotski Puzzles

I hate slider puzzles aka Klotski puzzles. The key move is usually a subtle block placement nested halfway between the starting setup and the ending solution. Since even the more basic puzzles require a minimum of 20+ moves to solve, I end up using trial and error which inevitably results in me repeating positions several times before frustration sets in.

Solving one puzzle is nice, but if I can solve every puzzle then I feel like I have truly conquered the problem. As such, I wrote a small Java command line application that can solve most compact sliders quickly.  It uses a breadth first searching algorithm to find the shortest solution assuming moving one block one space counts as a move.

Using the solver

Warning, this is more of a developer/geek friendly application. Download and unzip either the .zip or .tar.gz files from below. The program is meant to be run from the command line so jump to the console. Change directories to where you extracted the download and then you can run…

$bin/SliderSolver /path/to/puzzle /path/to/goal

See the download section for example puzzles, goals, and outputs. When creating the puzzle and goal files note that the only reserved character is the ‘#’ which is the wall symbol. There is very little error checking so be sure the puzzle is enclosed and “small”. At some point I might wrap this in a GUI but for now it is just a self exercise in solving a puzzle.

How it works

The algorithm is pretty straight forward:

  1. Read puzzle and goal files
  2. Generate shape equivalence mappings
  3. Try possible moves and store the current puzzle state if we have not seen the state before
  4. If the state matches the goal then print the solution else go to step 3

The only complex part is generating shape equivalence. In practice, this optimization reduces the memory needed and time required by a factor equal to the number of duplicate shapes in the puzzle. Without this trick the original Klostki puzzle will consume over 4GB of RAM and take several hours to solve. With the optimization, the puzzle can be solved in under a minute with under 2GB of RAM.

Below is a snip of the core solve method which uses a breadth first algorithm to find solutions.

public Solution solve() {
    Queue<StateNode> nextStates = new ArrayDeque<StateNode>();
    Set<String>      seenStates = new HashSet<String>();
 
    nextStates.offer(new StateNode(new Puzzle(this.sourcePuzzle), ROOT_MOVE, NO_PARENT));
 
    while (!nextStates.isEmpty()) {
	final StateNode currentState = nextStates.poll();
	final String puzzleString = this.generateEquivalentPuzzleString(currentState.puzzle);
 
	if (seenStates.contains(puzzleString)) {
	    continue;
	}
 
	if (this.targetGoal.matches(currentState.puzzle)) {
	    return this.buildSolution(currentState);
	}
 
	seenStates.add(puzzleString);
	this.offerNextStates(nextStates, currentState);
    }
 
    return null;
}

Summary

This isn’t the most user friendly app but I never really intended to release it anyway. It could probably be future optimized by adding an AI that could do path trimming or algorithm selection based on certain puzzle metrics. Error handling and usability could certainly be improved on. I found the exercise to be a good refresher on performance aware Java application development and a good reminder that my algorithms class in college does still hold some use for me.

Downloads

Slider Solver Source Code
Slider Solver Source Code
SliderSolver-Project.zip

Date:March 3, 2012
28.8 KiB
90 Downloads
Details...

Slider Solver (zip)
Slider Solver (zip)
SliderSolver.zip

Windows friendly version.

Date:March 3, 2012
1.1 MiB
89 Downloads
Details...

Slider Solver (tar.gz)
Slider Solver (tar.gz)
SliderSolver.tar.gz

Linux/Mac friendly version

Date:March 3, 2012
1.1 MiB
75 Downloads
Details...

Klotski Puzzle
Klotski Puzzle
klotski-puzzle.txt

Date:March 3, 2012
56.0 B
258 Downloads
Details...

Klotski Goal
Klotski Goal
klotski-goal.txt

Date:March 3, 2012
56.0 B
248 Downloads
Details...

Klotski Solution
Klotski Solution
klotski-solution.txt

Date:March 3, 2012
1.7 KiB
270 Downloads
Details...

Mar 2, 2012aewhiteCategory: General, Programming Read more Comments (1)

Pet Pictures

I was recently reminded that I have not updated my pictures in a while and, in particular, my pet album was missing a few. So, for the friends and family readers, I give you Green, Yellow, and Orange the hermit crabs and some Faye pup pictures. Our other hermit crab, Red, is probably molting right now so we didn’t dig him up for a photo shoot.

img_0042 img_0030 img_0023 img_0015_1

Feb 26, 2012aewhiteCategory: General, Life & Family Read more No Comments

LEGO iPad Stand

I’ve always loved LEGOs and this year for Christmas I got The LEGO Ideas Book. It has an entire chapter dedicated to practical applications of LEGOs such as card and pen holders. I also got this handy portable Bluetooth keyboard but our iPad’s case lacks the stand that some have. So, until we get one, I decided to build one and here are the results…

From a structural standpoint, the stand is fairly sturdy. It is mostly made from parts of an old LEGO fort from the Pirate series. This  project was particularly interesting due to the engineering challenge of supporting and balancing the iPad’s weight while not shearing the bricks from their bases.

Jan 10, 2012aewhiteCategory: General Read more No Comments

Unexpected empty JList model with IntelliJ’s GUI builder (Solved)

When working with IntelliJ’s GUI builder it is possible for custom implantations of  JList to mysteriously be empty when using a custom model that was defined and set in the constructor. This can be very confusion and non trivial to track down. This can be caused by accidentally setting the model property in the GUI Builder. The solution is to right click and select “Restore Default Value.”

This appears to be an issue because IntelliJ’s GUI builder uses instrumentation to inject the component properties at runtime. Furthermore, this occurs after the constructor of the components are finished. So, in a custom JList implementation, great care must be taken not to override any properties in the GUI builder that are going to be defined in code.

Jan 9, 2012aewhiteCategory: General, Programming Read more No Comments

Disable System Beeps for Non-KDE Applications (Eclipse) While Running KDE

If you have tried everything to get those annoying system beeps in KDE to stop but can’t, here is something to try.

  1. Launch gnome-control-center
    1. Can be done by typing “gnome-control-center” in a console while in KDE
    2. Log in to a Gnome session and launch the Control Center
  2. Find the “Sound” item
  3. Click the “Mute” checkbox next to “Alert Volume”

I noticed this issue when I was running Ubuntu and I updated to Kubuntu and I was running some non-KDE apps such as Eclipse. I had tried everything else from setting the system bell to mute to setting the “Beep Channel” to 0%/Mute and updating various settings in the System Notifications configuration. Finally I concluding that certain applications must still be pulling configurations from Gnome.

Mar 26, 2011aewhiteCategory: General, Programming Read more Comments (2)

How to Get the Most for Your Carnival Fun Points

This article outlines some easy to follow steps for participants in the Carnival Fun Points Mastercard program. The steps below work at the time of writing but may not after they change the point system on May 1st 2011, but may continue to work even then.

A little background

There is a little known secret about the Carnival Fun Points system that could save you hundreds of dollars on your next cruise. If you have ever played around with the Fun Points calculator you might have noticed some odd conversion ratios. First, let’s price out a cruise for $1250…

Ok, so we need 113,636 points to pay for that Cruise, fair enough. I wonder how much a $1251 cruise is worth in Fun Points…

What!? If I spend just $1 more I can cruise for free with just 74,910 points? Yes, and there is more to the story, but if you just want to see where the savings come in skip down to the “What does this mean for me?” section. So, you’re pricing a cruise, it sure would be nice to know where these boundaries are. After some basic analysis we can see that there are several of boundaries that are important to know.

Cost Range Points Needed Points Range
$50-$200 100 x Cost 5,000 – 20,000
$201-$800 ~95.23 x Cost 19,143 – 76,190
$801-$1250 ~90.91 x Cost 72,818 – 113,636
>$1251 ~59.88 x Cost 74,910

An astute reader will note that the same points buy you different amounts. For example if you have 73,000 points, which range do you fall in? The $801-$1250 range or the >$1251 range? Sadly it’s not documented on the site because they base their redemptions on the transaction amount NOT how many points you have.  However, as you can see, spending more than $1251 gets you a huge increase of points to cash conversion. There are still two more caveats to this system however.

  1. The table above is only for a redemption of a transaction in full!
  2. If you cannot redeem your transaction in full with your points it defaults to using the $50-$200 conversion rate.

Now I’m going to show you how to save big money using a few easy rules.

What does this mean for me?

There are two main parts of this process. First, figure out how much your points are really worth. Second, make sure you only pay for a very exact amount of your cruise at a time.

Step 1 – Figure out how much your points are worth

Use the following simple algorithm to determine what you can get with your points…

  • If you have more than 74,910 points then divide your points by 59.88
  • If you have between 72,818 and 74,909 points then divide your points by 90.91
  • If you have between 19,143 and 72,817 points then divide your points by 95.23
  • Else you don’t have enough points for this method to work

Step 2 – Pay only what your points will redeem in full now

This is the most important part. The credit card company only uses transaction amounts NOT the price of the cruise to calculate point redemption rates. So, if you calculated that your points are worth $1300 but your cruise will cost $2000, call your travel agent and only pay $1300 right now. As soon as the transaction posts, you can redeem your points in full and pay the remaining $700 later.

How much can I really save?

Let’s say you have a cruise booked for $1925 and you have 75,000 points. If you pay for the cruise in full and tried to redeem your 75,000 points you would get $750 off, not bad. Now, using the system above you would divide 75,000 by 59.88 and get $1252. Call the travel agent and pay for $1252 of the cruise, and redeem your points in full. You just saved $1252 or $500 more than what they would have given you in the first place.

Is this legal? How did you find out about this?

It’s legal but they can probably close this loophole at any time so I’m trying to let as many people as possible know about it. I found out about it when I didn’t get the points I expected. After several attempts to get customer service to provide me with a document that outlined their formulas or method I was simply told that no such document existed. Finally, I did find out that the redemption amount is based on transactions and not the price of the cruise. The conversation went something like this…

Me: “So, if I call up my travel agent and tell them to only post amount X you’ll give me an addition $Y back? Just by splitting the transaction”

Rep: “Yes, it’s only based on the transaction amount”

Conclusion

First, if at all possible spend more than $1251 and have at least 74,910 points. The savings are huge when compared to the lower values. Second, pay what your points are worth. Since you have 180 days to redeem your points for any given transaction you may be able to milk more savings out the system, but just be careful not to lock yourself into something you can’t buy your way out of. Finally, spread the word. I’m sure this loophole will get closed at some point but you might as well save an extra $500 on your next cruise at the expense of the credit card company.

Mar 16, 2011aewhiteCategory: General Read more Comments (3)

© 2008 The White Blog | Create by: Tatoon | Valid XHTML | CSS