Skip to content

Instantly share code, notes, and snippets.

@iain17
iain17 / backup-containers.sh
Created January 5, 2021 10:51
Backup docker containers
#!/bin/bash
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
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;
private:
std::future<T> _promise;
@iain17
iain17 / solution.java
Created September 28, 2017 00:04
Hackerrank contacts problem
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static class Node {
public Character value;
@iain17
iain17 / readme.md
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
iain17 / harddisk.md
Created August 6, 2017 19:42
move var directory to different disk
  1. Find the disk

lsblk

2.Then create a filesystem on it

sudo mkfs.ext4 /dev/vdb
@iain17
iain17 / k8s.sh
Last active June 29, 2017 19:22
Rancher little snippets
#SSH into the machine
ssh -i "aws-rancher.pem" rancher@ec2-00-158-000-000.eu-central-1.compute.amazonaws.com
#To switch to a Docker version supported by k8s.
#http://rancher.com/docs/rancher/v1.6/en/hosts/#supported-docker-versions
sudo ros engine switch docker-1.12.6
#Install Rancher
#http://rancher.com/docs/rancher/v1.6/en/installing-rancher/installing-server/
sudo docker run -d -v /home/rancher/mysql:/var/lib/mysql --restart=unless-stopped -p 8080:8080 rancher/server
@iain17
iain17 / instructions.md
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@8.8.4.4 -D 9050

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

  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
iain17 / problem1.erl
Last active April 8, 2017 11:55
Project euler erlang problems.
-module(problem1).
-export([solve/0]).
%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 ->
Sum;

Usage

c(translate_service).
c(doctor_translate).

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

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

Usage

c(translate_service).
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").