Skip to content

Instantly share code, notes, and snippets.

View UnquietCode's full-sized avatar

Benjamin Fagin UnquietCode

View GitHub Profile
@UnquietCode
UnquietCode / convert_to_tag.sh
Created August 16, 2013 22:13
Converts a git branch to a git tag, by passing in the branch name. Turns a branch "my-branch" into a tag "my-branch.final" and deletes the branch.
git checkout $1
git pull origin $1
git tag $1.final
git checkout master
git branch -d $1
git push origin --tags :$1
@UnquietCode
UnquietCode / Example.java
Last active December 20, 2015 21:09
I use this handler class when I want to have dynamically typed, variable length parameters.
registerStudent(student, new HandlerChain<RegistrationStep>()
.on(RegistrationStep.NEW_STUDENT, new FlexibleHandler() {
void handle(NewRegistrant registrant) {
System.out.println(registrant.info());
}
})
.on(RegistrationStep.USER_EXISTS, new FlexibleHandler() {
void handle(NewRegistrant registrant, UserContainer existingUser) {
System.out.println(registrant.info());
System.out.println(existingUser.info());
@UnquietCode
UnquietCode / RedisResource.java
Last active December 19, 2015 09:49
TryWithResource, because sometimes you don't have Java7, and even if you do the actual try-with-resource is somewhat clunky.
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class RedisResource extends TryWithResource<Jedis> {
private final JedisPool pool;
public RedisResource(JedisPool pool) {
this.pool = pool;
}
@UnquietCode
UnquietCode / ContextAware.java
Last active December 19, 2015 03:29
An encapsulation of the State Pattern in Java (http://en.wikipedia.org/wiki/State_pattern)
public interface ContextAware<T> {
void beforeMethod(AtomicReference<T> context);
}
@UnquietCode
UnquietCode / MockSQS.java
Last active October 1, 2022 04:00
Mock AWS SQS implementation which operatesin-memory rather than hitting the real SQS.
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.ResponseMetadata;
import com.amazonaws.regions.Region;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.*;
import com.google.common.hash.Hashing;
import java.util.*;
@UnquietCode
UnquietCode / RecyclingObjectPool.java
Created June 5, 2013 21:51
Object pool which reclaims resources not from the user but rather from the garbage collector.
package com.studyblue.utils.pool;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
@UnquietCode
UnquietCode / JSInvocable.java
Last active May 20, 2020 11:01
Code for running moment.js under Java using the Rhino script engine. https://github.com/timrwood/moment/
public class JSInvocable {
private final Invocable invocable;
private final Object object;
private JSInvocable(Invocable invocable, Object object) {
this.invocable = invocable;
this.object = object;
}
public String invoke(String method, Object...args) {
@UnquietCode
UnquietCode / GroovyCLI.groovy
Last active July 13, 2018 06:52
A simple command line utility template for Groovy. Functionality can be implemented by declaring new methods of the form "_doXYZ" where XYZ is the name of the command to run.
/**
* Base class for command line applications.
*
* Children can provide functionality in the form of
* <command name> <arguments...>
*
* @author Ben Fagin
*/
class GroovyCLI implements Runnable {
private String[] args;
@UnquietCode
UnquietCode / lessjs.rb
Created December 10, 2012 07:41 — forked from adunkman/lessjs.rb
Jekyll plugin to render LESS (lesscss.org) files during generation.
module Jekyll
class LessCssFile < StaticFile
def write(dest)
# do nothing
end
end
class LessJsGenerator < Generator
safe true
@UnquietCode
UnquietCode / bookmarklet.txt
Created September 23, 2012 08:57
StrangeLoop schedule helper
javascript:(function()%7B(function%20()%20%7Bvar%20jsCode%20%3D%20document.createElement('script')%3BjsCode.setAttribute('src'%2C%20'https%3A%2F%2Fraw.github.com%2Fgist%2F3769415%2Fslcal.js')%3Bdocument.body.appendChild(jsCode)%3B%7D())%7D)()