Skip to content

Instantly share code, notes, and snippets.

@andrewrlee
andrewrlee / JsonSubstepsPublisher.java
Created November 13, 2012 22:00
Json Publisher for Substeps
package com.technophobia.JsonPublisher;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Comparator;
import java.util.List;
import com.google.common.collect.Ordering;
import com.google.common.collect.TreeMultimap;
@andrewrlee
andrewrlee / prime.coffee
Last active December 18, 2015 20:39
Calculating prime numbers in coffeescript
fs = require 'fs'
number = 1
result = [2]
isPrime = (number) -> [ 0..Math.sqrt number ].every (i) -> number % result[i] != 0
findPrimes = ->
number+=2
result.push number if isPrime number
@andrewrlee
andrewrlee / gist:6486801
Created September 8, 2013 17:39
Example logstash format for parsing dropwizard logback format style logging. This parses the remainder of a message that starts with _data_ as json.
input {
stdin { }
file {
type => "applogs"
# Wildcards work, here :)
path => [ "/home/alee/workspaces/java-workspaces/elasticsearch-example/graph-presenter/logs/*.log" ]
}
}
@andrewrlee
andrewrlee / gist:6663394
Created September 22, 2013 20:18
Simple Coffeescript substeps style test runner.
class Runner
constructor: (@steps) ->
_execute = (input, name, step) ->
args = step.pattern.exec input
step.method args.slice(1)...
execute : (input) -> _execute(input, name, step) for name, step of @steps \
when input.match step.pattern
@andrewrlee
andrewrlee / gist:8582940
Last active January 4, 2016 06:39
dropwizard flyway module.
import net.sourceforge.argparse4j.inf.Namespace;
import com.googlecode.flyway.core.Flyway;
import com.googlecode.flyway.core.api.MigrationInfoService;
import com.yammer.dropwizard.Bundle;
import com.yammer.dropwizard.cli.ConfiguredCommand;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Configuration;
import com.yammer.dropwizard.config.Environment;
@andrewrlee
andrewrlee / 0.) notes.md
Last active August 29, 2015 13:57
Overriding property files in spring

Overriding property files in spring

I think the trick is to just use one property place holder and I think this covers all of your scenarios:

It resolves ${full.url} in this way:

  • first default.properties gets loaded => full.url=http://prod:9090
  • then dev-test.properties overrides the hostname and port name => full.url=http://test:8080
  • then development properties overrides the hostname only => full.url=http://localhost:8080
@andrewrlee
andrewrlee / 01. Main.java
Last active August 29, 2015 13:57
Compression example
package com.learndirect.tutor;
import static com.google.common.base.Charsets.UTF_8;
import static org.apache.commons.codec.binary.Base64.decodeBase64;
import static org.apache.commons.codec.binary.Base64.encodeBase64;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Map;
@andrewrlee
andrewrlee / fizzbuzz.clj
Last active August 29, 2015 14:01
Clojure fizzbuzz
(ns fizzbuzz.core
(:gen-class))
(defn fizzbuzzify[x]
"Get fizzbuzz result for a specific number."
(cond
(zero? (mod x 15)) "fizzbuzz"
(zero? (mod x 3 )) "fizz"
(zero? (mod x 5 )) "buzz"
:else (str x )))
@andrewrlee
andrewrlee / Composite.java
Created August 3, 2014 17:42
Java Mixins with Spring AOP
package uk.co.optimisticpanda.spring.proxy;
import java.util.ArrayList;
import java.util.List;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultIntroductionAdvisor;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
@andrewrlee
andrewrlee / Main.java
Created January 24, 2015 16:38
java 8 play
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {