Skip to content

Instantly share code, notes, and snippets.

View tobyweston's full-sized avatar

Toby tobyweston

View GitHub Profile
View irrefutable

inspired by a question my colleague asked me.

Given a list of option of Ints:

val list = List(Some(1),None,Some(2))

desugar the for comprehension give us: nothing special here

@ desugar{ for { x <- list } yield x } 
res5: Desugared = ammonite.$[Option[Int], Any](((x: Option[Int]) => x))(scala.collection.immutable.List.canBuildFrom[Option[Int]])
tobyweston / gist:7784272
Created December 4, 2013 08:42
OAuth v1 example hashing
View gist:7784272
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import rtx.forest.web.PercentEncoder
import com.googlecode.utterlyidle.{RequestBuilder, Request}
object OAuth {
type ApiKey = String
type SharedSecret = String
bih / apple-university-stores.json
Last active November 19, 2023 22:36
List of Apple's UK university education stores w/ web addresses
View apple-university-stores.json
[{"region":"East Midlands","university":"De Montfort University","url":""},{"region":"East Midlands","university":"Derby University","url":""},{"region":"East Midlands","university":"Jisc Collections and Janet Limited","url":""},{"region":"East Midlands","university":"Leicester University","url":""},{"region":"East Midlands","university":"Lincoln University","url":""},{"region":"East Midlands","university":"Loughborough College","url":""},{"region":"East Midlands","university":"Loughborough University","url":""},{"region":"East Midlands","university":"Nottingham Trent University","url":""},{"region":"East Midlands","university":"Nottingham University","url":""},{"region":"East Midla
ms-tg /
Created November 11, 2013 21:14
Does JDK8's Optional class satisfy the Monad laws? Yes, it does.
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
* Yes, it does.
* ```
PaulSandoz /
Last active December 12, 2015 05:28
This is an example of Conway's Game of Life using the OpenJDK lambda Stream API. This code works with build from the tip of the lambda repository as of the 1st February 2013. Since the API is a moving this code may not compile with future builds.
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
tobyweston / gist:2841959
Created May 31, 2012 08:38
Avoid finalizer problems with JMocks SingleThreadedPolicy
View gist:2841959
public static class SingleThreadedPolicyAvoidingFinaliseProblems extends SingleThreadedPolicy {
public Invokable synchroniseAccessTo(final Invokable mockObject) {
final Invokable synchronizedMockObject = super.synchroniseAccessTo(mockObject);
return new Invokable() {
public Object invoke(Invocation invocation) throws Throwable {
if (Thread.currentThread().getName().equalsIgnoreCase("Finalizer"))
return mockObject.invoke(invocation);
return synchronizedMockObject.invoke(invocation);