Category: Geek

TextMate for IntelliJ users

By , November 30, 2011

I use IntelliJ IDEA. I also use TextMate. The fact that I spend most of my day in IntelliJ means I’m used to IntelliJ’s keyboard mapping which happens to be slightly different from TextMate’s.

The biggest difference I found was with the Home and End keys and the Delete Line mapping. So here’s how to make TextMate work more like IntelliJ.

Change Home and End keys

From this old blog post:
Create the custom KeyBindings folder (if it doesn’t already exist):

mkdir ~/Library/KeyBindings

Create a key bindings file called DefaultKeyBinding.dict in this directory with the following content:

{
    /* home */
    "\UF729"  = "moveToBeginningOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
 
    /* end */
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";
 
    /* page up/down */
    "\UF72C"  = "pageUp:";
    "\UF72D"  = "pageDown:";
}

Change Delete Line mapping

Go to Bundles > Bundle Editor > Show Bundle Editor.
In text bundle, change Delete Line from CTRL+K to CMD+DELETE.
In the text bundle, Delete to Beginning of Line macro, click the X to remove the same binding.

Devoxx – Project Coin, Defective Java and the Social Network

By , November 18, 2010

Joe Darcy and Maurizio Cimadamore gave a preview of the changes coming up in Project Coin. These are small changes to the Java language that will be added to Java 7. They all look pretty useful and include:

  • Strings in switch
  • Collection literals
  • <> (generic type inference)
  • Multicatch
catch (ClassNotFoundException | NoSuchMethodException e) {
    // Do something
    throw(e);
}

Bill Pugh’s session was as popular as expected for his talk about defective code and how static analysis with FindBugs can help. I’ve heard Bill talk about this stuff before but this time he was emphasising that not all bugs are equal. All code has bugs but some mistakes don’t really matter.

Google’s code has over 1000 null pointer bugs but few if any NullPointerExceptions in running code are caused by these. You need to determine which bugs are worth your time to fix.

The most important bugs are generally those which can cost you money on the first day they manifest themselves and those bugs that occur silently. This is why Bill is a fan of runtime exceptions; if something unexpected happens, you want to know about it.

Devoxx is held in a massive cinema complex and so after all the talks today the organisers put on a showing of The Social Network, a movie about the founders of Facebook. I really enjoyed the film. All the performances were great and I really liked the soundtrack by Trent Reznor. You don’t need to be a geek to enjoy this film. I don’t know how much of it is actually true but it paints an interesting picture of Mark Zuckerberg and draws nice connections between our concepts of ‘friendship’.

Devoxx – Improve the performance of your Spring app

By , November 17, 2010

This talk by Costin Leau was about the new caching features in Spring 3.1.

After going over some problems you can face when caching (stale data, thrashing, distributed caches) and different caching patterns he introduced the declarative caching of Spring 3.1.

It uses AOP and can be declared on methods by adding the @Cacheable annotation. This annotation caches a method’s return value using it’s parameters as the key although this can be customised.

Eg:

@Cacheable
public Owner loadOwner(int id);
 
@Cacheable("owners")
public Owner loadOwner(int id);
 
// Using Spring expression language
@Cacheable(key="tag.name")
public Owner loadOwner(Tag tag, Date created);
 
@Cacheable(key="T(someType).hash(name)")
public Owner loadOwner(String name);
 
// Only cache on condition
@Cacheable(condition="name < 10")
public Owner loadOwner(String name, Date created);

The @CacheEvict annotation invalidates the cache:

@CacheEvict
public void deleteOwner(int id);
 
@CacheEvict("owners", key="id")
public void deleteOwner(int id, boolean saveCopy);
 
@CacheEvict(name="owners", allEntries=true)
public void batchUpdate()

You can also use your own stereotype annotations. Instead of spreading @Cacheable everywhere:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Cacheable("results")
public @interface SlowService {
 
}
 
@SlowService
public Source search(String tag) {...}

Spring is not a cache provider itself. You plug in your own cache provider (ehcache, JBoss Cache, etc).

Devoxx – Performance Anxiety

By , November 17, 2010

I doubt Joshua Bloch suffers from performance anxiety but it was slightly ironic that there were some technical problems before he started his talk, titled Performance Anxiety, to an absolutely packed room at Devoxx today. I knew it would be a popular session so I got there early and so managed to find a seat, unlike the others who sat on the steps or crowded the doorway.

His talk was about microbenchmarking – measuring the performance of a small piece of code as opposed to profiling an application.

In the good old days performance could be estimated simply by counting program instructions. Now it is simply impossible to do this because of the ‘abstraction gap’.  As code has become more and more complex it has become harder and harder to estimate and measure the performance.  Complexity and predictability are inversely related.

Even benchmarking code doesn’t really work with consecutive runs often showing a variance of 20%. The code and systems are so complex nobody really knows where this variance comes from.

The solution is to run a bunch of JVMs in sequence and then statistically analyse the data (mean, median, standard dev, etc).

Basically, benchmarking is really, really hard and most benchmarks are seriously broken. Either the results are unrelated to the test or the error bars exceed the measured values.

Caliper is microbenchmarking framework from Google which can help.

Devoxx – The Next Big JVM Language

By , November 17, 2010

Stephen Colebourne gave an entertaining talk to a packed room called The Next Big JVM Language. He went over the features of such new JVM languages as Groovy, Clojure, Scala and Fantom (which I’d never heard of).

He seemed to be leaning toward Fantom as the language of choice before delivering the punchline that the best candidate for the Next Big Language might be a backwards incompatible version of Java itself.

I think I agree. Oracle should get rid of all that legacy crap in JDK 9.

Devoxx day two

By , November 16, 2010

A couple of pretty heavy-going sessions at Devoxx today. First up was Cassandra by Example with Jonathan Ellis one of the founders of Cassandra support company Riptano.

I have already had some experience with Cassandra at both my previous and current jobs but it was good to go over the principals of Cassandra as well as seeing an example application deconstructed.

Cassandra’s strengths are:

  • Scalability
  • Reliability
  • No single point of failure
  • Multiple data centre support
  • Integrated Hadoop support (lets you run map reduce jobs on data in Cassandra without any ETL)

Of course Cassandra is not ACID and has limited support for OLTP ad-hoc queries. However, companies that have really scaled traditional RDBMSs like MySQL or Oracle end up dispensing with these features anyway in order to achieve that scale.

Jonathan had an interesting quote from Twitter:

It used to take 2 weeks to perform an ALTER TABLE on the tweets table

This is  definitely something I can sympathise with. If you don’t plan ahead it can be easy to suddenly find your tables are so big they cannot be changed without serious pain, downtime or both.

When designing a relational schema we tend to think of objects and relationships. With Cassandra we need to think of objects and the queries we want to run against them. For each type of query you will need a column family (something like a table).

When choosing a key for rows, a natural key is best. If you need a surrogate key, use a UUID as integers may create collisions due to the distributed nature of Cassandra. Version 1 UUIDs can be sorted by time but if you don’t need time ordering, use version 4 UUID.

Using Thrift directly should be avoided at all costs in favour of higher level libraries like Hector. There is a JPA implementation called Kundera but this is based around Lucene so unless search is an important part of your application it may not be the best choice.

The afternoon was spent learning what’s new in Hibernate with Emmanuel Bernard from JBoss.

Fetch profiles can be defined and chosen at runtime, eg:

@Entity
@FetchProfile(name = "all",
    fetchOverrides = {
        @FetchProfile.FetchOverride(
            entity = Customer.class,
            association = "orders",
            mode = FetchMode.JOIN)
        @FetchProfile.FetchOverride(
            entity = Order.class,
            association = "country",
            mode = FetchMode.JOIN)
})
 
public class Customer {
    @Id @GeneratedValue private long id;
    private String name;
    private long customerNumber;
    @OneToMany private Set&lt;Order&gt; orders;
 
// standard getter/setter
}
 
Session session = ...;
session.enableFetchProfile( "all" );  // name matches @FetchProfile name
Customer customer = (Customer) session.get( Customer.class, customerId );
session.disableFetchProfile( "all" ); // or just close the session

A lot of time was spent on the Criteria API which lets you write object oriented, type-safe and strongly typed queries.

Hibernate Search provides lucene-based full text search for Hibernate and looks quite neat. You get transparent index synchronisation and support for clustering and loading of massive indexes.

Hibernate Envers also looks really interesting. This is a framework for dealing with historical data in Hibernate.

Entities are versioned and all changes (insert, update, delete) are audited transparently. The existing tables are unchanged but new audit tables are created for each entity. For example a Person table will get a Person_AUD table. This looks the same with the addition of revision number and revision type (add, delete, modify) columns.

You can look up by revision and query by revision or entity history. You can also define a RevisionEntity to add new fields atop the standard revision number and date.

It looks really helpful for auditing and dealing with historical data although there is of course a performance hit to inserts, updates and deletes as the audit table must be written to as well.

Devoxx day one

By , November 15, 2010

Today was the first day of Devoxx, the European Java conference held in Antwerp.

The first two days are actually the ‘University’ sessions. These are longer, more in depth talks and the first one I went to was the ‘Productive Programmer’ by Neal Ford from Thoughtworks.

This was an interesting talk split into two sections, the first dealing with the mechanics of productivity and the second consisting of a number of tips putting these principals into practice.

The overarching theme was that “any time you are doing simple repetitive stuff on behalf of your computer it is laughing at you”. This means don’t type the same commands over and over but it also means learning keyboard shortcuts for your IDE and OS.

Neal demonstrated the Key Promoter plugin for IntelliJ which will pop up keyboard shortcuts whenever you use a menu item instead. I already use the GOTO class shortcut in IntelliJ all the time but didn’t know you can just type the capital letters of a class and it will find it. For example type ‘mac’ to find MyAwesomeClass.

