Skip to content

Instantly share code, notes, and snippets.

View UnquietCode's full-sized avatar

Benjamin Fagin UnquietCode

View GitHub Profile
@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 / CRUDMap.java
Created September 6, 2012 11:12
Map with simplified CRUD semantics for Java
/**
* Copyright 2012 Benjamin Fagin
* http://www.unquietcode.com
*
* 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
@UnquietCode
UnquietCode / gist:3711511
Created September 13, 2012 02:46
Extract tweet info from the basic Twitter timeline widget.
<html>
<head>
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<script type="text/javascript">
<!-- use the url that your twitter widget is using to retrieve the tweet data -->
$(function() {
$.getJSON("http://cdn.syndication.twimg.com/widgets/timelines/246079887021051904?dnt=true&domain=unquietcode.com&lang=en&callback=?", function(data) {
var tweets = $(data.body).find('li.tweet');
@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 / 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 / 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 / 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 / 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.*;