Skip to content

Instantly share code, notes, and snippets.

View weefbellington's full-sized avatar

David Stemmer weefbellington

  • Lyft
  • San Francisco
View GitHub Profile
@weefbellington
weefbellington / ReplayTest.java
Created August 2, 2016 02:07
replay(1).refcount() test
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import rx.Observable;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
public class ReplayTest {
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.functions.Func3;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
/**
package com.dramafever.android.lib.rxjava;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Action1;
@weefbellington
weefbellington / bubblesort.hs
Created October 4, 2015 18:41
Stupid haskell bubblesort
import Debug.Trace
main :: IO()
main = do
let sorted = bubbleSort [6, 5, 3, 1, 8, 7, 2, 4] :: [Integer]
print sorted
bubbleSort :: (Ord a, Show a) => [a] -> [a]
--bubbleSort lst | trace ("sorting: " ++ show lst) False = undefined
bubbleSort [] = []
@weefbellington
weefbellington / mergesort.hs
Last active July 12, 2018 02:37
mergesort implementation for learning Haskell
import Debug.Trace
main :: IO()
main = do
let sorted = mergeSort [6, 5, 3, 1, 8, 7, 2, 4]
print sorted
mergeSort :: (Ord a, Show a) => [a] -> [a]
-- mergeSort lst | trace ("sorting: " ++ show lst) False = undefined
mergeSort [] = []
@weefbellington
weefbellington / stupid_letter_counter.hs
Last active September 18, 2015 13:17
stupid Haskell letter counter
import Data.Char
import Debug.Trace
import System.IO
main :: IO()
main = do
hSetBuffering stdin NoBuffering
putStrLn "Sample: counting words with a given letter"
putStrLn "Input letter to count:"
letter <- getChar
public class DataBindingComponent<DataType> implements Scene.Component {
private final Bindable target;
private final Data data;
public DataBindingComponent(Data data, Bindable<DataType> target) {
this.data = data;
this.target = target;
}
@weefbellington
weefbellington / higher-order.hs
Created August 1, 2014 03:45
higher-order functions (sliding window)
windowMap :: ( a -> a -> b) -> [a] -> [b]
windowMap func list =
let zipped = zip list (tail list)
in map (uncurry func) zipped
windowScan :: (b -> a -> a -> b) -> b -> [a] -> [b]
windowScan func accumulator list =
let zipped = zip list (tail list)
func' = \ acc -> uncurry (func acc)
in scanl func' accumulator zipped
@weefbellington
weefbellington / ParallelPromises.java
Created July 25, 2014 19:10
parallel promises example
Promise<ResponseTypeA> responseA;
Promise<ResponseTypeB> responseB;
p1.then(new PromiseAction<A>() {
public void call(A response) {
// do something with the response
}
});
p2.then(new PromiseAction<B>() {
@weefbellington
weefbellington / zipsample.java
Created July 25, 2014 18:54
rxjava zip example
Action1 onNext = new Action1<R>() {
@Override
public void call(R composedResult) {
//do something
}
};
Observable.zip(observable1, observable2,
new Func2<T1, T2, R) {
@Override