2013-03-18

Crucial Tips for Tomcat in Eclipse

This one post in Fruzenshtein's notes blog could have saved me many hours of futzing with Tomcat in Eclipse. I highly recommend anyone new to Vaadin read that article.

2013-03-12

Java Serialization Articles

Some articles I found useful when studying Java Serialization.

Serialization is the process of "dehydrating" an object's state (fields of data) and its meta-data (its Class, super-classes, number and data type of its fields, and so on). This information is written into a file or other stream of octets. The format of those octets is a part of the Java standard, the same across various host platforms. Later, a serialized Java object may be "rehydrated" into an instance in memory in the same Java Virtual Machine or any other JVM.

Serialization (Wikipedia)
For those new to the concept.

5 things you didn't know about ... Java Object Serialization
By Ted Neward.

Official spec for Java 7 Serialization

Top 10 Java Serialization Interview Questions

Testing object serialization
by Elliotte Rusty Harold

2013-03-03

Another Font for Programmers: Adobe "Source Code Pro"

Source Code Pro by Adobe is a new (2012) free-of-cost and open-source monospace font designed for programming use.



Designed for programmers means, among other things, similar characters are made distinct. Indeed, I read about this string that makes a cute example of three such similar characters:
1 illinois
 Read more about this new font in this Adobe blog by Paul D. Hunt.

The reigning king of programmers' fonts is still Pragmata. But it is nevertheless nice to have another choice alongside Apple Menlo, DejaVu Mono (the mother of Menlo), Microsoft Consolas, and Ubuntu Monospace.

By the way, this font is a follow-up to another open-source font from Adobe, Source Sans Pro discussed in this announcement. Adobe hosts these and other open source projects at SourceForge.

2013-01-19

Tweaking Mountain Lion

As in Lion, in Mountain Lion I disabled the annoying zooming rectangle that appears with each window opening.


Just copy-paste this single line in Terminal.app:

defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool NO

Just Smooth scrolling is now mandated throughout Mountain Lion, as documented by John Siracusa amazing review. Fortunately Mr. Siracusa also found a solution:

defaults write -g NSScrollAnimationEnabled -bool NO

In Mail.app > Preferences, I set New messages sound to None.

In System Preferences > General, I set Appearance to Graphite to tone down Aqua's distracting colors. While there I bump up Recent Items to 50.

2012-10-31

Custom URL scheme in iOS

iOS, Android, and some other operating systems allow an app to volunteer to handle certain kinds of hyperlinks. Besides the usual http:// and mailto:// and ftp:// sorts of links, you can create your own links. I could, for example, create my own basil:// link. Indeed, this is the main avenue Apple provides for applications to talk to each other in iOS.

For more information…

Launching Your iPhone App via Custom URL Scheme by Rodney Aiglstorfer. He gives detailed steps with screen shots showing how to implement your own scheme.

Apple provides a brief intro to this topic, along with other Advanced App Tricks.

Apple documentation on the URL schemes built into iOS for calling the mail, phone, texting, Google Maps, Google YouTube, and iTunes apps.

2012-09-28

Generate a UUID in Objective-C (iOS)

I am surprised to find that even by 2012 Apple has yet to include an object type for UUID. Nor do they provide an easy way to generate a UUID. Java does both.

The blog post Creating a GUID or UUID in Objective-C by Don McCaughey provides source code for a nice method to wrap Apple's clumsy UUID feature in Core Foundation. Unfortunately his 2010 code is not working for me Xcode 4.4.1, apparently because of ARC.

Error:
Cast of C pointer type 'CFStringRef' (aka 'const struct _CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast

Two fix-its offered. I chose this one:
Use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct _CFString *' into ARC

And I deleted his call to autorelease.

Here is my revision to Mr. McCaughey’s code. My revision seems to be working. But is memory managed correctly? I am still too new to Objective-C and C to grasp the nuance of bridging OOP and POC (Plain Old C). Please post corrections or criticism.


//=================
    // Return a new UUID string. Built for ARC in iOS 4 and later.
- (NSString *)generateUuidString
{
        // create a new UUID which you own
    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
    
        // create a new CFStringRef.
    NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, uuid));
    
        // release the UUID
    CFRelease(uuid);
    
    return uuidString;
}
//=================

StackOverflow.com has a thread on this topic.

2012-08-09

The Modern Way to Store Passwords - BCrypt

When authenticating users, you should never store their password value directly. The proper way is to salt and hash before storing.

Most hashing algorithms are designed to take a large amount of data such as documents and quickly return a hash. For storing passwords, you want the opposite: small data, and slow (strong) hashing.

Recognizing this different need, BCrypt takes a different approach. BCrypt uses the very strong but slow Blowfish cipher to do the hashing. BCrypt generates a random salt value to be added to the password, changing on each usage. Furthermore, and most importantly, BCrypt is adaptive. That is, as computing technology speed increases, you can increase the the strength of BCrypt by passing an increasing number. Though oversimplifying, you can think of the number as indicating the number of iterations of hashing and re-hashing. As computers get faster in the future, you can increase the strength of your hashing by passing a higher numbers.

For more info, read the original paper by  Niels Provos and David Mazieres. Read a brief overview by Coda Hale. Read this entertaining article by Thomas Ptacek.

Postgres 9 has a crypto module that includes a "crypt" command that seems to implement BCrypt. Here's a example of calling that command, where 'bf' means Blowfish:
    SELECT crypt('YourPasswordGoesHere', gen_salt('bf', 10));

Returns a hash value like this:
     $2a$10$Tq0dC2EDyqKhFbjQpu42b.Hzvg4dntLSZPFfvacmzKqR0E6uIRUyG

Increasing that number slightly dramatically increases the burden on a comupter. Here's some results of calling that in Postgres 9.0.4 on Mac OS X 10.6.7 on a MacBook with a 2.4 GHz Core 2 Duo.
  • 6 ≈ 40 milliseconds
  • 8 ≈ 130 ms
  • 10 ≈ 500 ms
  • 12 ≈ 1,600 ms
  • 14 ≈ 7,000 ms
  • 16 ≈ 28,000 ms (half a minute)
  • 21 ≈ 1 million ms (17 minutes)
During this time, the calculation took about 80-100% utilization of a CPU core.

BCrypt has been implemented in many languages, including C, Java, Python, Ruby, and more.

An implementation is bundled with Postgres, at least when using the installer for Mac OS X provided by EnterpriseDB. At least it seems to me that you are getting BCrypt if you specify the 'bf' argument, but the docs are not explicit -- Please correct me if I'm wrong.

To use this in Postgres,  you must enable the "pgcrypto" functions, by copying and executing the SQL found in the "pgcrypto.sql" file found someplace such as this:
    /Library/PostgreSQL/9.0/share/postgresql/contrib/pgcrypto.sql
Open that file, copy and paste to an interactive SQL window in the pgAdmin app. Actually, you only need the first third of that file's SQL, down to but not including the "pgp_" functions.