Skip to content

Instantly share code, notes, and snippets.

@xinau
xinau / image.json
Created January 20, 2019 14:37
packer inspec.io docker target
{
"variables": {
"host": "default"
},
"builders": [
{
"type": "docker",
"image": "debian:latest",
"commit": "true",
"run_command": [
@xinau
xinau / canvas.html
Last active March 22, 2020 11:06
d3.js horizon chart standalone
<!doctype html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="graph"></div>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
(async () => {
overlap = 5
@xinau
xinau / Dockerfile
Last active November 12, 2022 05:35
configuring mtail as a node-level logging-agent on kubernetes
FROM debian:stable AS builder
ENV MTAIL_VERSION=3.0.0-rc33
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl && \
curl -LsS -O https://github.com/google/mtail/releases/download/v${MTAIL_VERSION}/mtail_v${MTAIL_VERSION}_linux_amd64 && \
mv mtail_v${MTAIL_VERSION}_linux_amd64 /usr/bin/mtail && \
chmod 755 /usr/bin/mtail
@xinau
xinau / main.tf
Created April 6, 2020 23:25
Terraform resources for a remote backend on AWS using a S3 bucket (with logging and enforced server side encryption) and a DynamoDB table.
variable bucket {
description = "AWS S3 bucket name to use for state storage"
type = string
}
variable dynamodb_table {
description = "AWS DynamoDB table name to use for state locking"
type = string
}
@xinau
xinau / packer.json
Created April 13, 2020 21:17
Building docker images using packer and ansible
{
"variables": {
"host": "default",
},
"builders": [
{
"type": "docker",
"image": "debian:9.6",
"commit": true,
"run_command": [
@xinau
xinau / main.go
Created May 7, 2020 11:38
script for geneareting a flat-file database on github repositories and releases
package main
import (
"context"
"fmt"
"os"
"github.com/google/go-github/v31/github"
"golang.org/x/oauth2"
)
@xinau
xinau / tfinist.sh
Created May 20, 2020 09:42
terraform init wrapper - backend switch and environment name export.
#!/usr/bin/env bash
#
# This script is used for configuring terraform and it's remote state backend
# for a specific environment. This is done by sourcing a backend config in the
# `dev` folder under the git root directory. Note that the backend config file
# name needs to end with a `.hcl` extension and the file basename is used as
# the environment name provided. It also sets a `TF_VAR_envname` with the
# environment name as value.
#
# For distinguishing the different environments the script also sets `PS1`.
@xinau
xinau / main.go
Last active May 22, 2020 12:04
CountFunc and SplitNFunc for byte arrays in golang
package main
import (
"bytes"
"fmt"
)
func CountFunc(s []byte, f func(rune) bool) int {
n := 0
for i := 0; i < len(s); i++ {
@xinau
xinau / domain.sh
Created February 5, 2021 09:07
script for getting available domains based on the filesysetm layout
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# sudo ./domains.sh | tee domains.txt | awk '/AVAILABILITY_AVAILABLE$/ {print $1}'
structs=$(find / -maxdepth 2 -mindepth 2 \
| grep -E "^/(media|run|dev)" \
| grep -v -E "(_|\.)" \
@xinau
xinau / prometheus.py
Last active July 1, 2024 07:56
Ansible callback plugin for exposing playbook execution statistics to Prometheus
# (c) 2018 xinau <[email protected]>
# GNU General Public License v3.0+ (see https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
callback: prometheus
callback_type: aggregate
short_description: expose playbook stats to as Prometheus metrics.