Skip to content

Instantly share code, notes, and snippets.

@ClaireNeveu
ClaireNeveu / Models.md
Last active August 29, 2015 14:11
Type-Safe Resolution

Instead of simple case classes we make use of a system of Extensible Virtual Models to describe our models. This has the practical advantage of making these models run-time extensible while maintaining type-safety. This document serves as a brief introduction to this system and explains how it relates to normal case classes.

Consider this simplified version of a Post and a function which operates on it:

case class Post(id : Id[Post], authorId : Id[Author], blogId : Id[Blog], title : String, body : Html)

def escapeBody(post : Post) : Post = ...

The model contains the Post's id, title, and body as well as foreign keys to its author and blog. This serves us well for many cases but sometimes we want to access properties of the author or blog of this post. Because retrieving these models requires API calls to the relevant service, we'd like to pass these models around with the post so we only retrieve them once.

@ClaireNeveu
ClaireNeveu / scalaFlags
Last active July 5, 2017 17:15
Scala Flags
-Dproperty=value Pass -Dproperty=value directly to the runtime system.
-J<flag> Pass <flag> directly to the runtime system.
-P:<plugin>:<opt> Pass an option to a plugin
-X Print a synopsis of advanced options.
-bootclasspath <path> Override location of bootstrap class files.
-classpath <path> Specify where to find user class files.
-d <directory|jar> destination for generated classfiles.
-dependencyfile <file> Set dependency tracking file.
-deprecation Emit warning and location for usages of deprecated APIs.
-encoding <encoding> Specify character encoding used by source files.
@ClaireNeveu
ClaireNeveu / Notes.md
Created January 27, 2015 01:33
Notes

Good name for a caching proxy: QuickMoney "fast cache" == "fast cash" == "quick money"

@ClaireNeveu
ClaireNeveu / TypeClasses.md
Created February 18, 2015 19:47
Type Classes Explained

A lot of people have difficulty understanding type-classes​. This has a lot more to do with the context of type-classes than type-classes themselves; Haskell, the foremost language with type-classes, also includes more complicated concepts enabled by type-classes. People often conflate these concepts with type-classes themselves.

Type-classes in Scala are similarly conflated with more complicated concepts and have the added detriment of being a pattern rather than a language feature.

In this post I'll explain type-classes by relating them to somehting everybody understands: the List interface in Java.

public interface List<E> {
   public E get(int index) = ...
   public int size() = ...
import Prelude hiding (max)
data Tree
= Alpha Int [Tree]
| Beta String [Tree]
| Gamma Bool [Tree]
children :: Tree -> [Tree]
children (Alpha _ ch) = ch
children (Beta _ ch) = ch
object TestConfig extends com.kinja.config.ConfigApi {
val root = com.kinja.config.BootupErrors(com.kinja.config.LiftedTypesafeConfig(testConf, "root"));
def <init>() = {
super.<init>();
()
};
private val subConfig = getConfig("sub-config");
val pureValue = 5;
val otherPureValue: Int = 7;
val somePureValue: Option[Int] = Some(8);
@ClaireNeveu
ClaireNeveu / monad.ml
Last active July 24, 2016 23:04
Defining Categories with Structural Types
type 'a monad = { bind : 'b. ('a -> 'b monad) -> 'b monad }
type 'a option = { getOrElse : 'a -> 'a }
let none = { getOrElse = (fun b -> b); bind = fun f -> none};;
let some a = { getOrElse = (fun b -> a); bind = fun f -> f a};;
@ClaireNeveu
ClaireNeveu / third-party-viddler-videos.csv
Created July 26, 2016 18:33
Third-party Viddler Videos
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
9ab3716
explore
c4a8e90c
8baef12e
e5b3acca
2b2450d4
dec1c552
2382
1155e288
2067
#! /usr/bin/env python3
import sys
import time
def main():
spinner = Spinner()
for x in range(20):
time.sleep(0.2)
@ClaireNeveu
ClaireNeveu / NonEmptyString.scala
Last active April 11, 2017 01:22
NonEmptyString
package nonemptystring
import macrame.delegate
import scala.collection.immutable.StringOps
final case class NonEmptyString(val head : Char, val tail : String) {
@delegate
override def toString : String = head + tail
}