Skip to content

Instantly share code, notes, and snippets.

@mmmries
mmmries / association_loader.rb
Created June 2, 2020 23:41
Association Loader for ruby-graphql
# from https://github.com/Shopify/graphql-batch/blob/c84a5236ecb1c38fa275c76ee38017f30b7074be/examples/association_loader.rb
# This handles creating generic association loaders (see team_member_graph.rb for an example)
class AssociationLoader < GraphQL::Batch::Loader
def self.validate(model, association_name)
new(model, association_name)
nil
end
def initialize(model, association_name)
@model = model
@mmmries
mmmries / controller.ex
Last active April 20, 2020 13:12
Kick off job after saving changes
defmodule UserController do
def create(params) do
changeset = params
|> cast([:name, :email])
|> validate_required([:email])
|> validate_other_stuff()
WithSideEffects.create(changeset)
end
end
@mmmries
mmmries / game_of_life_encoding.exs
Created January 17, 2020 17:21
A solution for how to encode a list of "on" cell locations into a game-of-life encoding
defmodule GOL do
def encode(list) do
encode(nil, list)
end
# Figure out the starting condition, whether we start "on" or "blank"
def encode(nil, [1 | rest]), do: encode({:on, 1, 1}, rest)
def encode(nil, rest), do: encode({:blank, 1}, rest)
# If we have a sequence of "on" cells we need to know when it started and whether we are consecutive
# with the last cell
@mmmries
mmmries / README.md
Last active January 1, 2019 18:34
Gnat Request Benchmark

I wanted to run another round of performance benchmarks for gnat to see how it's request throughput has changed with the introduction of the ConsumerSupervisor which handles things like processing each request in its own supervised process.

I used a CPU-optimized digital ocean droplet with 16 cores, gnatsd 1.3.0, erlang 21.2.2 and elixir 1.8.0.rc0 You can read the setup instructions below for more details and the results_by_concurrency.md contains details about a lot of different runs.

I'm trying to measure the overhead in the system, so the requests are random byte strings that just get echoed back with processing. The measurements use byte strings of 4 bytes up to 1024 bytes.

TL/DR; You can do 170k+ synchronous requests/sec of small messages or 192MB+/sec of 1kb messages

@mmmries
mmmries / suggested_topics.md
Created October 4, 2018 03:39
Nerves Remote Meetup
  • Testing
    • mocking hardware
    • what is worth testing?
  • Dev environment vs firmware
  • Sensors:
    • Moisture Sensors
    • Temperator Sensors
    • Magnetic Sensors
  • Touch Screen
  • Carry the touch screen from device-to-device
@mmmries
mmmries / A.md
Created June 7, 2018 12:36
A "Plug-ish" approach to flexible shared behavior

The main idea here is compose shared functionality into a pipeline of functions that all implement some shared behaviour.

defmodule Notification.Event do
  # The event (probably a bad name) is where you would put the structified JSON event you got from RabbitMQ
  defstruct [:sent_at, :user, :event]
end

defmodule Notification.Plug do
  @callback init(opts) :: opts
@mmmries
mmmries / language_job_postings.csv
Last active March 19, 2018 06:26
Language Job Postings
type language indeed.com postings stackoverflow postings
functional erlang 199 12
functional elixir 293 33
functional clojure 429 56
functional haskell 356 17
functional f# 126 10
functional akka 532 31
functional functional reactive programming 810 899
both scala 5260 189
both javascript 33347 1201
@mmmries
mmmries / benchmark_roundtrips.exs
Created October 10, 2017 17:19
Gnat Benchmark Script
defmodule LatencyBenchmark do
@default_settings %{
num_actors: 1,
actions_per_actor: 1,
}
def benchmark(action_fn, settings) do # = num_actors, actions_per_actor, setup_fn, action_fn) do
settings = Map.merge(@default_settings, %{setup_fn: fn -> %{} end}) |> Map.merge(settings)
settings = Map.put(settings, :action_fn, action_fn)
{:ok, collector_pid} = Agent.start_link(fn -> [] end)
@mmmries
mmmries / 01.README.md
Last active November 11, 2022 16:59
Load Test Phoenix Presence

Phoenix Nodes

First I created 3 droplets on digital ocean with 4-cores and 8GB of RAM. Login as root to each and run:

sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 4000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
@mmmries
mmmries / 0-README.md
Last active August 10, 2017 20:35
protobuf benchmarking

Protobuf Benchmarking

A really basic protobuf benchmark comparing the protobuf encoding/decoding performance. For details please see the benchmark.rb file in this gist and check the gpb benchmark files.

Latest Results

  • protobuf-3.6.12
  • gpb-3.26.6