Skip to content

Instantly share code, notes, and snippets.

View JonNorman's full-sized avatar

Jon Norman JonNorman

View GitHub Profile
@JonNorman
JonNorman / norman_family_quiz.md
Last active December 21, 2020 14:15
Quiz Time Hnnnhnhnnnnn
@JonNorman
JonNorman / GroupTask.scala
Created June 5, 2020 17:30
Grouping Sublists
import org.scalatest.FlatSpec
object GroupTask {
/**
* A function that can group a list of any type into sub-lists according to some condition.
*
* Because of the way we can pattern match on `List`s and extract their values via the "cons" operator - :: - we
* can build up our List of Lists as we go, adding a new list to the front whenever we find that the current element
* cannot be added to the current list.
@JonNorman
JonNorman / fake-artist-rules-explanation.md
Last active April 1, 2020 15:42
An explanation of the rules of fake-artist

Fake artist

Play here https://fake-artist.herokuapp.com/.

Aim of the game

In each round there will one player randomly selected as the "fake artist".

  • If you are not the fake artist, your objective is to correctly identify the player that is the fake artist.
  • If you are the fake artist, your objective is to avoid being identified as the fake artist! However, if you are identified at then you still have one last chance to win (this is explained below).

How it works

@JonNorman
JonNorman / Snowflake Worksheet example
Created October 14, 2019 15:58
Example Snowflake worksheet for ingesting data from an external S3 bucket.
-- following instructions in https://docs.snowflake.net/manuals/user-guide/data-load-s3-config.html
use role ACCOUNTADMIN;
CREATE STORAGE INTEGRATION poc_data_s3_integration
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = S3
ENABLED = TRUE
STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::021353022223:role/ophan-snowflake-bucket-role'
STORAGE_ALLOWED_LOCATIONS = ('s3://ophan-snowflake-data/');
@JonNorman
JonNorman / FutureTest.scala
Created August 27, 2019 08:18
A future exploring the nature of recursive flatMap calls on a Future.
object FutureTest extends App {
import scala.concurrent.{ExecutionContext, Future}
import java.util.concurrent.{ConcurrentLinkedQueue, Executors}
implicit val executionContext = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(8))
val fs = List(10, 9)
val log = new ConcurrentLinkedQueue[String]()
@JonNorman
JonNorman / CustomBackfill.scala
Last active March 18, 2019 10:57
Useful script for running backfills on specific tables/data/dates
package com.gu.emr
import java.time.LocalDate
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.ec2.model.InstanceType
import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceAsyncClientBuilder
import com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig
import com.gu.datalake.aws.LatestAWSSpotPricing
import com.gu.emr.model.ClusterDefinition.EC2SubnetID
@JonNorman
JonNorman / week-10-exercises.md
Last active December 10, 2018 17:06
week-10-exercises

Write an App that attempts to do the following tasks, and run it a few times. Each task should handle the case where the Future fails, as well as if it doesn't give back what you would expect.

  1. Get a Song from the SongAPI by name or artist and print it out.

  2. Put a Song into the SongAPI, then get it in a subsequent call to the SongAPI.

  3. Try adding a method to SongAPI def removeSong(name: String, artist: String): Future[Boolean]to remove a song from the catalogue. The Future[Boolean] should be true if the song was in there and deleted and false if the song wasn't there.

@JonNorman
JonNorman / week-8-exercises.md
Last active November 26, 2018 16:11
Exercises for playing with parameterised types

Paramtereised types (exercises)

For each of these exercises, try to write a test to ensure that it is producing what you expect it to do.

Part I

  1. Write a function called length that takes a list of any type and returns the number of elements in that list.

  2. Write the body for a function called head that takes a list of any type and returns the first element of it.

  3. Write a function called map that takes a list of any type A, a function that goes from that type to another type B and returns a list of type B.

@JonNorman
JonNorman / week7-recap.md
Last active November 22, 2018 15:41
A recap of week 7 scala school: projects, SBT and tests

Scala projects, SBT and Scala Test

Writing Scala isn't much good unless you can run it i.e. run it locally on demand, deploy as a lambda, run as a server etc. etc. So far in scala school we've looked at a lot of the Scala language features and concepts but that isn't that useful if we can't actually run our programs.

So how we can go from just writing Scala source code to actually executing and testing it? For starters, we need to build our source code.

Scala projects and SBT

What does it mean to "build" our source code?

TL;DR: creating executable artefacts from our source code

@JonNorman
JonNorman / week6-recap-functions.scala
Last active November 12, 2018 15:33
A recap of some of the concepts covered in week6 - predominantly how to read and write function definitions.
/**
* Functions!
*
* We've had some practice in writing our own functions, but let's go back to basics and go
* through what they are and how we can write them.
*
* Feel free to skip to the TL;DR at the bottom...
*
* So, what is a function?
*