Skip to content

Instantly share code, notes, and snippets.

@retronym
retronym / low-priority-implicits.scala
Created November 7, 2009 13:00
Scala 2.8 implicit prioritisation, as discussed in: http://www.scala-lang.org/sid/7
object Low {
def low = "object Low"
def shoot = "missed!"
}
object High {
def high = "object High"
def shoot = "bulls eye!"
}
@dholbrook
dholbrook / Tree.scala
Created June 21, 2012 17:59
Scala binary tree
/**
* D Holbrook
*
* Code Club: PO1
*
* (*) Define a binary tree data structure and related fundamental operations.
*
* Use whichever language features are the best fit (this will depend on the language you have selected). The following operations should be supported:
*
* Constructors

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@marianogappa
marianogappa / ordered_parallel.go
Last active February 12, 2024 09:27
Parallel processing with ordered output in Go
/*
Parallel processing with ordered output in Go
(you can use this pattern by importing https://github.com/MarianoGappa/parseq)
This example implementation is useful when the following 3 conditions are true:
1) the rate of input is higher than the rate of output on the system (i.e. it queues up)
2) the processing of input can be parallelised, and overall throughput increases by doing so
3) the order of output of the system needs to respect order of input
- if 1 is false, KISS!

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

object DockerClientApp extends App {
import DockerClientOps._
val client:DockerClient = DefaultDockerClient.fromEnv().build()
val interpreter = spotifyInterpreter(client)
val program = for {
_ <- pull("busybox:latest")
cntrId <- run("busybox", "sh", "-c", "while :; do sleep 1; done")

Fibers

Fibers are an abstraction over sequential computation, similar to threads but at a higher level. There are two ways to think about this model: by example, and abstractly from first principles. We'll start with the example.

(credit here is very much due to Fabio Labella, who's incredible Scala World talk describes these ideas far better than I can)

Callback Sequentialization

Consider the following three functions

@rodgtr1
rodgtr1 / CryptoKids.sol
Created April 7, 2022 12:31
CryptoKids Solidity Smart Contract - Tutorial at https://youtu.be/s9MVkHKV2Vw
// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.7;
contract CryptoKids {
// owner DAD
address owner;
event LogKidFundingReceived(address addr, uint amount, uint contractBalance);