Skip to content

Instantly share code, notes, and snippets.

@digulla
digulla / ApplicationContextAwareTestBase.java
Last active December 12, 2015 12:09
Helper class to reset/clean up Spring beans after a unit test
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.aop.TargetClassAware;
@digulla
digulla / updateSiteXml.py
Created March 11, 2013 09:49
Small Python script to generate site.xml files for a multi-module build. Run this after every change to the project structure.
#!/usr/bin/env python
from xml.etree.ElementTree import ElementTree, tostring
import os
import sys
import re
template = '''\
<project xmlns="http://maven.apache.org/DECORATION/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@digulla
digulla / jquery.text-overflow.js
Created June 17, 2013 10:33
Backup of Devon Govett's ellipsis plugin for jQuery
/*
* MIT LICENSE
* Copyright (c) 2009-2011 Devon Govett.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
@digulla
digulla / AnnotatedBeanLocator.java
Last active March 20, 2019 02:38
Locate beans in an ApplicationContext by annotation on the method which defines the bean.
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.type.StandardMethodMetadata;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
@digulla
digulla / DefaultLocaleRule.java
Last active March 9, 2022 17:16
JUnit 4 Rule to run individual tests with a different default locale
import java.util.Locale;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
public class DefaultLocaleRule extends TestWatcher {
private Locale originalDefault;
private Locale currentDefault;
public DefaultLocaleRule() {
@digulla
digulla / proxy-pac-debug.py
Created August 29, 2013 12:41
Command line utility to test and debug proxy.pac files. Depends on https://code.google.com/p/pacparser/
#!/usr/bin/env python2
# Usage: $0 proxy.pac url
import pacparser
import sys
import urlparse
pacfile, url = sys.argv[1:]
@digulla
digulla / RunPlattyRun_V1
Created December 15, 2013 21:45
Writing Games with Processing: Setup and a Simple Player Character
// Version 1: Setup and a Simple Player Character
void setup() {
size(640, 480); //VGA for those old enough to remember
}
int px = 320, py = 240;
int tileSize = 20;
void drawPlatty() {
@digulla
digulla / RunPlattyRun_V2
Created December 15, 2013 21:59
Writing Games with Processing: Enemies
// Version 2: Enemies
int px = 320, py = 240;
int tileSize = 20;
class Enemy {
color c;
int x, y;
String name;
@digulla
digulla / RunPlattyRun_V3
Last active December 31, 2015 11:19
Writing Games with Processing: Moving Around
// Version 3: Moving Around
int px = 320, py = 240;
int tileSize = 20;
class Enemy {
color c;
int x, y;
String name;
@digulla
digulla / RunPlattyRun_V4
Created December 18, 2013 11:59
Writing Games with Processing: Hunting Platty
// Version 4: Hunting Platty
int px = 320, py = 240;
int tileSize = 20;
int signum(float value) {
return value < 0 ? -1 : value > 0 ? 1 : 0;
}
class Enemy {