Skip to content

Instantly share code, notes, and snippets.

View anapsix's full-sized avatar
😺

Anastas Dancha anapsix

😺
View GitHub Profile
@anapsix
anapsix / kinesis_consumer.php
Created December 15, 2017 17:08
Kinesis Consumer in PHP with AWS SDK
<?php
// if running in Alpine, install the following
// apk -U add php7 php7-mbstring php7-simplexml php7-json php7-phar php7-openssl curl
// curl -sS https://getcomposer.org/installer | php
// php composer.phar require aws/aws-sdk-php
//
// export AWS_ACCESS_KEY_ID=...
// export AWS_SECRET_ACCESS_KEY=...
if (getenv('KINESIS_STREAM')) {
$streamName = getenv('KINESIS_STREAM');
@anapsix
anapsix / getting_ips_in_Javascript_and_CoffeeScript.md
Created December 22, 2017 13:09
How to get interface IP in JavaScript/NodeJS and CoffeeScript

JavaScript

function getInterfaceIPv4(iface) {
  var iface_info = os.networkInterfaces()[iface];
  var addresses = [];
  //console.log(iface_info);
  for (var k in iface_info) {
    var address = iface_info[k];
    //console.log(address);
 if (address.family === 'IPv4') {
@anapsix
anapsix / check_http.sh
Created January 9, 2018 09:20
Check URL and return timing, http code, number of redirects, and effective url
#!/usr/bin/env bash
#
# returns the following
# [curl exit code],[total request time],[http response code],[number of redirects],[effective url]
#
if [[ ${1} == '' ]]; then
echo >&2 'missing URL to check'
echo >&2 "Usage: $0 google.com"
exit 1
@anapsix
anapsix / lockcreen.md
Created February 8, 2018 15:18
lockscreen command line utility on mac

Make a lockscreen CLI utility on your Mac

ATTENTION: use at your own risk, no warranty of any kind This seems to work in High Sierra, but may break in future versions

cat > /tmp/lockscreen.c <<EOF
// lockscreen.c
extern void SACLockScreenImmediate();
int main()
{
@anapsix
anapsix / export_route53_zone.sh
Created March 5, 2018 12:17
export route53 in BINDish format
#!/bin/bash
case $1 in
--name)
shift
zonename="$1"
hostedzoneid=($(aws route53 list-hosted-zones | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3))
if [ ${#hostedzoneid[@]} -eq 0 ]; then
echo >&2 "Could not find Route53 zone for \"$zonename\", exiting.."
exit 1
@anapsix
anapsix / check_dns.sh
Created April 1, 2018 11:14
Watch for DNS changes and reload NGINX (or do something else)
#!/usr/bin/env bash
#
## example running it from cron
# MAILTO=""
# SHELL=/bin/bash
# VERBOSE=1
# CMD_ON_FAILURE='/etc/init.d/nginx reload'
# * * * * * root timeout -k 2 5 /tmp/check_dns.sh upstream.server.com 2>>/var/log/check_dns.log
# * * * * * root sleep 10 && sed -e :a -e '$q;N;501,$D;ba' -i /var/log/check_dns.log
#
@anapsix
anapsix / rmq_passwd_hash.py
Created May 22, 2018 19:33
generate RabbitMQ compatible SHA256 password hash
#!/usr/bin/env python
# details on rabbitMQ password hashing
# https://www.rabbitmq.com/passwords.html#computing-password-hash
from __future__ import print_function
import base64
import os
import hashlib
import struct
import getpass
@anapsix
anapsix / helm_tls_wrapper.sh
Last active October 28, 2020 02:43
Helm CLI wrapper making it easier to work with multiple clusters when using TLS-enabled Tiller
#!/usr/bin/env bash
#
# this script is a helpful wrapper for Helm CLI, when using TLS enabled Tiller
# See https://github.com/helm/helm/blob/master/docs/tiller_ssl.md
#
# === NOTE ===
# It will attempt to download Helm binary to match Helm Server version
# if it's not found locally
#
# === INSTRUCTIONS ===
@anapsix
anapsix / cronjob_with_exec_timeout.yaml
Last active March 30, 2023 19:51
K8s CronJob with execution timeout implemented via livenessProbe
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: do-something-job
namespace: scheduled-tasks
spec:
schedule: "*/2 * * * *"
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
@anapsix
anapsix / kubectl_with_ssh_jumphost.sh
Last active September 30, 2019 12:09
Wrapper for kubectl to automatically establish SSH connection to jumphost, though which to proxy requests to K8s API
#!/usr/bin/env bash
#
# DEPRECATED
# use k8s-vault instead
# https://gist.github.com/anapsix/b5af204162c866431cd5640aef769610
#
#
# Wrapper for kubectl to establish SSH connection to jumphost,
# though which to proxy requests to K8s API
#