Skip to content

Instantly share code, notes, and snippets.

@serverabuse
serverabuse / bash_strict_mode.md
Created September 22, 2021 14:35 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -x, -o pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@serverabuse
serverabuse / .vimrc
Last active October 20, 2020 18:20
.vimrc
" Pathogen Installation
call pathogen#infect()
" Stylish changes
filetype plugin indent on
syntax on
" colorscheme gotham256
colorscheme Atelier_DuneLight
" colorscheme Atelier_CaveDark
" colorscheme elflord
@serverabuse
serverabuse / inotify.sh
Last active April 8, 2020 16:58
inotify s3 sync
#!/bin/bash
watchdir=/home/vagrant
logfile=/home/vagrant/watcher.log
while : ; do
inotifywait $watchdir|while read path action file; do
ts=$(date +"%C%y%m%d%H%M%S")
echo "$ts :: file: $file :: $action :: $path">>$logfile
if [[ $action == "CREATE,ISDIR" || $action == "CREATE" || $action == "DELETE" || $action == "MODIFY" ]]; then
aws s3 sync s3://$TARGET_BUCKET $watchdir
@serverabuse
serverabuse / script-template.py
Last active April 8, 2020 16:58
python script template
#!/usr/bin/env python
"""A simple python script template.
"""
from __future__ import print_function
import os
import sys
import argparse
@serverabuse
serverabuse / docker-elk
Last active April 8, 2020 16:57
Create ELK stack
#!/bin/bash
docker network create elastic
docker run -d --network elastic -p 9200:9200 -p 9300:9300 --name elasticsearch --restart=always -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.4.0
docker run -d --network elastic --name apm-server --restart=always -p 8200:8200 --user root -v /home/ec2-user/apm-server.docker.yml:/usr/share/apm-server/apm-server.yml:ro -e output.elasticsearch.hosts=["elasticsearch:9200"] docker.elastic.co/apm/apm-server:7.4.0
docker run -d -p 5601:5601 --name kibana --network elastic --restart=always -v /home/ec2-user/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.4.0
@serverabuse
serverabuse / swagger-yaml-to-html.py
Last active April 7, 2021 11:12
swagger-yaml-to-html.py
#!/usr/bin/python
"""
Usage:
python swagger-yaml-to-html.py < /path/to/api.yaml > doc.html
"""
import yaml, json, sys
TEMPLATE = """
@serverabuse
serverabuse / logstash-pattern-core
Last active April 8, 2020 16:56
logstash-pattern-core
USERNAME [a-zA-Z0-9._-]+
USER %{USERNAME}
EMAILLOCALPART [a-zA-Z][a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILLOCALPART}@%{HOSTNAME}
INT (?:[+-]?(?:[0-9]+))
BASE10NUM (?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))
NUMBER (?:%{BASE10NUM})
BASE16NUM (?<![0-9A-Fa-f])(?:[+-]?(?:0x)?(?:[0-9A-Fa-f]+))
BASE16FLOAT \b(?<![0-9A-Fa-f.])(?:[+-]?(?:0x)?(?:(?:[0-9A-Fa-f]+(?:\.[0-9A-Fa-f]*)?)|(?:\.[0-9A-Fa-f]+)))\b
/* Deleting a node from Binary search tree */
#include<iostream>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
//Function to find minimum in a tree.
Node* FindMin(Node* root)