Skip to content

Instantly share code, notes, and snippets.

@rchatley
rchatley / books.py
Created January 25, 2024 12:45
Some sample data about books
books = [
{
'id': 1,
'title': 'To Kill a Mockingbird',
'author': 'Harper Lee',
'publication_year': 1960,
'genre': 'Southern Gothic'
},
{
'id': 2,
@rchatley
rchatley / build.yml
Created December 18, 2022 13:36
build.yml for Fly deployment
on: [ push ]
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@rchatley
rchatley / encoders.py
Created April 5, 2022 14:06
LineEncoders
import abc
class LineEncoder:
def __init__(self, algorithm):
self.algorithm = algorithm
def encode(self, text):
words = text.split(" ")
@rchatley
rchatley / HeadChef.java
Last active April 5, 2022 10:02
HeadChef (mocks)
package restaurant;
public class HeadChef {
private final Chef pastryChef;
private final Waiter waiter;
public HeadChef(Chef pastryChef, Waiter waiter) {
this.pastryChef = pastryChef;
this.waiter = waiter;
}
package com.iteratrlearning.collections.examples._4_sets;
import com.iteratrlearning.collections.examples.ProductFixtures;
import org.junit.Test;
import static com.iteratrlearning.collections.examples.ProductFixtures.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
public class ProductCatalogueTest {
@rchatley
rchatley / CollectionExamples.java
Created October 26, 2021 08:52
IterableAndCollection
package com.iteratrlearning.collections.examples._1_what_are_collections;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
public class CollectionExamples {
public static void main(String[] args) {
object PigLatin {
fun translate(phrase: String): String = phrase.split(" ").joinToString(" ", transform = ::translateWord)
private fun translateWord(word: String): String =
when {
word.startsWith(vowel) -> word + "ay"
word.startsWith("xr") -> word + "ay"
word.startsWith("yt") -> word + "ay"
word.startsWith("ch") -> word.drop(2) + "chay"
from unittest.mock import Mock
from order import Order
ROAST_CHICKEN = Order("roast chicken")
APPLE_TART = Order("apple tart")
class HeadChef:
def __init__(self, pastrychef, waiter):
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.fail;
public class WimbledonScoreCalcTest {
private WimbledonScoreCalc scoreCalc= new WimbledonScoreCalc();