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 LeakyBucket do | |
@moduledoc """ | |
A state machine implementation of the leaky bucket rate limiting algorithm | |
The leaky bucket algorithm is a commonly used rate limiting algorithm. You | |
start out with a number of drops in the bucket, and drops "drip" out of the | |
bucket for each action taken. Drops drip into the bucket based on a fixed | |
timer. This allows for some burst capacity. | |
This version obviously doesn't scale very highly, but most leaky buckets out |
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
// See http://brunch.io for documentation. | |
exports.files = { | |
javascripts: { | |
entryPoints: { | |
'game.js': 'brunchtest.js' | |
} | |
}, | |
}; | |
exports.paths = { |
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
Sanshiro Sugata (1943) | |
The Most Beautiful (1944) | |
Sanshiro Sugata Part Two (1945) | |
The Men Who Tread on the Tiger's Tail (1945) | |
No Regrets for Our Youth (1946) | |
One Wonderful Sunday (1947) | |
Drunken Angel (1948) | |
Stray Dog (1949) | |
Scandal (1950) | |
Rashomon (1950) |
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
var look = function(lineid) { | |
var find; | |
find = (lines_json.find( function(value) { | |
return (value.lineid === lineid); | |
})); | |
if(find.speakerid !== "" || (typeof find.speakerid === "undefined")) { | |
find.retrievedSpeaker = line(entity(find.speakerid).entityname); | |
} | |
lines_out.push(find); | |
if(find.advance_lineid !== "" || (typeof find.advance_lineid === "undefined")) { |
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
-module(chat_server). | |
-export([start/1]). | |
handle_socket(Router, Client) -> | |
case gen_tcp:recv(Client, 0) of | |
{ok, "quit!} -> | |
gen_tcp:close(Client); | |
{ok, Data} -> | |
Router ! {msg, Client, Data} |
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
# In case anyone is wondering how to easily use the :crypto hash or hmac API's from elixir-land, here you go. | |
File.stream!(filename, [:read, {:read_ahead, 65535}], 65535) | |
|> Enum.reduce(:crypto.hash_init(:sha), &:crypto.hash_update(&2, &1)) | |
|> :crypto.hash_final | |
|> Base.encode16 | |
# Line 3 opens up a stream, and we're reading in 64KB chunks from the FS which is roughly pretty efficient | |
# In line 4, we initialize our hash (which returns a context) and put that as the default value in the reducer | |
# The hash_update in the reducer returns the modified context. Remember arg1 is the item, and arg2 is the accumulator |
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 Datastore do | |
use Behaviour | |
@type key :: any | |
@type value :: any | |
defcallback start_link() :: Agent.t | |
defcallback get(Agent.t, key) :: value | |
defcallback put(Agent.t, key, value) :: :ok | |
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
Insertion into Elixir.Map. 10 entries | |
------------------------------------- | |
Range: from 14 to 4480µs | |
Median: 16µs | |
Average: 462.2µs | |
Insertion into Elixir.Map. 100 entries | |
-------------------------------------- |
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 HTMLCharacters do | |
def sanitize(phrase) do | |
chars = %{""" => "\"", "'" => "'", "&" => "&", "<" => "<", ">" => ">"} | |
cond do | |
String.match?(phrase, ~r/&\#?.+;/) -> | |
[code] = Regex.run(~r/&\#?.+;/, phrase) | |
Regex.replace(Regex.compile!(code), phrase, chars[code]) | |
true -> phrase |
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
-module(inotifywait). | |
-include("api.hrl"). | |
-export(?API). | |
find_executable() -> os:find_executable("inotifywait"). | |
known_events() -> [renamed, closed, modified, isdir, undefined]. | |
start_port(Path, Cwd) -> | |
Path1 = filename:absname(Path), | |
Args = ["-c", "inotifywait $0 $@ & PID=$!; read a; kill $PID", |