Skip to content

Instantly share code, notes, and snippets.

@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>
@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 / 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 / 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
✘╹◡╹✘ < 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 / task-proposal.md
Created December 30, 2015 14:36 — forked from alexandru/task-proposal.md
Task: A diverging design from Future and Scalaz Task

Monifu Task: A diverging design from Future and Scalaz Task

This document is about Task, an alternative for Scalaz's Task or Scala's Future. Note this is work in progress and this document suffered multiple modifications already:

import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ ThreadFactory, Executors, ExecutorService }
import scalaz.concurrent.Task
object Test {
class MyThreadFactory(prefix: String) extends ThreadFactory {
val n = new AtomicInteger(0)
override def newThread(r: Runnable) = {
val t = Executors.defaultThreadFactory().newThread(r)
package OptionValueAccessor
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
object OptionValueAccessor {
implicit def unwrapOptValue[A](a: OptValue[A]): Option[A] = a.unwrap
implicit class OptValue[A](val unwrap: Option[A]) extends Dynamic {
trait Applicative[F[_]] {
def pure[A](a: A): F[A]
def apply[A, B](f: F[A => B], a: F[A]): F[B]
}
trait Traversable[T[_], F[_]] {
def traverse[A, B](f: A => F[B], a: T[A]): F[T[B]]
}
trait Monoid[A] {
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