Skip to content

Instantly share code, notes, and snippets.

View richashworth's full-sized avatar

Richard Ashworth richashworth

View GitHub Profile
@richashworth
richashworth / spacy-setup.py
Last active September 8, 2021 23:39
spacy-setup
!pip install textblob 'spacy==3.0.0'
!python -m textblob.download_corpora
!python -m spacy download en_core_web_trf
import spacy
import en_core_web_trf
nlp = en_core_web_trf.load()
@richashworth
richashworth / ResultsWriter.java
Last active June 28, 2020 15:07
Used as Class Under Test in PowerMock Example
package com.richashworth.powermockexample;
import java.util.List;
public class ResultsWriter {
public String getDataAsString(){
StringBuilder builder = new StringBuilder();
List<String> dataList = DataProvider.getData();
for(String str: dataList){
@richashworth
richashworth / AWS Notes.md
Last active January 30, 2020 10:25
Revision Notes for AWS Developer Exam

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
richashworth / ktsrunner.sh
Created March 30, 2019 22:03
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
richashworth / ResultsWriterTest.java
Last active March 1, 2019 18:54
Unit Test used in PowerMock Example
package com.richashworth.powermockexample;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@richashworth
richashworth / Using Google Sheets API.md
Last active December 1, 2018 20:57
Using the Google Sheets API

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

  1. Create a Project in the Google developer console: https://console.developers.google.com
  2. Enable the Google Sheets API for that project: https://console.developers.google.com/apis/api/sheets.googleapis.com
  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
richashworth / Eventually.scala
Created August 30, 2018 22:40
Retry logic implemented with IO monad
import cats.effect.{IO, Timer}
import cats.syntax.applicativeError._
import cats.syntax.apply._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.{FiniteDuration, _}
import scala.math._
// From https://typelevel.org/cats-effect/datatypes/io.html#example-retrying-with-exponential-backoff
def eventually[A](ioa: IO[A], initialDelay: FiniteDuration = 1.second, maxRetries: Int = 10, backOffMultiplier: Int = 1)
(implicit timer: Timer[IO]): IO[A] = {
@richashworth
richashworth / pandoc-md-to-docx
Last active July 9, 2018 03:08
pandoc command to convert GitHub markdown (.md) to MS Word (.docx)
pandoc --to=docx -o document.docx wiki.md
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 = Show.show[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)