Skip to content

Instantly share code, notes, and snippets.

for _x <- 1..100 do
for {name, pid, _type, _whatever} <- Supervisor.which_children(Process.whereis(__MODULE__.Supervisor)) do
{_msg, n } = Process.info(p, :message_queue_len)
IO.puts("#{name}: #{String.duplicate("#", n)}")
end
:timer.sleep(1000)
end
@jamesduncombe
jamesduncombe / gist:40a6dabd9edeca63034c32c4fe453305
Created July 8, 2020 17:40
Find total percentage of containers
$ docker stats --no-stream | awk '{ gsub("%", "", $7); print $7 }' | tail +2 | paste -sd+ - | bc
shasum -b -a 384 assets/static/js/codemirror.min.js | awk '{ print $1 }' | xxd -r -p | base64
@jamesduncombe
jamesduncombe / config.ru
Last active November 13, 2018 12:06
Sinatra basic setup
# Mock app for Timber.io
# Ruby v2.2.1p85
# Sinatra v1.4.7
# Started with just `rackup`
require 'bundler'
Bundler.require
require 'json'
@jamesduncombe
jamesduncombe / amnesia.sh
Last active September 16, 2020 01:08
Amnesia.io bash alias
amn() {
if [ $# -ge 1 -a ! -f $1 ]; then
input=$(cat -)
temp=$(mktemp)
echo $input > $temp
curl -sF "file=@$temp;filename=xyz.$1" https://amnesia.io
rm $temp
elif [ $# -ge 1 -a -f $1 ]; then
curl -sF "file=@$1" https://amnesia.io
else
@jamesduncombe
jamesduncombe / sample new mailbox response.json
Last active September 11, 2020 16:41
Sample response for new mailbox - Letterb.in
{
"email": ":bin_public_id@letterbin.io",
"bin_url": "https://letterbin.io/m/:bin"
}
@jamesduncombe
jamesduncombe / letterbin - stream download attachments.sh
Last active September 11, 2020 16:43
Letterb.in - Stream downloading attachments
curl -s https://letterbin.io/m/:bin_key/stream --no-buffer \
| jq --unbuffered --raw-output '.attachments[0].data' \
| xargs -I {} open "https://letterbin.io/{}"
@jamesduncombe
jamesduncombe / curl download - letterbin.sh
Last active September 11, 2020 16:44
Letterb.in cURL example
curl https://letterbin.io/m/$(curl -s https://letterbin.io/m/:bin/json \
| jq -r '.[0].attachments[0].data') > mydownload
@jamesduncombe
jamesduncombe / sample response.json
Last active September 11, 2020 16:45
Sample letterb.in JSON response
[
{
"to": "2LrV4qq@letterbin.io",
"text": "The text version of the email if it exists or an empty string",
"subject": "Test",
"received": "2016-04-29T14:26:24Z",
"raw_mime": "raw_mime/bf7900f6d3077859ba649ad5b4556512e8de7fc…",
"original_html": "Unmodified HTML from the email OR the raw text version (liable to change)",
"id": "a3e2b1e0-cd13-48a8-bd51-abcf5c99f137",
"html": "Modified HTML of the email - all attachments that were inlined are changed to <img> tags etc",
@jamesduncombe
jamesduncombe / vaultoro api signature.exs
Last active May 5, 2016 14:37
Function for generating the API signature for Vaultoro's API - https://api.vaultoro.com
defmodule Vaultoro do
@doc """
secret = The Vaultoro secret generated along with your API key
endpoint = The full URL that you are requesting (with all params) e.g: https://api.vaultoro.com/1/balance?nonce=9&apikey=_MY_API_KEY_
"""
def signature(secret, endpoint) do
:crypto.hmac(:sha256, secret, endpoint)
|> Base.encode16(case: :lower)
end