Skip to content

Instantly share code, notes, and snippets.

@okapies
okapies / Id.scala
Created May 27, 2012 15:02
How to implement case class manually. (for Scala 2.9.2 final)
import scala.runtime.ScalaRunTime
/**
* A sample code to implement a customized case class manually (for Scala 2.9.2 final).
*
* Id has two properties: name and displayName. 'displayName' has default value that
* is same value as 'name'.
*/
class Id private ( // make primary constructor not to be accessible. (standard case class can do)
@retronym
retronym / instruction.sh
Last active December 17, 2015 00:29
scala-2.10
sudo gem install keydown # optional, only needed if you update the markdown.
git clone git@github.com:retronym/talks.git
git clone -b topic/play-keydown git@github.com:retronym/replhtml.git && cd replhtml
sbt -Dkeydown.root=$PWD/../talks/scala-2.10 run
open http://localhost:8080
@torgeir
torgeir / builder.scala
Last active December 21, 2015 03:48
Type safe scala builder, with required arguments, without a build()!
object BuilderTest {
class NAME_WAS_SET
case class Person(name: String, age: Option[Int])
case class PersonBuilder[NAME_NOT_SET](name: Option[String], age: Option[Int]) {
def withName(name: String) = new PersonBuilder[NAME_WAS_SET](Some(name), age)
def withAge(age: Int) = new PersonBuilder[NAME_NOT_SET](name, Some(age))
}
@sindresorhus
sindresorhus / post-merge
Last active February 14, 2024 06:20
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@vrischmann
vrischmann / .credentials
Last active January 20, 2023 11:57
Running SBT with a Nexus proxy with authentication
realm=Sonatype Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123
@acolyer
acolyer / service-checklist.md
Last active January 30, 2024 17:39
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?

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
@aaronlevin
aaronlevin / events.hs
Last active December 3, 2023 13:03
LambdaWorld 2016 & Typelevel Summit 2017 (Copenhagen): Type-Level DSLs // Typeclass induction
-- Our goal is to create a type describing a list of events. This is our
-- type-level DSL.
-- We will then use typeclass resolution to "interpret" this type-level DSL
-- into two things:
-- 1. A comma-separated list of events
-- 2. A method that, when given an event name and a payload, will try to parse
-- that event type with the payload. A form of dynamic dispatching
--
-- To model a list of types we will use tuples. You can imagine the list of
-- types "Int, String, Char" to look like: