Skip to content

Instantly share code, notes, and snippets.

View keathley's full-sized avatar

Chris Keathley keathley

View GitHub Profile
defmodule PCache do
def start do
# data = for i <- 0..1_000, do: {i, i}, into: %{}
spawn(fn ->
accept_reads()
end)
end
def get(pid) do
us = self()
@keathley
keathley / application.ex
Created October 22, 2019 14:29
Example of elixir runtime configuration
defmodule Huddle.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
Endpoint,
Repo,
{RedisClient, redis_config()}
@keathley
keathley / .credo.exs
Last active December 30, 2023 16:13
Keathley's credo file
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
@keathley
keathley / rabbit.ex
Created May 22, 2019 15:39
Rabbit connection statemachine
defmodule RabbitConnection do
@moduledoc """
RabbitMQ client connection
"""
@behaviour :gen_statem
use AMQP
alias AMQP.Basic
@exchange "messages_exchange"
@keathley
keathley / stateful_server.ex
Last active May 9, 2019 03:58
stateful_server example
defmodule Demo do
def demo do
_once_per_second = Demo.start(:once, 200)
_ten_per_second = Demo.start(:ten, 220)
_hundret_per_second = Demo.start(:hundret, 250)
IO.puts("Launced processes")
Process.sleep(1_500)
[:once, :ten, :hundret] |> show() |> IO.inspect()
@keathley
keathley / retry.ex
Created April 16, 2019 14:49
Tesla Middleware with exponential backoff
defmodule Huddle.Tesla.Retry do
@moduledoc """
Adds exponential backoff + retry logic to tesla
"""
# Maximum times to retry
@max_retries 5
# Base delay retry value is 50ms
@delay 50
@keathley
keathley / dry_monad_usage.md
Last active March 14, 2024 15:16
A description of how to take advantage of the dry-monad gem.

How we're using dry-monad

Imagine that we have an application where user's have a location. We want to find the weather for their current location using an external service call. We want to provide this functionality in a json api. A basic implementation might look like this.

def create
 user = User.find(params[:id])

Keybase proof

I hereby claim:

  • I am keathley on github.
  • I am keathley (https://keybase.io/keathley) on keybase.
  • I have a public key whose fingerprint is 127E 4801 6473 B025 9666 DDEC 646E F51E 2C11 C8A1

To claim this, I am signing this object:

@keathley
keathley / sift.hs
Created February 2, 2016 03:04
Fuzz file matching with haskell
import Data.List
type Query = String
type Choice = String
type Score = Int
data Match = Found String String Int Int
| Boundary String String Int Int
| Sequential String String Int Int