Skip to content

Instantly share code, notes, and snippets.

✘╹◡╹✘ < sbt run
[info] Set current project to scala-playground (in build file:/Users/aereal/devel/src/github.com/aereal/scala-playground/)
[info] Compiling 1 Scala source to /Users/aereal/devel/src/github.com/aereal/scala-playground/target/scala-2.11/classes...
[error] /Users/aereal/devel/src/github.com/aereal/scala-playground/App.scala:7: not found: type ?
[error] val v = Applicative[ValidationNel[String, ?]]
[error] ^
[error] /Users/aereal/devel/src/github.com/aereal/scala-playground/App.scala:7: scalaz.ValidationNel[String,<error>] takes no type parameters, expected: one
[error] val v = Applicative[ValidationNel[String, ?]]
[error] ^
[error] /Users/aereal/devel/src/github.com/aereal/scala-playground/App.scala:7: ambiguous implicit values:
@xuwei-k
xuwei-k / Scalaz Google Code page
Created February 12, 2016 17:49 — forked from runarorama/Scalaz Google Code page
Scalaz Google Code page
<b>The source for Scalaz is now hosted on !GitHub - http://github.com/scalaz/scalaz</b>
Scalaz is a library written in the [http://scala-lang.org/ Scala Programming Language]. The intention of Scalaz is to include general functions that are not currently available in the core Scala API. The scalaz-core module depends only on [http://www.scala-lang.org/docu/files/api/index.html the core Scala API] and the core Java 2 Standard Edition API. Scalaz is released under a BSD open source licence making it compatible with the licence of the Scala project.
[http://code.google.com/p/scalaz/wiki/Scalaz6 Scalaz 6.0.4] was released in January 2012, targeting Scala 2.8.1, 2.9.0.1, 2.9.1 and 2.10.0-M1. [http://scala-tools.org/repo-releases/org/scalaz/scalaz-full_2.9.1/6.0.4/scalaz-full_2.9.1-6.0.4.jar Full download for 2.9.1]
[Scalaz7 Scalaz 7] is currently being developed. This is a rewrite to address the challenges posed by type class inheritance. The first release of this series is expected in April 2012.
== Community
@xuwei-k
xuwei-k / kafka-move-leadership.sh
Created March 3, 2016 12:47 — forked from miguno/kafka-move-leadership.sh
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.
@xuwei-k
xuwei-k / JavaConversionsEvil.scala
Created March 28, 2016 03:53 — forked from jorgeortiz85/JavaConversionsEvil.scala
scala.collection.JavaConversions is evil
import scala.collection.JavaConversions._
case class Foo(s: String)
val map: Map[Foo, String] =
Map(
Foo("a") -> "a",
Foo("b") -> "b")
val v = map.get("a") // should be a type error, actually returns null
@xuwei-k
xuwei-k / apns.sh
Created August 24, 2016 08:52 — forked from greencoder/apns.sh
Curl the APNS http/2 API
# Note: You MUST have curl 7.47+ with http/2 support compiled in
curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert <certificate file> \
https://api.development.push.apple.com/3/device/<device token>
class TC[A](val x: String)
object TC {
def getX[A: TC](a: A): String = implicitly[TC[A]].x
implicit def anyTC[A]: TC[A] = new TC[A]("*")
implicit val stringTC: TC[String] = new TC[String]("String")
}
object Example {
import scalaz.std.string._
import scalaz.std.list._
import scalaz.{Semigroup, Monoid, Functor, Applicative}
trait Foo[A] {
override def toString: String = "Foo"
}
trait Foo2[A] extends Foo[A] {
override def toString: String = "Foo2"
@xuwei-k
xuwei-k / ListBufferTest.scala
Created December 15, 2016 14:32 — forked from jrudolph/ListBufferTest.scala
ListBuffer / List mutability fail
import scala.collection.mutable.ListBuffer
object ListBufferTest extends App {
new X().runTest()
}
class X extends Runnable {
var x: List[String] = List("", "")
def run() {
@xuwei-k
xuwei-k / ASample.scala
Created December 16, 2016 03:01 — forked from mandubian/ASample.scala
Encoding Category Theory Laws (à-la-scalaz/cats) using kind-polymorphic List and compare/manipulate laws of structure
/**
* In classic Scala implementation of hierarchies of Category theory laws (scalaz/cats), the dependency between
* different laws is encoded using inheritance (https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Monad.scala#L14)
*
* This approach creates well-known issues: for example, a Monad is able to _derive_ an Applicative.
* So sometimes, you don't have the Applicative you want but the one derived from the Monad or it doesn't
* compile because you have 2 Applicatives in your implicit scope.
*
* Alois Cochard has proposed a new model to represent that in (scato project)[https://github.com/aloiscochard/scato] or
* (scalaz/8.0.x)[https://github.com/scalaz/scalaz/blob/series/8.0.x/base/src/main/scala/typeclass/Monad.scala] branch.
@xuwei-k
xuwei-k / lmdb.tcl
Created April 28, 2017 15:43 — forked from antirez/lmdb.tcl
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!