Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
@jarrodhroberson
jarrodhroberson / ObjectifyLoaderContextListener.java
Last active July 29, 2017 15:21
A Servlet Context Listener to automatically register @entity decorated classes with ObjectifyFactory
import com.google.appengine.api.ThreadManager;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.annotation.Entity;
import org.reflections.Reflections;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@jarrodhroberson
jarrodhroberson / find_in_jar.bat
Last active November 16, 2017 00:50 — forked from leogomes/find_in_jar.sh
bash and windows shell scripts to find classes in .jar files in a directory
# Windows (cmd) Command line version
forfiles /S /M *.jar /C "cmd /c jar -tvf @file | findstr /C:"$1" && echo @path"
@jarrodhroberson
jarrodhroberson / Q21866253.java
Last active February 1, 2019 07:53
Example for a StackOverflow question about rate limiting a function call.
package com.stackoverflow;
import com.google.common.util.concurrent.RateLimiter;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
@jarrodhroberson
jarrodhroberson / PadStrings.java
Created February 17, 2014 20:12
Padding Strings in Java with String.format()
public static String padRight(@Nonnull final String s, int n)
{
return String.format("%1$-" + n + "s", s);
}
public static String padLeft(@Nonnull final String s, int n)
{
return String.format("%1$" + n + "s", s);
}
@jarrodhroberson
jarrodhroberson / main.groovy
Created February 14, 2014 03:46
Groovy and JSAP
JSAP jsap = new JSAP(main.getResource("main.jsap"));
JSAPResult config = jsap.parse(args)
if (config.getBoolean("help") || !config.success())
{
println "Usage: java -jar main.jar " + jsap.usage
println ""
println jsap.help
if (!config.success())
{
for (e in config.getErrorMessageIterator())
@jarrodhroberson
jarrodhroberson / jsap.xml
Created February 14, 2014 03:45
JSAP Example Configuration File
<jsap>
<parameters>
<switch>
<id>help</id>
<shortFlag>h</shortFlag>
<longFlag>help</longFlag>
<help>Display this help</help>
</switch>
<flaggedOption>
<id>host</id>
@jarrodhroberson
jarrodhroberson / PS1.sh
Created February 14, 2014 03:43
My favorite PS1 prompt definition
PS1="\[\e[0;37m\][\[\e[m\]\[\e[0;32m\]\u\[\e[m\]\[\e[0;31m@\[\e[m\]\[\e[0;32m\]\h\[\e[m\]\[\e[0;37m\]]\[\e[m\] \[\e[0;37m\][\[\e[m\]\[\e[0;34m\]\w\[\e[m\]\[\e[0;37m\]]\[\e[m\]\n"
@jarrodhroberson
jarrodhroberson / file_selection.py
Created February 14, 2014 03:41
Object Oriented File Selection in Python
class Action:
"""
Actions are things that can be executed.
"""
def execute(self):
pass
class PatternSet:
"""
Pattern set provides the interface and abstract functionality to provide the include and exclude
@jarrodhroberson
jarrodhroberson / linereceiver.erl
Created February 14, 2014 03:38
Python/Twisted vs Erlang/OTP
-module(linereceiver).
-export([start/1]).
sleep(T) ->
receive
after T ->
true
end.
start(Port) ->
@jarrodhroberson
jarrodhroberson / walk_dirs.m
Created February 14, 2014 03:36
Recursively list all files and directories below a given directory
/*
This is example code of how to walk a directory recurisively
and create a flat list of fully qualified names for all the files
and directories under the supplied virtual root directory.
*/
#import <CoreServices/CoreServices.h>
#import <AppKit/AppKit.h>
#import <stdarg.h>
int main (int argc, const char * argv[])