Skip to content

Instantly share code, notes, and snippets.

View noelwelsh's full-sized avatar
💭
Hacking on Doodle when I get time

Noel Welsh noelwelsh

💭
Hacking on Doodle when I get time
View GitHub Profile
@noelwelsh
noelwelsh / loop.scala
Created October 15, 2015 16:18
Example of monadic loop using the State monad in Cats
import cats.{Id,Monad}
import cats.state.State
import cats.std.function._
import scala.language.higherKinds._
// Call Example.example.run to see the example running
object Example {
type MyState[A] = State[Int, A]
@noelwelsh
noelwelsh / Example.scala
Created February 20, 2015 16:06
Robust Error Handling in Scala
import scalaz.\/
import scalaz.syntax.either._
object Example2 {
// This example simulates error handling for a simple three tier web application
//
// The tiers are:
// - the HTTP service
// - a user authentication layer
// - a database layer
@noelwelsh
noelwelsh / minikube-err.txt
Created February 2, 2021 13:12
minikube error log
minikube : I0202 12:40:59.542903 6584 out.go:229] Setting OutFile to fd 84 ...
At line:1 char:1
+ minikube start --alsologtostderr -v=5 2>minikube-err.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (I0202 12:40:59....le to fd 84 ...:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
I0202 12:40:59.543906 6584 out.go:242] Setting ErrFile to fd 3752...
I0202 12:40:59.556903 6584 out.go:236] Setting JSON to false
I0202 12:40:59.565255 6584 start.go:106] hostinfo:
@noelwelsh
noelwelsh / reader-monad.md
Last active October 23, 2020 14:27
Discovering the Reader Monad

The Reader Monad

The reader monad is one solution to "dependency injection". This document shows how we might discover the reader monad when we attempt to solve this problem.

Dependency Injection

Our working definition of the dependency injection problem will be this: we have a method or function that takes certain parameters that we don't want to specify every time we call it. For example, we might have a function that gets a user given an ID and also requires a database connection.

def getUser(db: DbConnection, id: Id): User =
@noelwelsh
noelwelsh / thoughts.txt
Created July 7, 2020 09:19
The difficulty of defining a curriculum for creative coding
The original poster said they wanted to construct a curriculum to become a "web artist and/or use code or electronics to create art".
In well established fields there are reasonably well established expectations as to what a curriculum involves. E.g. for computing there is an accreditation body (https://dev.csab.org/info-for/programs/) and widely agreed upon curriculum guidelines (e.g. https://www.acm.org/education/curricula-recommendations). So there is reasonably widely shared understanding of what someone undertaking, say, a computer science degree should learn. Computing is interesting because there are so many new alternate routes such as bootcamps but even here I think they are informed by the above (e.g. https://github.com/Ada-Developers-Academy/textbook-curriculum has elements that would be found in almost all university curriculums)
I believe "creative computing", or whatever we want to call OP's goal, is different. It's defined by the output (e.g. "creative application of computing") more than by
> java -version 1397ms  Thu 7 May 10:38:16 2020
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)
> java -jar ping-server.jar -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:+UseJVMCICompiler
[ioapp-compute-0] INFO o.h.b.c.n.NIO1SocketServerGroup - Service bound to address /[0:0:0:0:0:0:0:0]:8080
[ioapp-compute-0] INFO o.h.s.b.BlazeServerBuilder -
_ _ _ _ _
| |_| |_| |_ _ __| | | ___
| ' \ _| _| '_ \_ _(_-<
@noelwelsh
noelwelsh / HList.scala
Created April 14, 2020 13:47
An HList in Dotty (which doesn't compile)
import scala.compiletime._
import scala.compiletime.ops.any
// This is a standard HList plus data is keyed by a type K
sealed trait HList {
def :::[K <: AnyVal, V](data: V): HCons[K, V, this.type] = HCons(data, this)
inline def contains[K <: AnyVal]: Boolean =
inline this match {
case HNil => false
import scala.compiletime._
import scala.compiletime.ops.any
final case class Col[Key, Value](data: Array[Value])
object Frame {
object Types {
type Get[F <: Tuple, Key] =
F match {
case Col[Key, v] *: cols => v
@noelwelsh
noelwelsh / curriculum.org
Created March 13, 2020 17:19
ScalaBridge Curriculum

Curriculum

Level One

Setup

  • VSCode or IntelliJ?

Expressions, Types, and Values

  • Literals
  • Expressions have types and produce values
  • Compound expressions
  • All values are objects
  • Method call syntax
@noelwelsh
noelwelsh / Nullable.scala
Created April 17, 2015 10:38
Nullable types in Scala
object Nullable {
sealed trait NullableTag
type Nullable[A] = A with NullableTag
def nullAs[B]: Nullable[B] =
null.asInstanceOf[Nullable[B]]
implicit class ToNullable[A](val a: A) extends AnyVal {
def `?`: Nullable[A] = a.asInstanceOf[Nullable[A]]
}