Skip to content

Instantly share code, notes, and snippets.

View kpmeen's full-sized avatar
👾

Knut Petter Meen kpmeen

👾
View GitHub Profile
@jboner
jboner / latency.txt
Last active June 11, 2024 07:09
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@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
@mariussoutier
mariussoutier / JsonFormats.scala
Last active December 6, 2016 07:19
ReactiveMongo Play Plugin Extensions
package json
import reactivemongo.bson._
import reactivemongo.bson.handlers.DefaultBSONHandlers._
import play.api.libs.json._
import play.api.libs.json.Json._
import play.api.libs.json.util._
import play.api.libs.json.Writes._
import play.api.libs.functional.syntax._
@mandubian
mandubian / gist:8955241
Created February 12, 2014 13:07
Reads/Writes for a simple AST
import play.api.libs.json._
import play.api.libs.functional.syntax._
sealed trait Parent {
val typ: String
}
case class Foo(blabla: Long, override val typ: String = "foo") extends Parent
@schmmd
schmmd / pre-commit
Created May 7, 2014 16:54
Scalariform Precommit
#!/bin/sh
exec scala -savecompiled "$0" $@
!#
//
// Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
// Modified 2014 AI2 <http://www.allenai.org>
//
// This script will check that the commit is correctly formatted. It only checks files that are to be committed.
// To be run this file should be at `.git/hooks/pre-commit`.
@wozmir
wozmir / scalax_2014_slides.md
Last active August 29, 2015 14:11
Scala exchange 2014 slides
@cb372
cb372 / jargon.md
Last active May 14, 2024 03:45
Category theory jargon cheat sheet

Category theory jargon cheat sheet

A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)

I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.

Functor

A functor is something that supports map.

@aaronlevin
aaronlevin / shapeless-arb-keys.scala
Last active May 13, 2016 08:46
Use Structured Keys in Shapeless Records
/**
* Working with shapeless' records is great. However, you are limited to using only String, Integer, Boolean, and
* (package) Objects as singleton keys as the singleton machinery requires a stable point (I don't really fully
* understand this part but I have an intuition). I had asked if there was a way to use a tuple or case-class
* as a key in the shapeless gitter channel and no one really knew.
*
* I was reading the shapeless source for the Witness type and an idea came to mind: since we can use a package Object
* as a key, what if that key extends a trait (an abstract class can work as well)? Can we use those objects as
* singleton keys and access the values specified in the trait?
*

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

How to GPG as a Scala OSS Maintainer

tl;dr Generate a GPG key pair (exercising appropriate paranoia). Send it to key servers. Create a Keybase account with the public part of that key. Use your keypair to sign git tags and SBT artifacts.

GPG is probably one of the least understood day-to-day pieces of software in the modern developer's toolshed. It's certainly the least understood of the important pieces of software (literally no one cares that you can't remember grep's regex variant), and this is a testament to the mightily terrible user interface it exposes to its otherwise extremely simple functionality. It's almost like cryptographers think that part of the security comes from the fact that bad guys can't figure it out any more than the good guys can.

Anyway, GPG is important for open source in particular because of one specific feature of public/private key cryptography: signing. Any published software should be signed by the developer (or company) who published it. Ideally, consu