Skip to content

Instantly share code, notes, and snippets.

Dave Cottlehuber dch

Block or report user

Report or block dch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
maxlapshin / systemd.erl
Last active Aug 3, 2019
Systemd support
View systemd.erl
% This is what you need to adopt systemd in erlang
% Do whatever you want license. If you want, you can take this code under terms of MIT license.
-export([ready/0, reloading/0, stopping/0, watchdog/0]).
-export([init/1, handle_info/2, terminate/2]).
View gist:af9abf6b3600d2d7f08dba58fdfb514a
Originally from:
For a safe and fast Erlang SSL server, there's a few
configuration values you might want by default:
[{ciphers, CipherList}, % see below
{honor_cipher_order, true}, % pick the server-defined order of ciphers
{secure_renegotiate, true}, % prevent renegotiation hijacks
{client_renegotiation, false}, % prevent clients DoSing w/ renegs
{versions, ['tlsv1.2', 'tlsv1.1']}, % add tlsv1 if you must
assafmo /
Last active Jul 8, 2019
Import an archive full of JSONs into CouchDB
#json per line (same result, but for example can use jq to set _id)
7z x -so $1 | jq -c . | couchimport --db mydb --type jsonl
mrallen1 /
Last active Nov 8, 2018
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.

maxim / gh-dl-release
Last active Aug 17, 2019
Download assets from private Github releases
View gh-dl-release
#!/usr/bin/env bash
# gh-dl-release! It works!
# This script downloads an asset from latest or specific Github release of a
# private repo. Feel free to extract more of the variables into command line
# parameters.
jeffweiss / mix.exs
Last active Dec 18, 2018
Retrieving application version number in mix.exs from git describe
View mix.exs
defmodule MyApp.Mixfile do
use Mix.Project
def project do
[app: :my_app,
version: get_version,
elixir: "~> 1.0",
elixirc_paths: elixirc_paths(Mix.env),
compilers: Mix.compilers,
build_embedded: Mix.env == :prod,
View openssh.erl
#!/usr/bin/env escript
main([Port]) ->
{ok, _} = application:ensure_all_started(ssh),
View gist:3a2e355354e7f19066a0
## Enable kernel poll and a few async threads
+K true
+A 5
+Q 64000
+P 128000
+sbt db
+sbwt very_long
+swt very_low
+sub true
+Mulmbcs 32767
denji /
Last active Jul 11, 2019
Install unbound DNS(SEC) resolver on OS X, on the basis of
To install unbound you can use homebrew
$ brew install unbound ldns
Now we can edit the configuration file of unbound which by default is located in /usr/local/etc/unbound/unbound.conf:
brendangregg /
Last active Aug 4, 2019
some FS micro-benchmarks

F1. FS 128k streaming writes

Benchmark: fio write

Command: fio --name=seqwrite --rw=write --bs=128k --size=4g --end_fsync=1 --loops=4 # aggrb tput

Rationale: Measure the performance of a single threaded streaming write of a reasonably large file. The aim is to measure how well the file system and platform can sustain a write workload, which will depend on how well it can group and dispatch writes. It's difficult to benchmark buffered file system writes in both a short duration and in a repeatable way, as performance greatly depends on if and when the pagecache begins to flush dirty data. As a workaround, an fsync() at the end of the benchmark is called to ensure that flushing will always occur, and the benchmark also repeats four times. While this provides a much more reliable measurement, it is somewhat worst-case (applications don't always fsync), providing closer to a minimum rate – rather than a maximum rate – that you should expect.

F2. FS cached 4k random reads

You can’t perform that action at this time.