Skip to content

Instantly share code, notes, and snippets.

View erszcz's full-sized avatar

Radek Szymczyszyn erszcz

View GitHub Profile

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@erszcz
erszcz / node-name.sh
Last active October 1, 2018 10:00
Sequential Erlang node name based on EPMD entries
#!/usr/bin/env bash
# file: node-name.sh
set -eu
PREFIX=history
MAXNODES=100
DEFAULT=${PREFIX}_$(uuidgen | sed 's/-//g')
@erszcz
erszcz / ct_helper.erl
Last active May 7, 2018 13:38
Erlang Common Test helper defining test-local setup/teardown
-module(ct_helper).
-compile([export_all]).
%% @doc Like ct:get_config/1, but calls error/1 if Key is not found / undefined.
%% This guarantees to fail fast if required config options are missing from
%% the config file, saving trouble with `undefined` value propagation.
%% Use alongside with the CT `require` mechanism.
%% See s2s_SUITE for an example.
-spec get_config(atom()) -> any().
@erszcz
erszcz / agent.erl
Last active March 9, 2018 10:10
Remotely load code into an Erlang node
-module(agent).
-compile([export_all]).
test(CallerPid) ->
CallerPid ! {agent, node(), self()}.
@erszcz
erszcz / docker.fix-network
Created November 9, 2017 16:06
Fix Docker4Mac container routeability (steps needed every host VM restart)
#!/usr/bin/env bash
## Make Docker4Mac containers routable in a private network.
## This is mostly a copy-paste from the original solution.
## IT'S NOT A COMPLETE SOLUTION - this script only does the
## steps necessary every time Docker4Mac is restarted.
## Beforehand, you have to run the steps marked as ONCE yourself.
## See https://github.com/docker/for-mac/issues/155#issuecomment-320509769
set -e
@erszcz
erszcz / kerl-install-docsh.log
Created October 25, 2017 16:25
kerl install-docsh log
Last login: Wed Oct 25 18:19:04 on ttys005
e18:20:30 erszcz @ x4 : ~
$ erl
-bash: erl: command not found
18:20:30 erszcz @ x4 : ~
$ . ~/apps/erlang/19.3.6.2/activate
18:20:41 erszcz @ x4 : ~
$ erl
Erlang/OTP 19 [erts-8.3.5.2] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
@erszcz
erszcz / docs-chunk-design.md
Last active June 24, 2017 01:29
Docs chunk design

Docs chunk format proposal

Let's first look at some elixir_docs_v1 examples (Erlang syntax). The general chunk structure (from GenServer) is:

{elixir_docs_v1,
    [{docs,
         [{{'__using__',1},539,defmacro,[{'',[],'Elixir'}],false},
          {{abcast,3},
@erszcz
erszcz / cVimrc
Last active February 3, 2017 11:28
cVim config file
" d closes a tab
map d closeTab
" C-d/C-u scrolls down/up
map <C-d> scrollPageDown
map <C-u> scrollPageup
" M-§ / A-§ switch to previous active tab / last used tab
map <M-§> lastUsedTab
map <A-§> lastUsedTab
@erszcz
erszcz / my_tracer.erl
Last active March 25, 2016 16:08
Monitored tracer process
-module(my_tracer).
-compile([export_all]).
-define(il2b, iolist_to_binary).
%% Listen carefully, since I won't repeat.
%%
%% Default dbg:dhandler/2 is nice,
%% but when you want to use domain knowledge
@erszcz
erszcz / exml_assert.hrl
Last active March 11, 2016 09:53
XML element equality assertion ignoring attribute / subelement ordering (using https://github.com/esl/exml data structures)
%% See assertEqual in $ERLANG/lib/stdlib-2.6/include/assert.hrl for the original.
-define(exmlAssertEqual(Example, Expr),
begin
((fun (__X, __V) ->
case __V of
__X -> ok;
__V -> erlang:error({exmlAssertEqual,
[{module, ?MODULE},
{line, ?LINE},
{expression, (??Expr)},