Skip to content

Instantly share code, notes, and snippets.

Richard Ashworth richashworth

View GitHub Profile
richashworth / AWS
Last active Jan 30, 2020
Revision Notes for AWS Developer Exam
View AWS

AWS Notes

Exam tips {#Exam tips}

  • Memorize formulae for WCU and RCU from DynamoDB
  • AZs end in letters; Regions end in numbers

EC2 {#EC2}

richashworth /
Created Mar 30, 2019
Trigger execution of Kotlin scripts on save (useful for approximating worksheets).
fswatch -0 . | xargs -0 -n 1 -I {} sh -c "clear; echo '\033[0;32mRunning {}\033[0;37m'; echo; kscript {} ; echo;"
richashworth / Using Google Sheets
Last active Dec 1, 2018
Using the Google Sheets API
View Using Google Sheets

Set up credentials in the Developer Console using OAuth2 and a Service Account:

  1. Create a Project in the Google developer console:
  2. Enable the Google Sheets API for that project:
  3. Create credentials for a Web Server to access Application Data
  4. Create a Service Account; name it and grant it a Project role of Editor
  5. Download the credentials as client_secret.json
  6. Share the spreadsheet(s) with the email in client_secret.json

Install the Google OAuth2 and Client libraries: pip install gspread oauth2client

richashworth / Eventually.scala
Created Aug 30, 2018
Retry logic implemented with IO monad
View Eventually.scala
import cats.effect.{IO, Timer}
import cats.syntax.applicativeError._
import cats.syntax.apply._
import scala.concurrent.duration.{FiniteDuration, _}
import scala.math._
// From
def eventually[A](ioa: IO[A], initialDelay: FiniteDuration = 1.second, maxRetries: Int = 10, backOffMultiplier: Int = 1)
(implicit timer: Timer[IO]): IO[A] = {
import $ivy.`org.typelevel::cats:0.9.0`, cats.{Monoid, Show}
case class LCDDigit(firstRow: String, secondRow: String, thirdRow: String)
object LCDDigit {
implicit val ShowInstance =[LCDDigit](_.productIterator mkString "\n")
implicit val ConcatMonoid = new Monoid[LCDDigit] {
override def empty = LCDDigit("", "", "")
override def combine(l1: LCDDigit, l2: LCDDigit): LCDDigit =
import $ivy.`org.typelevel::cats:0.9.0`, cats.Semigroup
// Our domain entity
case class Company(name: String, value: Int)
// Some example data
val c1 = Company("A", 10)
val c2 = Company("B", 20)
val c3 = Company("C", 30)
val c4 = Company("D", 40)
import $ivy.`com.github.julien-truffaut::monocle-core:1.4.0`, monocle.Lens
import $ivy.`com.github.julien-truffaut::monocle-macro:1.4.0`, monocle.macros.GenLens
// _.copy fine for simple cases
case class Address(line1: String, line2: String, postcode: String)
val a = Address("221B", "Baker St", "NW1 6XE")
println(a.copy(line1 = "221A"))
View clapping.scala
abstract sealed class Beat
case object Rest extends Beat
case object Note extends Beat
case class Note(pitch: Int, duration: Int) extends Beat
case class Pattern(beats: Seq[Beat])
def formatBeat(b: Beat): String = b match {
case Rest => " _ "
case Note => " X "
View LCDDigit.scala
class LCDDigit(val firstRow: String, val secondRow: String, val thirdRow: String)
View LCDDigit.scala
case class LCDDigit(val firstRow: String, val secondRow: String, val thirdRow: String) {
def formatDigit(): Unit = {
productIterator.foreach(i => println(i))
You can’t perform that action at this time.