Skip to content

Instantly share code, notes, and snippets.

@baiyongzhen
baiyongzhen / auth.go
Created June 23, 2018 07:18 — forked from jebjerg/auth.go
nginx 2fa authentication layer (lua + Go)
// Swap values for CHANGE FOR YOURSELF, and OBS: it's a novelty authentication, so improvements can and will happen
package main
import (
"bufio"
"crypto/hmac"
"crypto/sha1"
"fmt"
"github.com/craigmj/gototp"
@baiyongzhen
baiyongzhen / elasticsearch_quickstart.py
Created July 4, 2018 01:45 — forked from rwalk/elasticsearch_quickstart.py
Quickstart elasticsearch with Python
#!/usr/bin/python3
# This script is a simple introduction to the python elasticsearch API.
#
# This script will populate an elasticsearch index from a file and then give a simple command line query interface.
# Each line of the input file will be mapped into a JSON document of the form { "text": "my file line..." } and added
# to the index.
#
# You can use Docker to spin up a local elasticsearch instance to play around with, e.g.
# docker run --name elasticsearch -d -p 9200:9200 elasticsearch:latest
#

In this step we'll create a swarm cluster from two nodes. You should've received access to two nodes in AWS.

  1. SSH in to the first node: ssh -i docker_demo.pem ubuntu@IP1
  2. Figure out the internal IP address of the node: ifconfig and check the eth0 address (10.0....)
  3. Initialize the Swarm cluster: `docker swarm init --listen-addr INTERNAL_IP --advertise-addr INTERNAL_IP
  4. Open a new tab and SSH to the other node: ssh -i docker_demo.pem ubuntu@IP2
  5. Check the internal IP of that node: ifconfig and eth0
  6. Join to the cluster with the command the previous command printed out. Before executing the command, you need to the extend it with the --listen-addr and --advertise-addr parameters (using the internal IP of the second node): docker swarm join TOKEN --listen-addr 10.0.... --advertise-addr 10.0..... node1...
  7. Get back to the first node and verify the results: docker node ls
@baiyongzhen
baiyongzhen / Makefile
Created August 12, 2018 06:11 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@baiyongzhen
baiyongzhen / aws.md
Created June 13, 2019 02:09 — forked from colinvh/aws.md
AWS Region Names

Alternative naming schemes for AWS regions

Purpose

The intent is to define terse, standards-supported names for AWS regions.

Schemes

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/vagrant"
config.vm.define :ubuntu do |host|
host.vm.box = "bento/ubuntu-18.04"
#!/bin/bash
set -e
rm -rf /var/lib/apt/lists/*
sed -i 's/archive.ubuntu.com/ftp.daum.net/g' /etc/apt/sources.list
apt-get update -y
...
$num_instances = 3
(1..$num_instances).each do |i|
config.vm.define "node#{i}" do |node|
node.vm.box = "centos/7"
node.vm.hostname = "node#{i}"
ip = "192.168.8.#{i+100}"
node.vm.network "private_network", ip: ip
node.vm.provider "virtualbox" do |vb|
vb.memory = "3072"
version: '3.3'
services:
localstack:
image: localstack/localstack:0.11.3
privileged: true
ports:
- 8080:8080
- 4567:4567 # apigateway
#- 4568:4568 # kinesis
terraform$ tree -l
├── envs
│   ├── dev
│   │   └── env.tf
│   ├── prd
│   │   └── env.tf
│   └── stg
│   └── env.tf
└── modules
├── env-def