Skip to content

Instantly share code, notes, and snippets.

View vortec's full-sized avatar

Fabian Kochem vortec

View GitHub Profile
defmodule KVServer.Command do
@doc ~S"""
Parses a line into a command.
## Examples
iex> KVServer.Command.parse "CREATE shopping\r\n"
{:ok, {:create, "shopping"}}
iex> KVServer.Command.parse "CREATE shopping \r\n"
defmodule KVServer.Command do
@doc ~S"""
Parses a line into a command.
## Examples
iex> KVServer.Command.parse "CREATE shopping\r\n"
{:ok, {:create, "shopping"}}
"""
def parse(line) do
defmodule Action do
defmodule Configuration do
end
@callback description(Configuration) :: String
@callback perform(Configuration, String) :: nil
end
defmodule Webhook do
@behaviour Action
defmodule KV.Bucket do
@doc """
Starts a new bucket.
"""
def start_link do
Agent.start_link(fn -> %{} end)
end
@doc """
Gets a value from the `bucket` by `key`.
defmodule KV do
def start_link do
Task.start_link(fn -> loop(%{}) end)
end
defp loop(map) do
receive do
{:get, key, caller} ->
send caller, Map.get(map, key)
loop(map)
defmodule Math do
def zero_a?(0) do
true
end
def zero_a?(_) do
false
end
def zero_b?(x) do
class EventDispatcher:
def __init__(self, loop, input_handler, output_handler):
self.loop = loop
self.input_handler = input_handler
self.output_handler = output_handler
async def __call__(self, event):
# Generic stuff (logging, benchmarking, ...)
message = await self.input_handler(event)
await self.output_handler(message)
MATCH (root:RootObject), (u {name: 'Tom'})-[:HAS_PERMISSION]->(o),
p = shortestPath((root)-[*]-(o)) WHERE (r IN rels(p) WHERE type(r) = 'CONTAINS')
RETURN p

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

(dx-rtu)[fkochem@FK2] code/didactix/rtu (git)-[signal]$ pip install --upgrade pip
Traceback (most recent call last):
File "/Users/fkochem/workspace/instances/dx-rtu/bin/pip", line 7, in <module>
from pip import main
File "/Users/fkochem/workspace/instances/dx-rtu/lib/python3.5/site-packages/pip/__init__.py", line 13, in <module>
from pip.commands import commands, get_summaries, get_similar_commands
File "/Users/fkochem/workspace/instances/dx-rtu/lib/python3.5/site-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.bundle import BundleCommand
File "/Users/fkochem/workspace/instances/dx-rtu/lib/python3.5/site-packages/pip/commands/bundle.py", line 6, in <module>
from pip.commands.install import InstallCommand