Skip to content

Instantly share code, notes, and snippets.

Steve Ash steveash

Block or report user

Report or block steveash

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@steveash
steveash / Orderings.cs
Created Nov 21, 2016
Generate all total orderings of (a) an unordered set of events with (b) an ordered list of events.
View Orderings.cs
public static IEnumerable<List<T>> AllOrderings<T>(List<T> unordered, List<T> ordered)
{
if (unordered.Count == 0)
{
yield return ordered;
}
else
{
foreach (var permutation in GetPermutations(unordered, unordered.Count))
{
@steveash
steveash / gist:3da817c58b47d324d074dfe0227d475b
Created Nov 5, 2016
c++11 quick reminder on lvalue/rvalue and move vs copy
View gist:3da817c58b47d324d074dfe0227d475b
// given a temp object like this:
class Temp
{
public:
Temp() : idx(0), good(true)
{
AL_INFO << "Temp zero-argo ctor " << idx;
}
@steveash
steveash / PreshingRandomSequence.java
Last active Apr 12, 2019
Pseudo-random generator that doesn't repeat integers
View PreshingRandomSequence.java
import java.util.Random;
/**
* Generates a sequence of pseudo-random numbers such that they never repeat. Can handle sequence sizes up to
* length Int.MAX_VALUE. Will throw exceptions if you ask for more than that; maps the entire [0, Integer.MAX_VALUE]
* range onto itself but in a random order
* <link>http://preshing.com/20121224/how-to-generate-a-sequence-of-unique-random-integers/</link>
*/
public class PreshingRandomSequence {
public static final int MAX_INT_PRIME = 2147483587;
@steveash
steveash / StreamStats.java
Created Aug 6, 2015
Class to do streaming count, mean, standard deviation allows replacements of particular values from the data population
View StreamStats.java
/**
* Class that allows for streaming collection of count, mean, stddev
* Allows combining multiple independent instances
* Allows _replacement_ of values in the stream (i.e. if one of the values of your data population changes
* you can replace it). Replacing values introduces some tiny error, but in testing that error is < 1e-9 even
* in extreme conditions.
*/
public class StreamStats {
private long count = 0;
@steveash
steveash / 00_input.conf
Last active Jun 18, 2019
ELK configuration for aggregating cassandra and spark logs
View 00_input.conf
input {
lumberjack {
# The port to listen on
port => 5043
# The paths to your ssl cert and key
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder/logstash-forwarder.key"
# default type, but this will already be set by logstash-forwarder anyways
@steveash
steveash / brainfuck.java
Created Dec 12, 2014
Simple Brainfuck interpreter for a friend
View brainfuck.java
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Brainfuck {
public static void main(String[] args) throws IOException {
int maxTapeSize = 10000;
@steveash
steveash / gist:9879696
Created Mar 30, 2014
Sample ehcache manager bean factory
View gist:9879696
@org.springframework.context.annotation.Configuration
public class CacheBeans {
private static final AtomicInteger cacheCounter = new AtomicInteger(0);
@Bean
public EhCacheManagerFactoryBean ecmfb() {
EhCacheManagerFactoryBean ecmfb = new EhCacheManagerFactoryBean();
// cannot share the cache managers
ecmfb.setShared(false);
@steveash
steveash / PrepareAspectJTestExecutionListener.java
Last active Aug 29, 2015
PrepareAspectJTestExecutionListener resets the AnnotationTransactionAspect to point to the correct bean factory and platform transaction manager before execution
View PrepareAspectJTestExecutionListener.java
package com.github.steveash.gist;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.aspectj.AnnotationTransactionAspect;
/**
* Test Execution Listener that resets the references to the Annotation Transaction Aspect's
@steveash
steveash / OptimalStringAlignment.java
Last active Mar 29, 2019
This is an implementation of Optimal String Alignment in Java with some tricks and optimizations. OSA is similar to Damerau–Levenshtein edit distance in that insertions, deletions, substitutions, and transpositions of adjacent are all treated as one edit operation. This OSA implementation also takes a "max edit" threshold, which allows you to sk…
View OptimalStringAlignment.java
package com.github.steveash.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.primitives.Shorts.checkedCast;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import java.util.Arrays;
You can’t perform that action at this time.