Skip to content

Instantly share code, notes, and snippets.

Arthur Embleton aembleton

Block or report user

Report or block aembleton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aembleton
aembleton / Only UK but this Perl can be expanded upon
Created Mar 15, 2011
Call Perl number normalisation from Java
View Only UK but this Perl can be expanded upon
#!/usr/bin/perl
use strict;
use warnings;
my $n = $ARGV[0];
my $country = $ARGV[1];
if ($country eq "GB") {
if ($n =~ /^0(\d{10})$/x) {
@aembleton
aembleton / Regex.java
Created Mar 17, 2011
Matches regular expressions in the haystack. Any matched strings are returned in a list.
View Regex.java
package util;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
/**
@aembleton
aembleton / Ignore certificate for HttpURLConnection in Android.java
Created Mar 27, 2011
The following code disables SSL certificate checking for any new instances of HttpsUrlConnection
View Ignore certificate for HttpURLConnection in Android.java
/**
* Disables the SSL certificate checking for new instances of {@link HttpsURLConnection} This has been created to
* aid testing on a local box, not for use on production.
*/
private static void disableSSLCertificateChecking() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@aembleton
aembleton / StringUtil.java
Created May 19, 2011
Useful String utility methods.
View StringUtil.java
package utils;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
@aembleton
aembleton / MapToData.java
Created Jul 21, 2011
Converts a Map into URLEncoded data that can be used in a POST
View MapToData.java
package net.blerg;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@aembleton
aembleton / JsonUtil.java
Created Jul 22, 2011
Utility class containing static methods that are useful for reading in and marshalling JSON
View JsonUtil.java
package net.blerg.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
@aembleton
aembleton / MapUtil.java
Created Jul 26, 2011
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.
View MapUtil.java
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 Jul 26, 2011
Auto-generated toString useful for all beans.
View Bean.java
/*
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 Aug 21, 2012
Ant script that packages up all of the jars into a single executable jar
View build.xml
<?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"/>
View KeyValue.java
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 = '\\';
You can’t perform that action at this time.