Skip to content

Instantly share code, notes, and snippets.

@aembleton
aembleton / MapUtil.java
Created July 26, 2011 10:49
Converts a List into a Map where the key is set to the value returned by calling the getter for the specified keyProperty on each element of the List and the value is set to the object held in the List.
package net.blerg.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@aembleton
aembleton / Bean.java
Created July 26, 2011 11:02
Auto-generated toString useful for all beans.
/*
Copyright (c) 2007 Arthur Embleton
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:
@aembleton
aembleton / build.xml
Created August 21, 2012 15:40
Ant script that packages up all of the jars into a single executable jar
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="jar">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="DataPersist.classpath">
<pathelement location="bin"/>
<pathelement location="lib/commons-cli-1.1.jar"/>
<pathelement location="lib/commons-io-1.2.jar"/>
package utils;
import java.util.HashSet;
import java.util.Set;
public class KeyValue {
private static final char DELIMITER = ':';
private static final char KEY_VALUE_DELIMITER = ',';
private static final char ESCAPE_CHAR = '\\';
@aembleton
aembleton / InformationBox.java
Created August 29, 2012 14:30
Provides a way to produce an information box surrounded by a char such as *.
import java.util.LinkedList;
import java.util.List;
/**
* Provides a way to produce an information box surrounded by a char such as *. To use, add lines by calling {@link #add(String)} and then call {@link #getStringsInBox(char)} to get a String that can
* be put into a System.out.println call or used elsewhere that is formatted.
*
* @author Arthur Embleton
*
*/
package net.blerg.oracleToMysql.util;
import java.util.LinkedList;
import java.util.List;
public class PatternReplace {
public static String replace (String string, String pattern, String replacement, char wildcard, char escapeChar, boolean ignoreCase) {
//tokenise against the pattern
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@aembleton
aembleton / lastfm_top-tags.py
Created December 13, 2015 16:45
Add tags to MP3s
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
def main(f):
if not os.path.splitext(f)[1].lower() == '.mp3':
err('usage')
@aembleton
aembleton / Frequency of email address domains
Created March 22, 2013 14:00
Find the frequency of email address domains from your email table.
select substring_index(value, '@',-1) as email, count(*) as frequency FROM emailTable where name="EmailAddress" group by email order by frequency desc;
package com.jandrewthompson;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**