Skip to content

Instantly share code, notes, and snippets.

# Create a boto3 session by assuming a role
import boto3
import uuid
def create_session(role_arn):
client = boto3.client('sts')
response = client.assume_role(
RoleArn=role_arn,
@kenoir
kenoir / game_of_life.scala
Last active August 29, 2019 16:52
Game of Life in Scala
val length = 10
val breadth = 10
type Loc = (Int, Int)
type Grid = Map[Loc, Cell]
case class Cell(i: Loc)
class World(xlim: Int, ylim: Int)(grid: Grid = Map.empty) {
trait Reader[T] {
def read(t: T): String
}
sealed trait MakesSound {
val doesTalk: Boolean
}
case class Dog(doesTalk: Boolean) extends MakesSound
case class Frog(doesTalk: Boolean) extends MakesSound
# Based on https://www.ncbi.nlm.nih.gov/pubmed/30850328
import datetime
from random import choices
withdrawal_percentage_per_week = 5
starting_dosage_in_milligrams = 200
minimum_reduction_in_milligrams = 25
dosage_reduction_population = [minimum_reduction_in_milligrams, 0]
import java.time.Instant
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException
import com.gu.scanamo.error.{ConditionNotMet, ScanamoError}
import com.gu.scanamo.ops.ScanamoOps
import com.gu.scanamo.query.{KeyEquals, UniqueKey}
import com.gu.scanamo.syntax.{attributeExists, not}
import com.gu.scanamo.{DynamoFormat, Scanamo, Table}
import grizzled.slf4j.Logging
Service Modes
- Operational
- Transient
- Catastrophic
trait LockingService[IdentF[_], OutT[_], Ident, Out] {
import cats.implicits._
sealed trait LockProcess
case class FailedLock(id: Ident, e: Throwable) extends LockProcess
case class FailedUnlock(id: Ident, e: Throwable) extends LockProcess
type Lock = Validated[FailedLock, Unit]
type Unlock = Validated[FailedLock, Unit]
import uk.ac.wellcome.platform.archive.common.bagit.models.{BagDigestFile, BagItemPath}
import uk.ac.wellcome.platform.archive.common.storage.models.ChecksumAlgorithm
case class FileManifest(
algorithm: ChecksumAlgorithm,
files: List[BagDigestFile]
)
object FileManifestUpdate {
import scala.concurrent.Future
sealed trait Result[Id] {
val id: Id
}
trait Completed[Id] extends Result[Id]
trait Retry[Id] extends Result[Id]