Skip to content

Instantly share code, notes, and snippets.

@arnolddevos
arnolddevos / gist:574873
Created September 11, 2010 05:36
Idea for generator and suspendable wrapper
import scala.util.continuations._
class Generator[A] extends Iterator[A] with (A => Unit @ suspendable) {
private var a: Option[A] = None
private var k: Option[Unit => Unit] = None
def next = {
val a0 = a.get
val k0 = k.get
a = None
@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@viktorklang
viktorklang / ExecutionContextExecutorServiceBridge.scala
Last active June 27, 2022 11:38
Turning an ExecutionContext to an ExecutorService (or rather and ExecutorService AND an ExecutionContext) using Scala 2.10+
/*
Copyright 2013 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@chaotic3quilibrium
chaotic3quilibrium / DIY Scala Enumeration - README.txt
Last active September 13, 2020 22:20
DIY Scala Enumeration (closest possible Java Enum equivalent with guaranteed pattern matching exhaustiveness checking)
README.txt - DIY Scala Enumeration
Copyright (C) 2014-2016 Jim O'Flaherty
Overview:
Provide in Scala the closest equivalent to Java Enum
- includes decorating each declared Enum member with extended information
- guarantees pattern matching exhaustiveness checking
- this is not available with scala.Enumeration
ScalaOlio library (GPLv3) which contains more up-to-date versions of both `org.scalaolio.util.Enumeration` and `org.scalaolio.util.EnumerationDecorated`:
@mingfang
mingfang / convert id_rsa to pem
Last active July 20, 2024 14:14
Convert id_rsa to pem file
openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
chmod 600 id_rsa.pem
// http://underscore.io/blog/posts/2015/04/14/free-monads-are-simple.html
// updated version for scalaz 7.2.x where Free automatically applies the
// Coyoneda transform
import scalaz.{Free, ~>, Id}
import scalaz.std.list._
import scalaz.syntax.traverse._
type UserId = Int
type UserName = String
@paulp
paulp / sbt-with-coursier.sh
Last active March 30, 2017 07:58
sbt from zero to shell in 39s.
#!/usr/bin/env bash -x
#
# Invoke sbt starting with no local jars, using coursier.
shopt -s globstar
set -euo pipefail
cpof() {
find "$@" -iname '*.jar' -o -iname '*.zip' | paste -sd: -
}
import cats.data.ReaderT
import cats.implicits.{catsStdInstancesForFuture, _}
import cats.{Applicative, Monad}
import scala.concurrent.ExecutionContext.global
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Future}
object Foo extends App {
@shinnya
shinnya / Main.scala
Last active March 20, 2018 21:37
An example of FP testing using Continuation
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.higherKinds
import scalaz.ContT
import scalaz.std.scalaFuture.futureInstance
object Main {
@dadhi
dadhi / Lens.cs
Last active February 23, 2024 09:41
Functional optics, e.g. Lens, in C# - to simplify access and modification for deep part of immutable value
/*
Inspired by: https://medium.com/@gcanti/introduction-to-optics-lenses-and-prisms-3230e73bfcfe
*/
using System;
using static System.Console;
public static class Program
{
public static void Main()