Skip to content

Instantly share code, notes, and snippets.

@retronym
retronym / indylambda.md
Last active February 5, 2022 10:47
indylambda: Putting invokedynamic to work for Scala

indylambda: Putting invokedynamic to work for Scala

Java 8 introduced lambdas to the Java language. While the design choices differ in many regards from Scala's functions, the underlying mechanics used to represent Java lambdas is flexible enough to be used as a target for the Scala compiler.

Lambdas in Java

Java does not have canonical heirarchy of generic function types (ala scala.FunctionN), but instead allows a lambda to be used as a shorthand for an anonymous implementation of an Functional Interface

Here's an example of creating a predicate that closes over one value:

Actor Queue Notes

The first thing to understand is that the head field inside of scalaz.concurrent.Actor is not the "head" of the message queue in any traditional sense of the word. A better description would be "last". The there are no pointers to the head of the queue, which one of the very clever things about this implementation.

Empty Actor

Consider the case where the actor has no outstanding messages. This new message will go into the following code:

 def !(a: A): Unit = {
@miguno
miguno / kafka-move-leadership.sh
Last active July 6, 2023 19:53
A simple Ops helper script for Apache Kafka to generate a partition reassignment JSON snippet for moving partition leadership away from a given Kafka broker. Use cases include 1) safely restarting a broker while minimizing risk of data loss, 2) replacing a broker, 3) preparing a broker for maintenance.
#!/usr/bin/env bash
#
# File: kafka-move-leadership.sh
#
# Description
# ===========
#
# Generates a Kafka partition reassignment JSON snippet to STDOUT to move the leadership
# of any replicas away from the provided "source" broker to different, randomly selected
# "target" brokers. Run this script with `-h` to show detailed usage instructions.
@shyouhei
shyouhei / gist:0b7dab3e75bfbf96f895
Created March 31, 2015 15:26
新社会人の人が留意すべき事項

新社会人に必須である:

  • 勤務先との書面による「労働契約」。業務委託契約等NG。
  • 多寡を問わず毎月払われる給料。遅配等論外である。
  • 健康保険。
  • 労災保険。
  • 雇用保険。
  • 三六協定。
  • 年次有休。
  • 育児休業の制度があり取得者がいる会社に勤務する。
object TransducerSpecs extends Specification with ScalaCheck {
import Process._
import StreamUtils._
"effectful stream transducers" should {
def id[I]: Transducer[Nothing, I, I] =
transducer.receive1[Nothing, I, I](emit).repeat
"perform a simple identity transformation" in prop { xs: List[List[Int]] =>
val p = emitAll(xs map emitAll).toSource.join
@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 / Foldable.scala
Last active August 29, 2015 14:17 — forked from xuwei-k/Foldable.scala
Trampolined to avoid stack overflow ...
import scala.util.control.TailCalls._
import shapeless._
trait Foldable[F[_]] {
def foldLeft[A, B](fa: F[A], b: B)(f: (B, A) => B): B
}
object Foldable {
implicit def apply[F[_]](implicit fr: Lazy[FoldableRec[F]]): Foldable[F] =
@kusano
kusano / circle.js
Created March 7, 2015 15:23
ガルーンの予定の参加者を円形に(回転版)
!function(){
function render(){
var t=performance.now()/1000;
document.querySelectorAll(".schedule_member_base_grn")[1].style.position="relative";
var p=document.querySelectorAll(".user-grn");
var n=p.length;
for(var i=0;i<n;i++){
var s=p[i].style;
s.position="absolute";
s.top=48*Math.sin(2*Math.PI*(i/n+t))+"px";
@mpilquist
mpilquist / State.scala
Created February 9, 2015 02:31
trampolined state
package cats
package data
import free.Free.Trampoline
import free.Trampoline
// Quick port of http://blog.higher-order.com/assets/trampolines.pdf for cats
sealed abstract class State[S, A] {
import State._
@okapies
okapies / fpinscala-chap11-note.md
Last active August 29, 2015 14:12
FP in Scala chapter notes - Chapter 11: Monads