Skip to content

Instantly share code, notes, and snippets.

@lifecoder
lifecoder / UniqueId.java
Created August 18, 2011 09:19
UniqueId (UUID) embedded primary key in JPA 2 (Hibernate) for MySQL
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.UUID;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@lifecoder
lifecoder / nested-funcs.js
Created May 6, 2011 22:15
Named nested functions after return
CategoryRepository.prototype.findAll = function(callback) {
return this.db.collection('categories', onCollectionReady);
function onCollectionReady(error, collection) {
if (error) return callback(error);
collection.find(onCursorReady);
}
function onCursorReady(error, cursor) {
console.log('onCursorReady');
if (error) return callback(error, null);
cursor.toArray(callback);
@lifecoder
lifecoder / CategoryRepository.js
Created April 14, 2011 21:20
simple DAO example for nodejs
var mongo = require('mongodb'),
EventEmitter = require('events').EventEmitter;
function Connector(settings) {
settings.port = settings.port || mongo.Connection.DEFAULT_PORT;
this.settings = settings;
this.server = new mongo.Server(settings.host, settings.port);
this.db = new mongo.Db(settings.database, this.server, {native_parser: true});
}