This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import os | |
class JobDoneError(Exception): | |
pass | |
class Job: | |
"""A file backed job, completed steps are commited to disk so it's resumable""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program output: | |
// original: Power(Multiply(Variable(x),Sum(Variable(y),Multiply(Constant(5.0),Constant(7.0)))),Power(Sum(Constant(1.0),Constant(2.0)),Power(Sum(Constant(0.0),Constant(1.0)),Constant(2.0)))) | |
// optimized: Power(Multiply(Variable(x),Sum(Variable(y),Constant(35.0))),Constant(3.0)) | |
// show: ((x * (y + 35.0)) ^ 3.0) | |
// evaluates to: 216000.0 for variables: Map(x -> 1.5, y -> 5.0) | |
sealed trait Expr | |
case class Constant(a: Double) extends Expr | |
case class Variable(a: String) extends Expr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anthonynsimon.boolquery | |
sealed trait BooleanQuery[A] | |
case class Pure[A](a: A) extends BooleanQuery[A] | |
case class And[A](x: BooleanQuery[A], y: BooleanQuery[A]) extends BooleanQuery[A] | |
case class Or[A](x: BooleanQuery[A], y: BooleanQuery[A]) extends BooleanQuery[A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
from threading import Thread, Lock | |
import sys | |
import time | |
class Q: | |
def __init__(self): | |
self._items = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Functor[F[_], A] { | |
def fmap[B](f: (A) => B): F[B] | |
} | |
trait Applicative[F[_], A, B] { | |
def liftA(f: F[A]): F[B] | |
} | |
def fmap[A, B](f: (A) => B): (Option[A]) => Option[B] = { | |
case Some(x) => Option(f(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.* | |
import kotlinx.coroutines.experimental.channels.Channel | |
import java.util.concurrent.atomic.AtomicLong | |
import kotlin.concurrent.thread | |
fun main(args: Array<String>) { | |
// bench("threads") { skynetThread(0, 1000000, 10) } // Out of Memory error | |
bench("sync") { skynetSync(0, 1000000, 10) } | |
bench("coroutines-async") { skynetCoroutinesAsync(0, 1000000, 10) } | |
bench("coroutines-launch") { skynetCoroutinesLaunch(0, 1000000, 10) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PingPong do | |
def ping(pid) do | |
send pid, {:ping, self()} | |
receive do | |
:pong -> :ok | |
end | |
end | |
def pong do | |
receive do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.netty.bootstrap.ServerBootstrap | |
import io.netty.channel.{ChannelOption, ChannelHandlerContext, ChannelInitializer, ChannelInboundHandlerAdapter} | |
import io.netty.channel.nio.NioEventLoopGroup | |
import io.netty.channel.socket.SocketChannel | |
import io.netty.channel.socket.nio.NioServerSocketChannel | |
import io.netty.channel.group.{ChannelGroup, DefaultChannelGroup} | |
import io.netty.handler.codec.http.{HttpObjectAggregator, HttpServerCodec} | |
import io.netty.handler.logging.{LogLevel, LoggingHandler} | |
import io.netty.channel.ChannelHandler.Sharable | |
import io.netty.handler.codec.http._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"net" | |
"strings" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable | |
trait Source[+A] { | |
def output(): A | |
} | |
trait Flow[A, B] extends Sink[A] with Source[B] | |
trait Sink[-A] { | |
def input(a: A): Unit |