Skip to content

Instantly share code, notes, and snippets.

View cer's full-sized avatar

Chris Richardson cer

View GitHub Profile
@cer
cer / gist:5397346
Last active December 16, 2015 07:18
Using Scala Futures to reimplement the Java Future examples used to provide the motivation for Netflix RxJava - https://gist.github.com/benjchristensen/4671081#file-futuresb-java-L163 - in the announcement: http://techblog.netflix.com/2013/02/rxjava-netflix-api.html The code compares quite nicely with RxJava
@RunWith(classOf[JUnitRunner])
class Example1Test extends FunSuite with ShouldMatchers {
// Services that return Futures
def serviceA() = Future { 7 }
def serviceC(x : Int) = Future { 2 * x }
def serviceB() = Future { 9}
def serviceD(x : Int) = Future { 5 * x}
def serviceE(x : Int) = Future { 4 * x}
@cer
cer / VideoGridTest.scala
Created April 18, 2013 21:43
A scala Future version of the Netflix video grid example ( http://techblog.netflix.com/2013/02/rxjava-netflix-api.html ) that was written using RxJava.
@RunWith(classOf[JUnitRunner])
class VideoGridTest extends FunSuite with ShouldMatchers {
// Make scalaz work with futures
implicit object FutureFunctor extends Functor[Future] {
def fmap[A, B](r : Future[A], f : scala.Function1[A, B]) : Future[B] = r.map(f)
}
implicit object FutureApply extends Apply[Future] {
@cer
cer / both-ways.js
Created October 31, 2013 23:42
An example of a function that returns a promise and takes a callback
var when = require("when");
function makePromiseCallback(label, callback) {
var deferred = when.defer();
function actualCallback(err, data) {
if (err)
console.log(label || "some label", {err: err, data: data});
if (err)
deferred.reject(err);
package net.chrisrichardson.microservices.restfulspringboot
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
import org.springframework.context.annotation._
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import net.chrisrichardson.microservices.restfulspringboot.backend.ScalaObjectMapper
import net.chrisrichardson.microservices.restfulspringboot.dustview.DustViewResolver
import org.springframework.web.client.{ResponseErrorHandler, RestTemplate}
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import scala.collection.JavaConversions._
val children = Set("a", "b", "c")
var knownChildren = Map[String, String]()
val newChildren = Map[String, String]()
for (i <- 1 to 1000*1000) {
if (i % 1000 == 0) println(knownChildren.size)
knownChildren = knownChildren.filterKeys(children.contains) ++ newChildren
}
When files are uploaded to CrashPlan, a checksum is generated for the file, but is not verified immediately upon receipt.
These checksum values are logged and checked when archive maintenance is performed on the archive, every 7 days.
If CrashPlan were to verify the checksum for each file upon receipt, this would cause each file's upload to take considerably more time to complete, relatively speaking.
Plus, if the drive that the source data was being backed up from was failing, this could potentially cause the drive to fail much more quickly, as there would be a great deal more disk I/O, caused by the file block verification occurring on a per-file basis, while being backed up.
By default, CrashPlan gathers the data that has been collected by a process known as a file verification scan on a daily basis, and then uses this file block information to analyze the files that exist in the backup archive.
If CrashPlan runs into any files that do not match the checksum, it attempts to self-heal the archive, usually
package net.chrisrichardson.getataxi.dispatcher.services;
import net.chrisrichardson.getataxi.dispatcher.domain.DispatcherDriver;
import net.chrisrichardson.getataxi.dispatcher.domain.DriverMother;
import net.chrisrichardson.getataxi.dispatcher.domain.DriverRepository;
import net.chrisrichardson.getataxi.domain.Location;
import net.chrisrichardson.getataxi.domain.events.DriverAcceptedTripEvent;
import net.chrisrichardson.getataxi.domain.events.TripCreatedEvent;
import net.chrisrichardson.getataxi.domain.events.TripOfferedToDriver;
@cer
cer / pom.xml
Created February 22, 2017 13:49
Eventuate Local pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.eventuate.examples.mavenexample</groupId>
<version>0.1.0-SNAPSHOT</version>
<artifactId>Maven-Example</artifactId>
<packaging>jar</packaging>
<name>maven example</name>
<repositories>
<repository>
@cer
cer / DefaultController.java
Last active January 14, 2023 18:17
Spring Webflux-based proxying controller
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.reactive.function.client.WebClient;
#! /bin/bash -e
grep eventuate gradle.properties
fixVersion() {
name=${1?}
version=${2?}
sed -i "" -e "s/${name}=.*/${name}=${version}/" gradle.properties
}