Skip to content

Instantly share code, notes, and snippets.

View gnilchee's full-sized avatar

Greg Nilchee gnilchee

  • Evernote
  • Woodinville, WA
View GitHub Profile
@gnilchee
gnilchee / get_request_url.go
Created January 4, 2017 07:01
Get content and status code of headers and body and print to screen. Url is pulled from commandline arguments
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
@gnilchee
gnilchee / simple_http_server.go
Last active January 4, 2017 02:40
Simple http server using redirect handlers and func handlers via mux (no external middleware)
package main
import (
"log"
"net/http"
"io"
"fmt"
)
func main() {
@gnilchee
gnilchee / Vagrantfile
Created December 19, 2016 05:20
Vagrantfile to create a drbd cluster
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "db1" do |db1|
db1.vm.box = "centos/6"
db1.vm.hostname = "db1"
end
@gnilchee
gnilchee / simple_check.sh
Created October 31, 2016 03:49
a simple check to register passing, warn, critical, with consul using http api
#!/usr/bin/env bash
# Assign service variables
CONSUL_URL=
CHECK_ENDPOINT=
CONSUL_DC="dc1"
NODE_NAME="$(hostname -f)"
NODE_ADDRESS="$(hostname -I| awk '{print $1}')"
SERVICE_ID="Redis1"
SERVICE_NAME="Redis"
@gnilchee
gnilchee / docker-compose-consul.yml
Created October 28, 2016 06:04
Stand up a single node consul server and export ui/api over port 80 and consul dns over port 53
version: '2'
services:
consul:
image: consul
volumes:
- ./data/consul:/consul/data
command: /bin/consul agent -server -data-dir="/consul/data" -bootstrap -client="0.0.0.0" -advertise="127.0.0.1" -ui
ports:
- 80:8500 #HTTP API/UI
- 53:8600/udp #DNS
@gnilchee
gnilchee / Dockerfile
Last active October 23, 2016 01:23
Modifying Alpine image to use glibc.
FROM alpine:latest
RUN ALPINE_GLIBC_VERSION="latest" && \
ALPINE_GLIBC_REPO="sgerrand" && \
ALPINE_GLIBC_PROJ="alpine-pkg-glibc" && \
apk add --update -t deps ca-certificates wget curl && \
cd /tmp && \
wget $(curl -s https://api.github.com/repos/$ALPINE_GLIBC_REPO/$ALPINE_GLIBC_PROJ/releases/$ALPINE_GLIBC_VERSION | grep 'browser_' | egrep 'glibc-.*.apk' | cut -d\" -f4) && \
apk add --allow-untrusted glibc-*.apk && \
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 C.UTF-8 || true && \
@gnilchee
gnilchee / MySQL_memory
Created October 20, 2016 21:37
Select statement to get total memory usage
select @@GLOBAL.KEY_BUFFER_SIZE + @@GLOBAL.INNODB_BUFFER_POOL_SIZE + @@GLOBAL.INNODB_LOG_BUFFER_SIZE + @@GLOBAL.INNODB_ADDITIONAL_MEM_POOL_SIZE + @@GLOBAL.NET_BUFFER_LENGTH + (@@GLOBAL.SORT_BUFFER_SIZE + @@GLOBAL.MYISAM_SORT_BUFFER_SIZE + @@GLOBAL.READ_BUFFER_SIZE + @@GLOBAL.JOIN_BUFFER_SIZE + @@GLOBAL.READ_RND_BUFFER_SIZE) * @@GLOBAL.MAX_CONNECTIONS AS TOTAL_MEMORY_SIZE\G
select (@@GLOBAL.KEY_BUFFER_SIZE + @@GLOBAL.INNODB_BUFFER_POOL_SIZE + @@GLOBAL.INNODB_LOG_BUFFER_SIZE + @@GLOBAL.INNODB_ADDITIONAL_MEM_POOL_SIZE + @@GLOBAL.NET_BUFFER_LENGTH + (@@GLOBAL.SORT_BUFFER_SIZE + @@GLOBAL.MYISAM_SORT_BUFFER_SIZE + @@GLOBAL.READ_BUFFER_SIZE + @@GLOBAL.JOIN_BUFFER_SIZE + @@GLOBAL.READ_RND_BUFFER_SIZE) * @@GLOBAL.MAX_CONNECTIONS)/1024/1024/1024 AS TOTAL_MEMORY_SIZE_gb\G
@gnilchee
gnilchee / tcpdump
Created October 20, 2016 21:35
Simple way to view all unencrypted MySQL traffic from client host
tcpdump -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}' | tee -a /tmp/out.txt
@gnilchee
gnilchee / simple_auth.py
Created October 11, 2016 06:40
flask simple auth
#!/usr/bin/env python3
from functools import wraps
from flask import Flask, request, Response, jsonify
app = Flask(__name__)
def check_auth(username, password):
return username == 'admin' and password == 'sECreTpassW0Rd'
def authenticate():
return Response(
@gnilchee
gnilchee / atlas.py
Created October 8, 2016 05:24
simple flask app
#!/usr/bin/env python3
from flask import Flask,request,jsonify
app = Flask(__name__)
@app.route('/')
def default_rt():
return 'Welcome to the Atlas API'
@app.route('/ip', methods=["GET"])