Skip to content

Instantly share code, notes, and snippets.

@alexandru
alexandru / sbt.sh
Last active September 26, 2018 06:24
#!/usr/bin/env bash
#
# Script that detects if Scala's SBT is installed and if
# not then it automatically downloads and installs it at
# a specified path.
#
# Author: Alexandru Nedelcu (https://alexn.org)
#
set -e
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active June 8, 2024 03:01
set -e, -u, -o, -x pipefail explanation

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@sskylar
sskylar / tags.html
Last active January 26, 2021 13:40
Sort Jekyll tags by popularity (number of posts)
<ul>
{% capture tags %}
{% for tag in site.tags %}
<li data-sort="{{ site.posts.size | minus: tag[1].size | prepend: '0000' | slice: -4, 4 }}">
<a href="/{{ site.tag_page_dir }}/{{ tag[0] | slugify: 'pretty' }}">{{ tag[0] }} <span>{{ tag[1].size }}</span></a>
</li>
{% endfor %}
{% endcapture %}
{{ tags | split:'</li>' | sort | join:'</li>' }}
</ul>

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
@milessabin
milessabin / blah.scala
Created May 19, 2016 13:32
Doing something useful with bare singleton types and no macros ...
scala> trait Label[T] { val value: Boolean }
defined trait Label
scala> def mkInstance(s: String, v: Boolean): Label[s.type] = new Label[s.type] { val value = v }
mkInstance: (s: String, v: Boolean)Label[s.type]
scala> implicit def lTrue = mkInstance("True", true)
lTrue: Label[String("True")]
scala> implicit def lFalse = mkInstance("False", false)
@gigamonkey
gigamonkey / criteria.txt
Last active January 5, 2020 06:21
Hiring criteria: looking for the ability to …
Write a program that does what it’s supposed to do
Write idiomatic code
Debug a program that you wrote
Debug a program someone else wrote
Debug the interaction between a system you wrote and one you didn’t
File a good bug report
Modify a program you didn’t write
Test a program you wrote
Test a program you didn’t write
Learn a new programming language
@djspiewak
djspiewak / streams-tutorial.md
Created March 22, 2015 19:55
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@milessabin
milessabin / gist:cadd73b7756fe4097ca0
Last active September 16, 2019 13:44
A new approach to encoding dependently-typed chained implicits, using singleton types ...
object Demo {
// A couple of type classes with type members ...
trait Foo[T] {
type A
}
object Foo {
implicit val fooIS = new Foo[Int] { type A = String }
}
@markhibberd
markhibberd / Aaa-notes.md
Last active August 29, 2015 13:59
lots of questions

So what I understand to be your questions:

  1. What is a coherency problem?
  2. What does over constained code look like / cause?
  3. How do you lose your "desired" instance?

A way to step through understanding this problem:

  • Oh shit, If I have local type classes, I have to handle crazy wacky cases in my implementation, this will likely have performance and correctness implications (see Coherency.scala)
  • What happens if I close over constraint on construction? Oops if I close over it, I end up with OverConstrained code (see OverConstrainedCode.scala) and worse I still have coherency issues, and the ability to lose my intended behavious (LosingAnInstance.scala)
  • Oh wow, if I just don't do local type classes, by never define conflicting implicits, and ascribe a single type to each behaviour, everything is simple and just works.