Skip to content

Instantly share code, notes, and snippets.

iain17 /
Created January 5, 2021 10:51
Backup docker containers
mkdir containers | true
containers=`docker ps -a -q | sed -z 's/\n/ /g'`
echo "Backing up $containers"
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose $containers > "containers/$(date +"%Y_%m_%d_%I_%M_%p").docker-compose.yml"
iain17 / await.cpp
Last active December 16, 2017 01:48
Simple C++ async promise class using std::async
#include <future>
template <class T>
class Promise {
typedef std::function<T(Promise*)> Job;
typedef std::function<void(T)> resultCallback;
typedef std::function<void(std::string)> failCallback;
typedef std::function<void()> finallyCallback;
std::future<T> _promise;
iain17 /
Created September 28, 2017 00:04
Hackerrank contacts problem
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static class Node {
public Character value;
iain17 /
Created August 7, 2017 01:36
centos iptables keeps resetting

FirewallD is frontend controller for iptables used to implement persistent network traffic rules. It provides command line and graphical interfaces and is available in the repositories of most Linux distributions. Working with FirewallD has two main differences compared to directly controlling iptables:

FirewallD uses zones and services instead of chain and rules. It manages rulesets dynamically, allowing updates without breaking existing sessions and connections.

If you are like me, this stupid preinstalled service might be blocking you. Stop and disable it by doing:

sudo systemctl stop firewalld
sudo systemctl disable firewalld
iain17 /
Created August 6, 2017 19:42
move var directory to different disk
  1. Find the disk


2.Then create a filesystem on it

sudo mkfs.ext4 /dev/vdb
iain17 /
Last active June 29, 2017 19:22
Rancher little snippets
#SSH into the machine
ssh -i "aws-rancher.pem"
#To switch to a Docker version supported by k8s.
sudo ros engine switch docker-1.12.6
#Install Rancher
sudo docker run -d -v /home/rancher/mysql:/var/lib/mysql --restart=unless-stopped -p 8080:8080 rancher/server
iain17 /
Last active July 6, 2017 08:30
Terminal use proxy (Socks proxy to HTTP proxy)
  1. Setup your socks proxy. In my case I'm creating a socks proxy by creating a secure shell connection (SSH): ssh iain@ -D 9050

  2. (Optional for mac users): You can also simplify this action by using a lovely (free) application called Secure Pipes:

  3. Download delegate and move the executable (dg9_9_13) into /usr/local/sbin or /usr/bin. Example:

cp dg9_9_13/DGROOT/bin/dg9_9_13 /usr/local/sbin/delegate
chmod +x /usr/local/sbin/delegate
iain17 / problem1.erl
Last active April 8, 2017 11:55
Project euler erlang problems.
%Assignment: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
%Find the sum of all the multiples of 3 or 5 below 1000.
solve() ->
solve(1, 0).
solve(Number, Sum) when Number == 1000 ->



Doctor = spawn(fun doctor_translate:watch/0).
Doctor ! new.

translate_service:translate(translator, "casa").
translate_service:translate(translator, "blanca").


Service = spawn(fun translate_service:watch_loop/0).
Service ! new.
translate_service:translate(translator, "casa").
translate_service:translate(translator, "blanca").
translate_service:translate(translator, "incorrect").
translate_service:translate(translator, "casa").