Skip to content

Instantly share code, notes, and snippets.

View zkendall's full-sized avatar

Zack Kendall zkendall

View GitHub Profile
@zkendall
zkendall / Writing Cheat Sheet.md
Last active August 25, 2019 01:12
Plot and Character Writing Cheat Sheet

Des-compressed from: http://www.writerscheatsheet.com/writing/

Plot

The Hero's Journey (Campbell)

  • Miraculous birth
  • Hero's ordinary home-town (peaceful, waste-land, or suburbia)
  • Dissatisfied ("I want")
  • Call to adventure
  • Refusal of call (or jumps)
@zkendall
zkendall / RetryTemplateFactory.java
Created September 7, 2016 00:46
Factory for creating a Spring RetryTemplate, primarily for use for HTTP calls such as with Spring's RestTemplate.
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
import org.springframework.retry.RetryPolicy;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
@zkendall
zkendall / RunQpidTest.java
Last active August 13, 2016 00:28
Local Qpid Attempt
package com.testing;
import com.testing.amqp.QpidRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.NamingException;
@zkendall
zkendall / VerifySpyProxyTest.java
Last active August 3, 2016 02:25
Test to demonstrate incorrect behavior when trying to verify the behavior of a spy on already proxied instance.
/*
Relevant dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
{
init: function(elevators, floors) {
log = function() { return console.log.apply(console, arguments); };
for(i = 0; i < floors.length; i++) {
var floor = floors[i];
log("Iterate Floor Num:" + floor.floorNum()) // I iterate as expected 1,2,3,4
floor.on("up_button_pressed", function() {
log("floor[" + floor.floorNum() + "].up_button_pressed()") // I am always 4, what gives?
});
@zkendall
zkendall / elevatorSaga.js
Last active February 8, 2023 14:12
Elevator Saga - The elevator programming game - My Solutions
// My Reference Docs
// http://play.elevatorsaga.com/#challenge=5
// http://play.elevatorsaga.com/documentation.html#docs
// https://www.codecademy.com/articles/glossary-javascript
// Passes through level 4
// Sometimes passes 6
// Also passes: 8, 9, 16
{
@zkendall
zkendall / ansible-dynamic-to-static.py
Last active October 9, 2018 17:23
Script to convert the output of Ansible's ec2 dynamic inventory to a flat static inventory.
#!/usr/bin/env python
'''
This script converts the output of Ansible's dynamic ec2.py to a flatly formmated static inventory file.
Before running this script run `python ./ec2.py --refresh-cache > ec2-dynamic.json`
See: http://docs.ansible.com/ansible/ec2_module.html
'''
@zkendall
zkendall / CustomItemSorter.java
Created March 9, 2015 22:53
Vaddin Container - Custom sorting by converted property
import java.util.Comparator;
import com.vaadin.data.Container.Sortable;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.util.DefaultItemSorter;
/**
* The original need for this class is to provide a way of sorting by converted values instead of only the underlying
* property values. Sometimes a property is converted to be entirely different than the underlying property, and the
@zkendall
zkendall / TableEditableBySelection.java
Last active August 29, 2015 14:09 — forked from canthony/ExampleTableEditingUI.java
This example class shows a way of editing only the selected rows in a Vaadin table. This improves rendering performance on large tables.
import java.util.Collection;
import com.vaadin.data.Container;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Table;
@SuppressWarnings("serial")
@zkendall
zkendall / directory_tree.py
Last active August 29, 2015 13:56
Print out the directory tree with indentation from a starting path.
# Taken from: http://stackoverflow.com/a/9728478/768671
import os
def list_files(startpath):
for root, dirs, files in os.walk(startpath):
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
print('{}{}/'.format(indent, os.path.basename(root)))
subindent = ' ' * 4 * (level + 1)