Skip to content

Instantly share code, notes, and snippets.

@andrewrlee
andrewrlee / Instantiator.java
Created April 24, 2016 21:16
instantiate class by constructor args. (Derive constructor based on arg types)
/**
* Highly influenced by: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.*;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MockitoSpyTest {
@andrewrlee
andrewrlee / git-status.sh
Last active August 29, 2015 14:17
Trash script for showing git status in recursive directories
#!/usr/bin/ruby
dirty = ARGV.include? "-d"
change_dir = ARGV.include? "-cd"
search = ARGV.find{|x| ! x.start_with? "-"}
repos = Dir.glob("/home/alee/workspaces/**/.git/").collect()
class String
def brown; "\033[33m#{self.strip! || self}\033[0m" end
@andrewrlee
andrewrlee / index.md
Last active August 29, 2015 14:17
Jave 8 streaming with index
	public static <T> Function<T, IndexedItem<T>> indexed() {
		AtomicInteger count = new AtomicInteger();
		return (t) -> new IndexedItem<T>(count.getAndIncrement(), t);
	}

	public static class IndexedItem<T> {
		public final Integer index;
		public final T item;
(ns diamond.core
(:gen-class))
(defn letter-index [char] (- (+ 1 (int char)) (int \a)))
(def letter-seq (map char (range (int \a) (+ 1 (int \z)))))
(defn format-line [[char indent inner-space]]
(let [whitespace (fn [i] (apply str (repeat i " ")))
last-char (if (not= char \a) char "")]
@andrewrlee
andrewrlee / core.clj
Created March 1, 2015 17:28
Sample clojure thrift client
(ns test-client.core
(:gen-class)
(:require [thrift-clj.core :as thrift]
[environ.core :refer [env]]))
(thrift/import
(:types [github.thrift.mongo.core.api Commit]
[github.thrift.mongo.core.api Push])
(:clients github.thrift.mongo.core.api.PushService))
@andrewrlee
andrewrlee / release.sh
Created February 24, 2015 18:53
Creating .deb for a lein project with fpm
#/bin/bash
NAME="thrift-server"
VERSION="0.1.0"
LOCATION="/opt/$NAME"
JAR_NAME="server-0.1.0-SNAPSHOT-standalone.jar"
DEB_NAME="${NAME}_${VERSION}_amd64.deb"
lein clean && lein uberjar;
@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) {
@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 / 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 )))