Skip to content

Instantly share code, notes, and snippets.

View UnquietCode's full-sized avatar

Benjamin Fagin UnquietCode

View GitHub Profile
@UnquietCode
UnquietCode / A.js
Last active August 29, 2015 14:07
gulp-browatchify test
var B = require('./B');
console.log("hello");
@UnquietCode
UnquietCode / SimpleStateTraverser.java
Created August 9, 2012 04:10
A simple traverser which handles recursive computations, specifically those where it is required to be aware of the previous, current, and next states.
/*******************************************************************************
Copyright 2012 Benjamin Fagin
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
@UnquietCode
UnquietCode / NestedClassesExample.java
Created August 24, 2012 15:55
Simulating multiple inheritance in Java.
public class NestedClassesExample {
public static void main(String args[]) {
Child child = new Child();
child.print();
}
public static class ParentA {
public void printA() {
@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)()
@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 / 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 / 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 / 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 / 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 / API.java
Created November 14, 2013 19:49
Keep track of your API in your code. This also allows you to easily identify places in your application where legacy blocks ('hacks') can be removed.
public enum API {
@Deprecated Version1,
Version2(
add(Feature.BLUE_ICONS)
),
Version3(
parent(Version2),