Skip to content

Instantly share code, notes, and snippets.

View mikaelhg's full-sized avatar
🏠
Working from home

Mikael Gueck mikaelhg

🏠
Working from home
View GitHub Profile
@mikaelhg
mikaelhg / FooTest.java
Created May 13, 2011 13:35
Spring 3.1 MVC unit testing with annotated controllers, JAXB2 marshalling, and @PathVariable annotations
package foo.bar.baz;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
@mikaelhg
mikaelhg / confluence-migrator.sql
Created July 3, 2011 17:19
Confluence migrator SQL script
BEGIN;
INSERT INTO users (id, name, password, email, fullname)
SELECT u.id, u.username, u.passwd,
(SELECT string_val FROM os_propertyentry
WHERE entity_id = u.id AND entity_key = 'email'),
(SELECT string_val FROM os_propertyentry
WHERE entity_id = u.id AND entity_key = 'fullName')
FROM os_user u
WHERE u.id NOT IN (
@mikaelhg
mikaelhg / pgmail.sql
Created October 14, 2011 10:25
PostgreSQL PL/Python stored procedures for email handling
CREATE OR REPLACE FUNCTION download(url TEXT) RETURNS TEXT
AS $$
import urllib2
try:
result = urllib2.urlopen(url)
rawdata = result.read()
info = result.info()
try:
content_type, encoding = info['Content-Type'].split('charset=')
except:
@mikaelhg
mikaelhg / DaoUsage.java
Created November 26, 2011 10:08
Spring Data JPA example snippets
@Autowired
private ExampleDao dao;
model.put("examples", dao.findAll());
model.put("comedies", dao.findByNameLike("%y%"));
@mikaelhg
mikaelhg / CustomizableExpressionTraceInterceptor.java
Created November 29, 2011 18:57
Customizable Expression Trace Interceptor
package gumi.spring;
import java.util.HashMap;
import java.util.Map;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.springframework.aop.interceptor.AbstractTraceInterceptor;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@mikaelhg
mikaelhg / basics.md
Created July 24, 2012 20:29
Ethical professional developers optimize for business results

Ethical professional developers optimize for business results per unit of resources over product or project lifecycles, balanced risk profiles over project portfolios, and the ablity to scale investment into a given project both up and down as the business environment changes.

Let's break this down.

Ethics

The virtue of a professional acting ethically is that this allows for trust in working relations between colleagues and organizations, which in turn makes working together significantly more efficient, as there is significantly less need to verify and control. The profession of software development has plenty of in-house codes of conduct, as well as the codified ACM "Software Engineering Code of Ethics and Professional Practice".

Many of the everyday ethical questions break down to the form: should I do A which is best for me, B which is best for my employer, or C which is best for the client. Very rarely you add D, best for our society, when C is clearly detrimental to the society. Unless D is releva

public class Foo {
public void test1() {
long timeout = System.currentTimeMillis() + 500;
int i = 0;
while (System.currentTimeMillis() < timeout) {
System.out.println(i++);
try {Thread.sleep(50);} catch (Exception ex) {}
}
}
@mikaelhg
mikaelhg / Boot.scala
Created September 22, 2012 09:28
Scalate PlantUML + ditaa macro
package scalate
import org.fusesource.scalamd.{MacroDefinition, Markdown}
import java.util.regex.Matcher
import org.fusesource.scalate.wikitext.Pygmentize
import org.fusesource.scalate._
import util.Log
import net.sourceforge.plantuml.{FileFormat, FileFormatOption, SourceStringReader}
import java.io.ByteArrayOutputStream
import java.nio.charset.StandardCharsets
@mikaelhg
mikaelhg / fix-vb-mouse-glitch.sh
Created November 20, 2012 11:49
Fix VirtualBox mouse jump glitch
#!/bin/bash
# Fix glitching mouse with VirtualBox + Ubuntu 12.10:
# https://bbs.archlinux.org/viewtopic.php?id=145960&p=2
# https://www.virtualbox.org/ticket/10853
# https://bugs.freedesktop.org/show_bug.cgi?id=54353
xinput set-prop "VirtualBox mouse integration" "Coordinate Transformation Matrix" 0.5 0 0 0 0.5 0 0 0 1.0
xinput set-prop "VirtualBox mouse integration" "Coordinate Transformation Matrix" 1.0 0 0 0 1.0 0 0 0 1.0
@mikaelhg
mikaelhg / mysql_to_jpa.py
Created November 25, 2012 11:37
Automatically generate / reverse engineer a MySQL database and generate Scala JPA classes for tables
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy.engine import reflection
from datetime import datetime
engine = create_engine('mysql://username:@localhost/foobar')
insp = reflection.Inspector.from_engine(engine)