Skip to content

Instantly share code, notes, and snippets.

View thobson's full-sized avatar

Toby Hobson thobson

View GitHub Profile
import { Entity } from "electrodb";
import { client, table } from "../client";
export const UserEntity = new Entity(
{
model: {
version: "1",
entity: "user",
service: "default",
},
# Error
➜ ~ brew upgrade
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from e98a91378 to 4c8fe984c.
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
dasel
Error: undefined method `ohai_stdout_or_stderr' for #<ReporterHub:0x00007fd88a968308>
Please report this issue:
@thobson
thobson / StreamingPoc.scala
Created December 13, 2019 16:45
Monix vs fs2
package com.example
import java.text.NumberFormat
import java.time.Instant
import cats.effect.{IO, Sync, Timer}
import fs2.{Chunk, Stream}
import monix.eval.Task
import monix.execution.Scheduler
import monix.reactive.Observable
class TableManager[F[_]](guard: Semaphore[F],)(implicit F: Sync[F], TableOps: TableOps[F]) {
// this feels hacky
private val state = mutable.Map.empty[String, Table]
def tableFor(name: String, createIfMissing: Boolean): F[Table] = guard.withPermit {
state.get(name) match {
case Some(table) => table.pure[F]
case None => for {
newTable <- TableOps.open(buildPath(name), createIfMissing)
implicit val vehicleLikeTank = new VehicleLike[Tank] {
def drive: String = "driving a big big tank"
}
val tank = Tank(...)
val drivenTank: Tank = Dealership.driveAndReturn(tank)
import Vehicles._ // import car and bus implementations
val ford = Car("ford")
Dealership.driveAndReturn(ford) // vehicleLikeCar is already in scope due to the import
trait VehicleLike[A] {
def drive(a: A): String
}
object Vehicles {
implicit val vehicleLikeCar = ...
implicit val vehicleLikeBus = ...
}
object Dealership {
val ford: Car = Car("ford")
// still a Car
val drivenFord: Car = driveAndReturn(ford)
implicit val vehicleLikeCar = ...
implicit val vehicleLikeBus = ...
def driveAndReturn[A](vehicle: A)(implicit vehicleLike: VehicleLike[A]): A = {
println(vehicleLike.drive(vehicle)); vehicle
}
val ford = Car("ford")
val londonBus = Bus("red")
println(vehicleLikeCar.drive(ford))
println(vehicleLikeBus.drive(londonBus))