Neal is so productive he doesn’t even bother to type the left hand side of statements in IntelliJ; he lets the IDE fill that in for him (using introduce variable). :-)

Neal also talked about a concept called ‘locus of attention’ and the need to make your environment quiet to preserve your locus of attention. The higher the level of concentration, the denser the ideas, so turn off notifications, don’t keep email open all the time. Windows is the worst at stealing focus; “it is like a bored 3 year old”. Another reason why 80% of people here seem to have Macs… I quite like the idea of using something like Doodim to gradually dim everything on your desktop apart from the application you are working in.

The problem with using graphical tools to navigate a file system or class structure is that the hierarchies are too deep. Any time you know where you want to get to already it will be faster to search than to navigate. So make use of shortcuts like GOTO class or OSX menu item search.

Another neat idea was to use Selenium to record interactions for debugging web apps. Rather than having to repeatedly click through a sequence to get to where you need to be in the app, simply record the sequence using Selenium and play it back instantly. Even better: get your QA team to record a Selenium script to reproduce a bug and have them attach that to the JIRA ticket instead of a screenshot.

Neal suggests to always use a ‘real’ programming language for scripting (groovy, ruby, php) instead of sed or awk. This allows your little tools to grow into assets and lets you add unit tests and refactor.

The second major session was an introduction to MongoDB by Alvin Richards. This was a pretty in depth session and as he said it was a bit like drinking from the firehose but I came away liking what I saw.

MongoDB belongs to the so-called NoSQL family of data stores and is ‘document oriented’. Documents are stored as binary JSON and the schema is not fixed. This makes it really easy for your schema to evolve with your application.

With MongoDB you get all this built in:

  • Horizontal scaling
  • Simplified schema evolution
  • Simplified deployment and operation

Reads can be scaled using replica sets. These are a cluster of servers where any node can be the primary and failover/recovery is handled automatically. All writes go to the primary node.

Writes can be scaled using automatic sharding. MongoDB’s sharding is transparent to the application code and migrations and rebalancing are handled automatically with no down-time(!)

You can write Map Reduce functions in JavaScript for MongoDB.

You can either use the low-level java library to talk to MongoDB or use Morphia which provides a kind of O/R wrapper to map your POJOs. Morphia gives you Annotations like @Entity, @Transient, @Indexed, @PrePersist, @PreSave, @PostPersist, etc.

To backup MongoDB you can either use mongodump/mongorestore which gives you a binary dump that is not neccesarily consistent from start to finish or use fsync + lock from a slave and then snapshot the files.

It was a long day but a good start to the conference. Tomorrow I’m starting with another NoSQL data store: Cassandra.

Sharkproof

By , March 31, 2010

I may never go to the moon, but it’s nice to know that if I do my Speedmaster will still keep ticking.

I like watches. I particularly like watches that have some history or character about them. Watches that are designed for a purpose, not just to look good.

Omega have released a new version of their Seamaster PloProf. The standard Seamaster is a nice watch, good enough for James Bond, but the PloProf is like a Seamaster on steroids.

The first PloProf (the name comes from plongeurs professionnels – French for “professional divers”) was first released in 1970 and it was rated to the man-crushing depth of 600M. It also looked like no other watch. The crown was on the other side and under a protective shield to allow freer wrist movement and to protect against any accidental changes at depth.

At the 2 o’clock position is the orange bezel-release security pusher. You need to push this to move the bezel, again to prevent any accidental asphyxiation on the sea floor.

The new PloProf has all these same features as the original but doubles the depth to a giant squid-dwelling 1200M. You can also get it with a “Sharkproof” bracelet.

Nice to know that if you drop it in the bath, or get your arm bitten off by a shark it will still keep time.

You do not have permission

By , February 10, 2010

Miguel found this screenshot in an old email from when we were working on permissions and preferences in OpenX:

The subject of the email was “Permissions & Settings: Learn From The Masters”

Piping Wired

By , July 19, 2009

Big PipesLove how there is now a UK version of Wired?  Hate how it doesn’t have Scott Brown or Steven Levy?

I do.

I mean, Warren Ellis is great and all but I miss my favourite regular writers from US Wired.

Well now I’ve finally found a use for Yahoo Pipes, that cool but strangely pointless thing Yahoo built a couple of years ago.

Luckily Wired post all their magazine content online (an inferior format, unworthy of Wired’s awesome graphic design, but I’m not going to buy both editions of the magazine, especially as they share some of the feature articles) so I created a pipe to suck down the Wired RSS feed and filter it for articles by Scott Brown and Steven Levy.

Now I have the best of both worlds.

You can get an RSS version of the pipe here.

Image: Uwe Hermann

Panorama Theme by Themocracy

SEO Powered by Platinum SEO from Techblissonline