Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
@jarrodhroberson
jarrodhroberson / jquery.couch.js
Created April 26, 2010 03:54
jquery.couch.js patched to allow list function queries with both GET and POST
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
@jarrodhroberson
jarrodhroberson / Main.java
Created June 13, 2011 21:40
Java formatted interval processing
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main
{
private static long parseInterval(final String s)
{
final Pattern p = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{3})$");
final Matcher m = p.matcher(s);
@jarrodhroberson
jarrodhroberson / FluentApiEnforcement.java
Created July 7, 2011 19:44
Fluent API Enforcement in Java using Interfaces
import java.util.Date;
public class PermissionManager
{
public static AssignPermission grantUser(final String user)
{
return new Rights(user);
}
private static class Rights implements AssignItem, AssignPermission, SetDate
@jarrodhroberson
jarrodhroberson / InsertionOrderSet.java
Created November 1, 2011 17:55
Sorted Set implementation that preserves insertion order like a List does
import java.util.*;
public class InsertionOrderSet<E> implements SortedSet<E>
{
private final SortedSet<IndexedEntry<E>> bs;
public InsertionOrderSet(final E[] e)
{
this(Arrays.asList(e));
}
@jarrodhroberson
jarrodhroberson / size of array.cpp
Created November 12, 2012 15:33
How to get the length of an array with a template as well as pass in an array to a function to get its length in the function.
#include <cstdint>
#include <stdio.h>
template<typename T, size_t SIZE>
size_t getSize(T (&)[SIZE]) {
return SIZE;
}
typedef std::uint_fast8_t byte;
@jarrodhroberson
jarrodhroberson / delve-jar.sh
Created March 12, 2013 16:52
A short Bash script to delve through a directory of .jar files and find the ones that contain a given package or class.
#!/bin/sh
find . -name '*.[jwes]ar' | while read LINE; do grep -q $1 "$LINE"; if [ $? -eq 0 ];then echo "$LINE"; jar tvf "$LINE" | grep $1;echo;fi;done
@jarrodhroberson
jarrodhroberson / DiagnosticProperties.java
Last active December 19, 2015 20:09
Diagnostic Properties implementation
package com.gm.gbrd.prefs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
/**
* This class is very very resource intensive and should only be used for diagnostic purposes, it should never
* be used in production code, Thread.currentThread.getStackTrace() is a very expensive operation, this was created
@jarrodhroberson
jarrodhroberson / NodeChangeEvent.java
Last active December 19, 2015 20:09
More advanced and feature rich Preferences object than java.util.Preferences, and one that is compatible with Google App Engine.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gm.gbrd.FormattedRuntimeException;
import javax.annotation.Nonnull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.EventObject;
public class NodeChangeEvent extends EventObject
{
@jarrodhroberson
jarrodhroberson / weblogic-application.xml
Created July 22, 2013 16:55
weblogic-application.xml example
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.3/weblogic-application.xsd">
<application-param>
<param-name>webapp.encoding.default</param-name>
<param-value>UTF-8</param-value>
</application-param>
</weblogic-application>
@jarrodhroberson
jarrodhroberson / MyApp.java
Created September 10, 2013 15:12
Proper idiom to correctly implement the "Singleton" pattern in modern versions of Java.
import javax.management.InstanceAlreadyExistsException;
import javax.management.JMX;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
public class MyApp