Skip to content

Instantly share code, notes, and snippets.

View vortec's full-sized avatar

Fabian Kochem vortec

View GitHub Profile
root@(none):~/debian-installer-20130613+deb7u1/build# fakeroot make rebuild_netboot
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
@vortec
vortec / gist:5843378
Created June 23, 2013 01:35
Late night implementation of Tornado + Redis PubSub + Websockets. It's late, the code is messy, but it should demonstrate how the general construct works. Feel free to try it on your own after studying it.
import json
import os
import tornado.httpserver
import tornado.web
import tornado.websocket
import tornado.ioloop
import tornado.gen
import tornadoredis
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