Skip to content

Instantly share code, notes, and snippets.

View jruusu's full-sized avatar

Jan Ruusuvuori jruusu

View GitHub Profile
@jruusu
jruusu / Ubiquiti UniFi controller in Docker.md
Last active October 5, 2018 09:45
Ubiquiti UniFi controller in Docker
@jruusu
jruusu / fix-docker-dns.sh
Created October 13, 2016 11:43
Set docker dns options dynamically on a Ubuntu 16.04 (systemd) host
#!/usr/bin/env bash
#
# Set docker dns options dynamically on a Ubuntu 16.04 host
#
# See:
# https://github.com/docker/docker/issues/541
# https://docs.docker.com/engine/admin/systemd/
# http://stackoverflow.com/questions/33784295/setting-dns-for-docker-daemon-on-os-with-systemd
#
set -eui
@jruusu
jruusu / BooleanToOption.scala
Last active October 4, 2016 06:40
Scala: Boolean to Option
// By extending Boolean
// See: http://docs.scala-lang.org/overviews/core/value-classes.html#extension-methods
implicit class PimpedBoolean(val self: Boolean) {
def toOption[T](x: => T): Option[T] = if (self) Some(x) else None
}
true toOption "foox" // => Some(foox)
true toOption {
println("garglex")
"foox"
@jruusu
jruusu / service_stubbing_in_rails.md
Created September 27, 2016 14:41
Service stubbing in Rails

Example: stubbing a service object in a Rails application

app/models/services/sharepoint.rb (partial):

module SharePoint

  # Live SharePoint Context class, uses OAuth2 and RestClient
  # to talk to the outside world
  class LiveContext
@jruusu
jruusu / Play24JsonFormatsWithRecursiveTypes.scala
Last active February 11, 2016 12:41
Play 2.4 Json Formats with Recursive Types
import play.api.libs.functional.syntax._
import play.api.libs.json._
case class Foo(id: String, bar: Option[Bar])
object Foo {
implicit val format = Json.format[Foo]
}
case class Bar(id: String, foos: Option[Seq[Foo]])
object Bar {

Keybase proof

I hereby claim:

  • I am jruusu on github.
  • I am jruusu (https://keybase.io/jruusu) on keybase.
  • I have a public key ASC83N5RGYbiDybp1XMjikjP_FEhruFljc-sQbVKorOrGgo

To claim this, I am signing this object:

@jruusu
jruusu / MySpec.scala
Last active February 8, 2017 11:45
Play 2.4 Specs2 Mockito mocked method answers with multiple arguments
// Play 2.4 Specs2 Mockito mocked method answers with multiple arguments
import org.specs2.matcher.ThrownExpectations
import org.specs2.mock.Mockito
import play.api.test.{FakeRequest, WithApplication, PlaySpecification}
class MySpec extends PlaySpecification {
class MySpecScope extends WithApplication with Mockito with ThrownExpectations {
val programService = mock[ProgramService]