Skip to content

Instantly share code, notes, and snippets.

View iwalsh's full-sized avatar

Ian Walsh iwalsh

View GitHub Profile
@iwalsh
iwalsh / JSONBUserType.java
Created April 29, 2018 15:49
Hibernate UserType for marshalling Postgres jsonb columns <=> Jackson JsonNode objects
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.google.common.base.Objects;
import java.io.IOException;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
@iwalsh
iwalsh / fluent_method_chaining.rb
Created April 22, 2018 16:31
Fluent method chaining in Ruby
# Demonstrates a class-based approach for defining chainable methods: those that return a `self` reference.
class MyClass
def self.chainable_methods(&block)
mod = Module.new
# `class_eval` turns every method in the block into an instance method of this module.
mod.class_eval(&block)
mod.public_instance_methods(false).each do |method_name|