Skip to content

Instantly share code, notes, and snippets.

View PeterPerhac's full-sized avatar
💭
compiling...

Peter Perhac PeterPerhac

💭
compiling...
View GitHub Profile

Haskell in Production: Adventures in Blockchain Building

@isyufu
isyufu / TryXodus.scala
Created June 21, 2018 00:39
JetBrains Xodus is a Java transactional schema-less embedded database
/* "org.jetbrains.xodus" % "xodus-openAPI" % "1.2.3",
"org.jetbrains.xodus" % "xodus-entity-store" % "1.2.3",
*/
object XodusApp extends App {
import jetbrains.exodus.bindings.StringBinding.{entryToString, stringToEntry}
import jetbrains.exodus.env.StoreConfig.WITHOUT_DUPLICATES
val env = Environments.newInstance("data")
@isyufu
isyufu / TryDoobie.scala
Created June 16, 2018 03:02
Doobie with SQLite
/* library dependecies
"org.xerial" % "sqlite-jdbc" % "3.23.1",
"org.tpolecat" %% "doobie-core" % "0.5.3",
"org.tpolecat" %% "doobie-hikari" % "0.5.3", // HikariCP transactor.
"org.tpolecat" %% "doobie-specs2" % "0.5.3", // Specs2 support for typechecking statements.
"org.tpolecat" %% "doobie-scalatest" % "0.5.3", // ScalaTest support for typechecking statements.
*/
object TryDoobie extends App {
import doobie._

Why not both?

With the recent announcement of cats-effect, a relevant question from the past resurfaces: why does IO, which is otherwise quite Task-like, not define both or race? To be clear, the type signatures of these functions would be as follows:

object IO {
  def both[A, B](ioa: IO[A], iob: IO[B])(implicit EC: ExecutionContext): IO[(A, B)] = ???
  def race[A, B](ioa: IO[A], iob: IO[B])(implicit EC: ExecutionContext): IO[Either[A, B]] = ???
}

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
@mislav
mislav / git-recently-checkout-branches.sh
Created November 19, 2015 15:35
Show list of recently checked-out branches in reverse-chronological order
#!/bin/bash
set -e
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
seen=":"
git_dir="$(git rev-parse --git-dir)"
while read line; do
date="${line%%|*}"
branch="${line##* }"
if ! [[ $seen == *:"${branch}":* ]]; then
@CMCDragonkai
CMCDragonkai / http_streaming.md
Last active July 27, 2024 11:07
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on