Skip to content

Instantly share code, notes, and snippets.

View michael-simons's full-sized avatar

Michael Simons michael-simons

View GitHub Profile
@michael-simons
michael-simons / fitbit_archiver.rb
Created February 12, 2013 12:33
This script fetches stuff from the fitbit api. You need to register an app (for consumer key and secret) and authorize this script on behalf of your account. One way to do this is with the out of band authentication. Feel free to expand this script to automate this.
# encoding: UTF-8
require 'rubygems'
require 'date'
require 'optparse'
require 'ostruct'
require 'oauth'
require 'json'
class FitbitArchiver
@michael-simons
michael-simons / gist:5299398
Created April 3, 2013 08:17
Move some specific files from one git repository into a new one preserving the history
cd ~/the/old/repo
find -E . -regex ".*(File1|File2)\.java" | xargs git log --pretty=email --patch-with-stat --reverse | (cd ~/the/new/repo && git am)
@michael-simons
michael-simons / Unchecker.java
Last active December 17, 2015 22:19
This code "unchecks" checked exceptions without wrapping them in RuntimeException and polluting the stacktrace.
package ac.simons.utils;
/**
* Use it like throw Unchecker.uncheck(checkedException);
*
* @author Michael J. Simons, 2012-02-03
* http://www.gamlor.info/wordpress/2010/02/throwing-checked-excpetions-like-unchecked-exceptions-in-java/
*/
public final class Unchecker {
private Unchecker(){}
@michael-simons
michael-simons / CalendarTest.java
Created October 15, 2013 09:05
Hibernate changed tz handling in 4.2.6 for mysql date columns.
package tests;
import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
/** This breaks several criteria queries, especially root.subquery() and a join on foobar in the subquery */
@Id
@ManyToOne(fetch=FetchType.EAGER, optional=false)
@JoinColumn(name="foobar_id")
@Fetch(FetchMode.JOIN)
Foobar foobar;
@Id
@Column(name="id")
package org.hibernate.bugs;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
NamedNativeQuery(
name="Foobar.findByBlahAndBlub"
query="Select * from foobar where blah_id = :blah and lower(blub) = :blub"
)
Optional<Foobar> findByBlahAndBlub(Blah blah, String blub);
@michael-simons
michael-simons / gist:fc401f19817e207ad747b86dfe8fc649
Created July 5, 2016 14:39
Error upgrading wro4j-spring-boot-starter
Checking compile classpath
Checking runtime classpath
Checking test classpath
Found duplicate (but equal) classes in [net.minidev:accessors-smart:1.1, org.ow2.asm:asm:5.0.3]:
org.objectweb.asm.AnnotationVisitor
org.objectweb.asm.AnnotationWriter
org.objectweb.asm.Attribute
org.objectweb.asm.ByteVector
org.objectweb.asm.ClassReader
org.objectweb.asm.ClassVisitor
@michael-simons
michael-simons / T_SBFA_ASPECT_INSTANCE_FACTORY.SQL
Created July 12, 2016 07:33
SimpleBeanFactoryAwareAspectInstanceFactory
CREATE OR REPLACE TYPE T_SBFA_ASPECT_INSTANCE_FACTORY AS OBJECT (
CONSTRUCTOR FUNCTION T_SBFA_ASPECT_INSTANCE_FACTORY RETURN self AS result,
MEMBER PROCEDURE SET_ASPECT_BEAN_NAME(P_ASPECT_BEAN_NAME IN VARCHAR2),
MEMBER FUNCTION GETASPECTINSTANCE RETURN OBJECT
)
/
package patternexamples;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
public class Sandwich {
private final String bread;