This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
MIT License | |
Copyright (c) 2018 Anthony Najjar | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
This file contains hidden or 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 aiohttp | |
def request_tracer(results_collector): | |
""" | |
Provides request tracing to aiohttp client sessions. | |
:param results_collector: a dict to which the tracing results will be added. | |
:return: an aiohttp.TraceConfig object. | |
:example: |