Skip to content

Instantly share code, notes, and snippets.

@koterpillar
koterpillar / kind-projector.gradle
Created November 28, 2019 04:18
Enable Scala kind projector in a Gradle build
// This enables kind projector (https://github.com/typelevel/kind-projector) in a Gradle build.
// Versions used: Gradle 6.0.1, Scala 2.13.1.
ext {
scalaVersionFull = '2.13.1'
scalaVersion = '2.13'
}
configurations {
kindProjectorPlugin
@matthieuheitz
matthieuheitz / djvu2pdf.sh
Last active June 12, 2023 12:47
djvu2pdf, a conversion script using ocrodjvu and pdfbeads
#!/bin/bash
# Method found here https://askubuntu.com/a/122604/423332
# Dependencies:
# On ubuntu, you can install ocrodjvu and pdfbeads with:
# sudo apt install ocrodjvu
# gem install pdfbeads
# The path and filename given can only contain ascii characters
@wagnerfonseca-luizalabs
wagnerfonseca-luizalabs / Install Google Protobuf on Mac
Created October 31, 2017 18:39
How to install Google Protobuf on Mac
$ wget https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz
$ tar -zxvf protobuf-cpp-3.4.1.tar.gz
$ sudo mv protobuf-3.4.1 /usr/local/bin
$ cd /usr/local/bin/protobuf-3.4.1
$ ./configure
$ make
$ make install
$ protoc --version
@vibin
vibin / OpenInSafari.scpt
Created January 20, 2017 05:51
Open Chrome's Current URL in Safari
tell application "Google Chrome"
set visibleUrl to get URL of active tab of window 1
end tell
tell application "Safari"
open location visibleUrl
activate
end tell

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
@jkpl
jkpl / Main.scala
Last active February 5, 2024 08:29
Ways to pattern match generic types in Scala
object Main extends App {
AvoidLosingGenericType.run()
AvoidMatchingOnGenericTypeParams.run()
TypeableExample.run()
TypeTagExample.run()
}
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
}
@goldobin
goldobin / ByteStringConverters.scala
Last active November 6, 2017 08:06
Converters for UUID and String to ByteString for Scala
object ByteStringConverters {
implicit val DefaultByteOrder = ByteOrder.BIG_ENDIAN
implicit class UUIDWithToByteString(uuid: UUID) {
def toByteString = ByteString(
ByteBuffer
.allocate(16)
.putLong(uuid.getMostSignificantBits)
.putLong(8, uuid.getLeastSignificantBits)
)
@jwreagor
jwreagor / EmacsKeyBinding.dict
Created March 20, 2014 18:41
Global Emacs Key Bindings for OS X
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
@cheecheeo
cheecheeo / MonoidFun.hs
Created November 26, 2013 03:37
Somebody said that lists are the "free monoid" in Haskell
module MonoidFun where
-----------------------------------------------------------------------------
-- |
-- Inspirition from: http://stackoverflow.com/a/13357359/1019205 lists are
-- the "free monoid" and http://hackage.haskell.org/package/newtype
import Data.Monoid
import Data.Foldable
import Control.Newtype
@jgoosey
jgoosey / quine.hs
Last active August 12, 2020 17:22
Quine in Haskell, two implementations
--Haskell Quine
--Implementation 1
import Control.Monad
import Control.Monad.Instances
main = (putStr . ap (++) show)
"--Haskell Quine\n--Implementation 1\nimport Control.Monad\nimport Control.Monad.Instances\nmain = (putStr . ap (++) show) "
--Implementation 2
--main = putStrLn (s ++ show s) where s =
-- "--Haskell Quine\n--Implementation 2\nmain = putStrLn (s ++ show s) where s ="