Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@benjchristensen
benjchristensen / SampleExample.java
Last active August 29, 2015 14:04
SampleExample
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
public class SampleExample {
public static void main(String args[]) {
hotStream().sample(500, TimeUnit.MILLISECONDS).toBlocking().forEach(System.out::println);
@benjchristensen
benjchristensen / ThrottleExample.java
Last active August 29, 2015 14:04
ThrottleExample
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
public class ThrottleExample {
public static void main(String args[]) {
// first item emitted in each time window
@benjchristensen
benjchristensen / ReactivePullCold.java
Created August 4, 2014 16:56
ReactivePull Iterable Example
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
/**
* Example of a "cold Observable" using "reactive pull" to emit only as many items as requested by Subscriber.
@benjchristensen
benjchristensen / ReactivePullColdNonConformant.java
Created August 4, 2014 16:57
Handling an Observable Iterable without Reactive Pull using onBackpressureBuffer
import java.util.ArrayList;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
/**
* This demonstrates a "cold" Observable that does not use "reactive pull" and how to handle it.
*/
public class ReactivePullColdNonConformant {
@benjchristensen
benjchristensen / MulticastColdFiniteBackpressureExample.java
Created August 4, 2014 17:20
Multicasting a cold, finite Observable and using onBackpressureBuffer/Drop to handle overflow
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;
import rx.Observable;
import rx.Subscriber;
import rx.observables.ConnectableObservable;
import rx.schedulers.Schedulers;
@benjchristensen
benjchristensen / MulticastColdInfiniteBackpressureExample
Created August 4, 2014 17:24
Multicasting a cold, infinite Observable and using onBackpressureBuffer/Drop to handle overflow
import java.util.concurrent.CountDownLatch;
import rx.Observable;
import rx.observables.ConnectableObservable;
import rx.schedulers.Schedulers;
/**
* This shows how a "reactive pull" compliant "cold" Observable, when multicasted, becomes "hot" and each Subscriber
* must then choose its strategy for overflow.
*/
<?php
header("Content-Type: text/event-stream\n\n");
echo 'data: ' . json_encode(
array(
0 => array(
'time' => time(),
'message' => 'Some kind of foo'
),
1 => array(
@benjchristensen
benjchristensen / index.html
Created August 18, 2011 04:18
DIV Popup with "Lightbox" Style
<html>
<head>
<title>DIV Popup with "Lightbox" Style</title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<style>
/* popup div contents */
DIV.lightbox-content {
position: absolute;
margin-right: auto;
margin-left: 5%;
@benjchristensen
benjchristensen / gist:1284836
Created October 13, 2011 17:14
Shell script with command line arguments
#!/usr/bin/env python
import subprocess
import argparse
import zipfile
import os
parser = argparse.ArgumentParser(description='Upload a file or files to a RESTful endpoint')
parser.add_argument('-e', '--environment', metavar='TEST/PROD',
help='The environment to upload to: TEST/PROD')
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.TestCase;
import org.junit.Test;