Skip to content

Instantly share code, notes, and snippets.

View Gazler's full-sized avatar

Gary Rennie Gazler

View GitHub Profile
#!/bin/bash
###
### my-script — does one thing well
###
### Usage:
### my-script <input> <output>
###
### Options:
### <input> Input file to read.
### <output> Output file to write. Use '-' for stdout.
@astery
astery / mix_test_summary.sh
Created September 15, 2017 12:24
Bash script which add summary after running `mix tests` in umbrella root
#!/usr/bin/env bash
set +m
shopt -s lastpipe
app_name="unknown"
declare -A app_tests
declare -A app_fails
declare -A app_warnings
declare -A app_errors
@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'
@bitwalker
bitwalker / config.ex
Created July 19, 2016 23:00
Useful config wrapper for Elixir
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
@josevalim
josevalim / watcher.sh
Last active February 28, 2024 07:42
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | mix test --stale --listen-on-stdin
@jadeallenx
jadeallenx / discussion.md
Last active April 21, 2023 17:13
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.

@andreicristianpetcu
andreicristianpetcu / ansible-summary.md
Created May 30, 2016 19:25
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)

Configuration file

intro_configuration.html

First one found from of

@aaronjensen
aaronjensen / drain_stop.ex
Last active November 28, 2022 06:59
Phoenix Drain Stop
# ATTENTION: This is now supported in plug_cowboy as of 2.1.0:
# https://hexdocs.pm/plug_cowboy/Plug.Cowboy.Drainer.html
defmodule DrainStop do
@moduledoc """
DrainStop Attempts to gracefully shutdown an endpoint when a normal shutdown
occurs. It first shuts down the acceptor, ensuring that no new requests can be
made. It then waits for all pending requests to complete. If the timeout
expires before this happens, it stops waiting, allowing the supervision tree
to continue its shutdown order.
@henrik
henrik / say_when.exs
Last active September 7, 2016 09:03
Example of using "guard clauses" in your own code with Elixir macros. Inspired by `plug :foo when action in [:create, :update]`. This implementation accepts any types of conditions, not just the subset allowed in actual guard clauses. But also see https://gist.github.com/henrik/68f136f9916165e0defb for an implementation with real guard clauses.
defmodule Lab do
defmacro say({:when, _, [message, condition]}) do
{result, _} = Code.eval_quoted(condition)
if result do
quote do
IO.puts unquote(message)
end
end
end
def update_company(company, company_params) do
changeset = Company.changeset(company, company_params)
if Ecto.Changeset.fetch_change(changeset, :shortname) != :error do
Logger.debug "Shortname changed"
#TODO dont allow shortname change if shortname is in use in video addresses
:ok
end
Repo.transaction( fn ->
case Repo.update(changeset) do