title | search |
---|---|
Simple API |
true |
A Simple API.
defmodule Opaque.User do | |
@moduledoc """ | |
Demonstrates a ridiculous method for enforcing that a type remains in a valid state using a closure and internal secret | |
""" | |
alias __MODULE__ | |
# Ensure that the internal closure can only be called from within this module | |
@update_key :crypto.strong_rand_bytes(8) | |
namespace System.Text.Json | |
open System | |
open System.Collections.Generic | |
open System.Text.Json.Serialization | |
// Converts Option<T> to/from JSON by projecting to null or T | |
type OptionValueConverter<'T>() = | |
inherit JsonConverter<'T option>() |
defmodule TextProcess do | |
def generate_files(num_files, lines_per_file) do | |
Enum.each(1..num_files, fn i -> | |
filename = "data/test_#{i |> Integer.to_string() |> String.pad_leading(3, "0")}.csv" | |
File.open!(filename, [:write], fn file -> | |
Enum.each(1..lines_per_file, fn _ -> | |
IO.puts(file, line()) | |
end) | |
end) |
defmodule ExqStatsD do | |
@behaviour Exq.Middleware.Behaviour | |
alias Exq.Middleware.Pipeline | |
@moduledoc """ | |
This behavior will send stats to statsd endpoint for monitoring. | |
""" | |
require Logger |
defmodule NumberToWord do | |
@spec say(integer) :: String.t | |
def say(n), do: n |> say_io() |> IO.iodata_to_binary() | |
@spec say_io(integer) :: iodata | |
def say_io(1), do: "one" | |
def say_io(2), do: "two" | |
def say_io(3), do: "three" | |
def say_io(4), do: "four" | |
def say_io(5), do: "five" |
defmodule Scrabble do | |
def score("", n), do: n | |
def score("A" <> rest, n), do: score(rest, n + 1) | |
def score("B" <> rest, n), do: score(rest, n + 3) | |
def score("C" <> rest, n), do: score(rest, n + 3) | |
def score("D" <> rest, n), do: score(rest, n + 2) | |
def score("E" <> rest, n), do: score(rest, n + 1) | |
def score("F" <> rest, n), do: score(rest, n + 4) | |
def score("G" <> rest, n), do: score(rest, n + 2) | |
def score("H" <> rest, n), do: score(rest, n + 4) |
defmodule MyService do | |
def foo() do | |
GenServer.call(:my_service, :foo) | |
end | |
end | |
defmodule MyServiceFake do | |
use GenServer | |
def handle_call(:foo, _from, state) do | |
{:reply, :fake, state} |
{ | |
"swagger": "2.0", | |
"info": { | |
"version": "1.0.0", | |
"title": "Simple API", | |
"description": "A Simple API.", | |
"termsOfService": "Use at your own risk!", | |
"contact": { | |
"name": "Joe P. Coder" | |
}, |