Skip to content

Instantly share code, notes, and snippets.

View alexandru's full-sized avatar
😺
Having fun

Alexandru Nedelcu alexandru

😺
Having fun
View GitHub Profile
import monix.execution.{Cancelable, Scheduler}
import monix.execution.atomic.Atomic
import monix.reactive.Observable
import monix.reactive.observables.ConnectableObservable
import monix.reactive.observers.Subscriber
import monix.reactive.subjects.PublishSubject
final class AwaitSubscribersObservable[A](source: Observable[A], awaitCount: Int)
(implicit sc: Scheduler) extends Observable[A] {

How to add a Web Feed (RSS/Atom) to your Jekyll website

If you're generating your website with Jekyll or another static website generator, don't forget to also expose a web feed for us old timer using RSS readers. The format we'll be preferring here is Atom.

Some reasons to expose a web feed:

  1. people using RSS readers regularly are pretty loyal, RSS/Atom subscribers being like a mailing list for some of us
  2. tooling knows RSS/Atom — e.g. the easiest way to build a mailing list is to give Mailchimp your RSS feed

If you're looking for a recommendation on online RSS readers, I personally like Newsblur.

import cats.effect.{ContextShift, IO}
object TestStartJoin {
def test(times: Int)(implicit cs: ContextShift[IO]) = {
var count = 0
for (_ <- 0 until times) {
val thread = Thread.currentThread().getName
val task = for {
_ <- IO.unit.start.flatMap(_.join)
@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
import IOApp.Runtime
trait IOApp {
// Implicit extractor
implicit final def contextShift(implicit r: Runtime): ContextShift[IO] =
r.contextShift
// Implicit extractor
implicit final def timer(implicit r: Runtime): Timer[IO] =
r.timer
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
import scala.concurrent.Future
import scala.util.control.NonFatal
import Ack.{Continue, Stop}
sealed trait Ack
object Ack {
case object Continue extends Ack

Cats-Effect Model vs Auto-cancelable FlatMaps

Consider this data structure:

sealed trait LazyList[F[_], A]

case class Cons[F[_], A](head: A, tail: F[LazyList[F, A]], stop: F[Unit])
  extends LazyList[F, A]
sbt:scala-futures> benches/jmh:runMain scala.future.BenchRunner -p threads=1 -p recursion=8192 -i 30 -wi 15 -f1 -t1 Benchmark
[info] Packaging /Users/alex/Projects/personale/scala-futures/benches/target/scala-2.12/benches_2.12-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running (fork) scala.future.BenchRunner -p threads=1 -p recursion=8192 -i 30 -wi 15 -f1 -t1 Benchmark
[info] # JMH version: 1.20
[info] # VM version: JDK 1.8.0_112, VM 25.112-b16
[info] # VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/bin/java
[info] # VM options: -Xmx512M -Xms512M -ea -server -XX:+UseCompressedOops -XX:+AlwaysPreTouch -XX:+UseCondCardMark
[info] # Warmup: 15 iterations, 1 s each
[info] # Measurement: 30 iterations, 1 s each
import java.io.Serializable
/**
* Extracted from the cats-effect project.
*
* A type-aligned seq for representing function composition in
* constant stack space with amortized linear time application (in the
* number of constituent functions).
*
* Implementation is enormously uglier than it should be since