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 gleam/should | |
pub type Parser(r) { | |
Pop(Parser(fn(String) -> r)) | |
End(r) | |
} | |
fn apply(parser: Parser(fn(String) -> r), value: String) -> Parser(r) { | |
// fn apply(parser) { | |
case parser { |
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
./_build/default/rel/hello_world/bin/hello_world console | |
Exec: /usr/local/lib/erlang/erts-10.7.1/bin/erlexec -boot /opt/app/_build/default/rel/hello_world/releases/0.1.0/hello_world -mode embedded -boot_var ERTS_LIB_DIR /usr/local/lib/erlang/lib -config /opt/app/_build/default/rel/hello_world/releases/0.1.0/sys.config -args_file /opt/app/_build/default/rel/hello_world/releases/0.1.0/vm.args -- console | |
Root: /opt/app/_build/default/rel/hello_world | |
/opt/app/_build/default/rel/hello_world | |
Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:30] [hipe] | |
=CRASH REPORT==== 3-May-2020::13:00:58.045666 === | |
crasher: | |
initial call: application_master:init/4 | |
pid: <0.327.0> |
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
pub type Worker(m) { | |
Pid | |
} | |
pub type WorkerMessage(m) { | |
Down | |
Message(m) | |
} | |
pub type Worker(m) { |
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
// NEEDS TO RUN IN SECURE (HTTPS) CONTEXT. | |
async function run() { | |
// New key pair | |
var keyPair = await window.crypto.subtle.generateKey( | |
{ | |
name: "ECDSA", | |
namedCurve: "P-521" | |
}, | |
true, | |
["sign", "verify"] |
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
mod actor { | |
extern crate typemap; | |
#[derive(Debug)] | |
pub struct Envelop<For: Actor> { | |
// TODO make fields private | |
pub address: For::Id, | |
pub message: For::Message | |
} |
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
pub mod raxx { | |
#[derive(Debug)] | |
pub enum Method {GET, POST} | |
#[derive(Debug)] | |
pub struct Request { | |
pub method: Method | |
} | |
#[derive(Debug, PartialEq)] | |
pub struct Response { |
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
// Turns out this was not too difficult. | |
// By using the event loop as a global mail box ordering is even guaranteed for messages between only two actors. | |
// TODO would like to try and put one actor in a web worker to get some real parallism | |
// TODO would like to handle errors and have the concept of a deceased actor while a reference to an actor still exists. Probably involves creating an actor system like in Scala. Eurgh. | |
var actor = { | |
send: function(message) { | |
var self = this; | |
console.log("sending to:", self); | |
setTimeout(function(){ |
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
# This module represents a behaviour and when used picks from the Application configuration which implementation will be used | |
defmodule Clock do | |
@callback now() :: Integer.t | |
defmacro __using__([]) do | |
module = Application.get_env(:my_app, :Clock) | |
quote do | |
alias unquote(module), as: Clock | |
end |
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
# Using the erlang mechanism of tuple modules it is possible to create a "stateful module". | |
# This concept of a stateful module is discussed in "Programming erlang" Second edition. | |
defmodule User do | |
defstruct name: nil, admin: false, internal: "kinda private" | |
def new(name, options \\ []) do | |
dependencies = struct(%__MODULE__{name: name}, options) | |
{__MODULE__, dependencies} |
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
class CreatePost | |
# An interactor to create a post. | |
# Initialize with a request object that implements the request interface for this interactor. | |
def initialize(request) | |
RequestInterface.required_on! request | |
@user = {:title => request.title} | |
end | |
def result |
NewerOlder