Tuesday, March 4, 2014

Ruby Tricks - Listing time spent in code

<some code>

@@t = ::Time.now

<more code>

puts "Time: " + (::Time.now-@@t).to_s +  "\n"

Note: the ::Time is only there because I ran into a conflict between the Time class in Ruby and the Time class in one of the gems I'm using.

Thursday, July 19, 2012

Truncate vs Delete in Oracle

Database 101 says...always truncate instead of doing a delete from on tables. It's faster and more efficient. Well, everything you learn in a beginning class is wrong sometimes.

We had a set of Junit tests that truncated a set of Oracle tables a few thousand times. It took a long time. Changing those truncates to deletes made the tests run about 10 times as fast. So apparently truncate has some overhead that delete does not.

Lesson: the stuff you learn in Anything 101 should be verified.

Wednesday, June 9, 2010

Googley

We've been re-architecting our application from Swing to GWT and it's been working quite well. GWT is surprisingly stable and non-quirky. In general. It has some visual issues with IE6 but then IE6 has some issues with IE6.

One thing we did was use an event bus to pass events around. This solved a number of issues for us. Sometimes an event in one view would need to trigger a change in another view, or multiple views and this pattern allowed us to easily trigger those changes without having to clutter up the interfaces of parent classes.

Thursday, January 28, 2010

Testing Testing

The different ways to test a DB connection:

MySQL/PostgreSQL/MS SQL use: SELECT 1
DB2 use: SELECT 1 FROM sysibm.sysdummy1
Oracle use: SELECT 1 from dual

Why do DB2 and Oracle always have to be different? Just because they can?

Wednesday, October 21, 2009

Swing Low

Thanks to the book Swing Hacks for this one. An extended version of JButton that blurs when it's disabled.

/**
*
* @author bhegberg
*/
public class BlurJButton extends JButton {
public BlurJButton(String text) {
super(text);
}

public void paintComponent(Graphics g) {
if (isEnabled()) {
super.paintComponent(g);
return;
}
BufferedImage buf = new BufferedImage(getWidth(),getHeight(), BufferedImage.TYPE_INT_RGB);
super.paintComponent(buf.getGraphics());
// Blur the buffered image
float[] my_kernel = {
0.10f, 0.10f, 0.10f,
0.10f, 0.20f, 0.10f,
0.10f, 0.10f, 0.10f };
ConvolveOp op = new ConvolveOp(new Kernel(3,3, my_kernel), ConvolveOp.EDGE_NO_OP, null);
Image img = op.filter(buf,null);

g.drawImage(img,0,0,null);
}
}

Friday, September 25, 2009

Webamability

Interesting usability article(s):
http://www.smashingmagazine.com/2009/09/24/10-useful-usability-findings-and-guidelines/

Synopsis:
1. Put labels over text boxes. Not to the left.
2. Having a picture of someone looking at your text gets it read more.
3. Quality=credibility (This is pretty obvious)
4. Users scroll more than they used to but only if given a reason.
5. Links should be blue. Google has blue links...
6. Search boxes should be 27 chars wide.
7. White space between paragraphs helps comprehension.
8. 3 users will find 75% of the problems, 6 users will find 90%.
9. Product pages are good. (Well, duh...)
10. Users ignore advertising...and also stuff that just looks like advertising. Be careful...

Wednesday, September 23, 2009

RESTafarianism

I've read some things about REST in the past and I've never really seen much point to it. I mean, if it makes sense to use URLs to drill into data then do it that way. Otherwise don't. But now I see things a bit clearer. I can see how RESTful URLs are like SOAP responses that contain their own WSDL. I can see how the URL becomes a name for a piece or batch of data and that makes it easily cachable. That name for a batch of data also makes it more flexible. And you can make it scalable more easily because you can (for instance) put in place hierarchies of servers...load balancers for instance in a way that makes sense for your hierarchical data.

I still don't understand completely why it's called REpresentational State Transfer though.