Skip to content

Instantly share code, notes, and snippets.

View robfletcher's full-sized avatar

Rob Fletcher robfletcher

View GitHub Profile
@robfletcher
robfletcher / Event.scala
Created September 15, 2015 01:06
Using companion object apply method from outside of Scala
package example
import java.time._
case class Event(description: String, time: Option[ZonedDateTime])
object Event {
def apply(description: String) = new Event(description, None)
def apply(description: String, time: ZonedDateTime) = new Event(description, Some(time))
}
@robfletcher
robfletcher / gist:fb3546d248bf0398d741
Created March 17, 2015 18:53
Test for backpressure when using Observable.interval
@Grab("io.reactivex:rxjava:1.0.8")
import rx.*
import static java.util.concurrent.TimeUnit.*
import static java.time.LocalTime.*
def sub = Observable.interval(1, SECONDS)
.doOnNext { tick->
println "tick $tick at ${now()}"
}
.subscribe { tick ->
@robfletcher
robfletcher / gist:b596b90d651370da281c
Created December 12, 2014 22:13
Using Groovy inject to iteratively add things to a fluent builder
JobParameters fromMap(Map<String, String> parameters) {
parameters.inject(new JobParametersBuilder()) { JobParametersBuilder builder, entry ->
builder.addParameter(entry.key, new JobParameter(entry.value))
} toJobParameters()
}
@robfletcher
robfletcher / gist:44b115286fd9ef9c8a8c
Last active August 29, 2015 14:11
Difference in static & dynamic code dispatching to field or getter
import groovy.transform.*
//@CompileStatic
class Person {
String name
private List<Person> friends
String friendNames() {
friends.collect { it.name }.join(", ")
}
def "subscriber receives message"() {
given: "An async event bus"
def eventBus = new AsyncEventBus(Executors.newCachedThreadPool())
and: "A Fake Service"
def vars = new BlockingVariables()
def fakeService = Stub(FictionalService) {
process(_) >> { PersonMessage message -> vars.message = message }
}
@robfletcher
robfletcher / build.gradle
Created October 29, 2014 23:51
Example of trying to execute a script from a gem using JRubyExec
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.github.jruby-gradle:jruby-gradle-plugin:0.1.3+"
}
}
@robfletcher
robfletcher / gist:5d9c79aec1c7bb694517
Last active August 29, 2015 14:05
Is this supposed to be able to compile?
import groovy.transform.*
@CompileStatic
class A {
private final String name
A(String name) {
this.name = name
}
}
@robfletcher
robfletcher / gist:6c049a4c807cedc0e844
Last active August 29, 2015 14:03
This is a list of smaller, lesser-known libraries that I've used and vouch for. It has bookmark value for me as much as anything but I'm keeping it here in the hope someone might find it useful.

Libraries

JVM

Strongly-typed Java interfaces for REST endpoints. Supports returning RxJava Observables. Similar to Feign which is by Netflix but doesn’t support Rx.

@robfletcher
robfletcher / TumblrToMiddleman.groovy
Last active November 5, 2019 14:15
Scrape markdown posts from a Tumblr blog and export for Middleman
/*
* This script will scrape text posts from a Tumblr blog and export them as `.md`
* files with YAML frontmatter ready to be used in a Middleman blog.
*
* Aliases are added for the _middleman-alias_ gem so Tumblr style URLs like
* `/post/{id}/{slug}` will redirect to the Middleman-style URL.
*
* Although I built this for migrating to Middleman it should be pretty easy to
* adapt this for any similar static site generator.
*/

Keybase proof

I hereby claim:

  • I am robfletcher on github.
  • I am robfletcher (https://keybase.io/robfletcher) on keybase.
  • I have a public key whose fingerprint is B0DA 4426 D1D5 1AF0 2D93 F480 9376 AE14 4362 B58E

To claim this, I am signing this object: