Skip to content

Instantly share code, notes, and snippets.

View amoilanen's full-sized avatar
💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra

Anton Moilanen amoilanen

💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra
View GitHub Profile
@amoilanen
amoilanen / ZioSubscriptionRef.scala
Created June 30, 2021 21:25
Full runnable example for the documentation https://zio.dev/docs/datatypes/stream/subscription-ref including correcting the type inference for IDEA
import java.io.IOException
import zio.{Chunk, RefM, Runtime, UIO, URIO, ZIO, console, random}
import zio.console.Console
import zio.random.Random
import zio.stream.{SubscriptionRef, ZStream}
// Full running example for the ZIO documentation https://zio.dev/docs/datatypes/stream/subscription-ref
object Subscription extends App {
@amoilanen
amoilanen / generator_function.js
Created February 1, 2021 13:48
Simple demo of a generator function
function square(x) {
return x * x;
}
function* sumSquares(values) {
let result = 0;
for (value of values) {
const nextIncrement = yield square(value);
console.log(`inside sumSquares: ${nextIncrement}`);
result += nextIncrement;
@amoilanen
amoilanen / aoc2020_day15.ts
Created December 20, 2020 20:43
Solution in Typescript for Day 15 of Advent of Code 2020
interface NumberIndexes {
[key: number]: number;
}
const input: string = '0,13,1,16,6,17';
function withTimings<T>(f: () => T): T {
const startTime = new Date().getTime();
const result = f();
const endTime = new Date().getTime();
@amoilanen
amoilanen / infinite_streams_in_scheme.scm
Last active December 13, 2020 18:10
Infinite stream implementation in Scheme
(define (force x)
(x))
(define (stream-numbers-from n)
(cons
n
(lambda () (stream-numbers-from (+ n 1)))))
(define (stream-multiples-of n)
(stream-map
@amoilanen
amoilanen / useful.bash.utilities.sh
Last active May 20, 2021 09:27
Useful Bash utilities which might be added, for example, to .bashrc
#!/bin/bash
alias view-staged-diff="git diff --staged > ~/temp/changes.diff && gedit ~/temp/changes.diff &"
alias view-diff="git diff > ~/temp/changes.diff && gedit ~/temp/changes.diff &"
free_port() {
kill -9 $(lsof -t -i:$1)
}
terminate() {
@amoilanen
amoilanen / free.docker.space.sh
Last active February 5, 2020 18:25
Useful commands to free Docker space
# Stop and remove all containers
docker rm -f $(docker ps -a -q)
# Remove all images
docker rmi $(docker images -a -q)
# Remove other unused docker data, i.e. networks
docker system prune
# Remove all the unused docker volumes (frees lots of space!)
@amoilanen
amoilanen / launch.json
Created August 22, 2019 09:50 — forked from constantm/launch.json
Get VSCode debug and breakpoints to work with Vue Cli and Jest
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vue-cli-service-tests",
"request": "launch",
"env": {
"NODE_ENV": "test"
},
@amoilanen
amoilanen / list_map_fold.scm
Created October 8, 2018 20:30
map and fold implementation for lists in Scheme
; Maps function over list
; f - function of one argument, returns transformed argument
; l - list
(define (map f l)
(if (> (length l) 0)
(cons
(f (car l))
(map f (cdr l))
)
()
@amoilanen
amoilanen / create_bootable_drive.sh
Created September 24, 2018 09:28
Command to create bootable USB with progress displayed using dd, pv
sudo dd if=./some.linux.iso | pv -s 2G | sudo dd of=/dev/sdb bs=8192
@amoilanen
amoilanen / akka_stream_example.scala
Created March 11, 2018 22:25
Simple example of a stream in Akka: source -> flow -> sink
import akka.actor.ActorSystem
import akka.stream.scaladsl._
import akka.stream._
object AkkaStreamExample extends App {
implicit val system = ActorSystem("MyActorSystem")
implicit val materializer = ActorMaterializer()
val source = Source(1 to 5)
val square = Flow[Int].map(x => x * x)