Skip to content

Instantly share code, notes, and snippets.

View danielkza's full-sized avatar

Daniel Miranda danielkza

  • Vonage
  • London, United Kingdom
View GitHub Profile
@danielkza
danielkza / gzip-cont.sh
Last active November 11, 2022 13:54
Incrementally gzip a file (such as a log). Each call will append only new bytes from the input to the output.
#!/bin/bash
# Usage: gzip-cont {in_file} {out_file} {gzip_args...}
set -e -o pipefail
in="$1"
out="$2"
shift 2
@danielkza
danielkza / Dockerfile
Created January 5, 2018 21:54
Bors-NG Docker setup
ARG ELIXIR_VERSION=1.4.5
FROM elixir:${ELIXIR_VERSION} as builder
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update -q && apt-get install -y build-essential libtool autoconf curl
RUN DEBIAN_CODENAME=$(sed -n 's/VERSION=.*(\(.*\)).*/\1/p' /etc/os-release) && \
curl -q https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
@danielkza
danielkza / zfs-root-fs-generator.sh
Last active August 20, 2017 10:30
ZFS root systemd generator
#!/bin/sh
generator_dir="$1"
list_datasets() {
/usr/sbin/zfs list -r -H -o name,canmount,mountpoint "$1"
}
get_root_zfs_dataset() {
while read mnt_dev mnt_path mnt_type rest; do

Keybase proof

I hereby claim:

  • I am danielkza on github.
  • I am danielkza (https://keybase.io/danielkza) on keybase.
  • I have a public key whose fingerprint is B797 986C 9753 D44F 0477 32D0 0790 9306 308D 7399

To claim this, I am signing this object:

@danielkza
danielkza / heartbeat.clj
Created March 15, 2017 17:44
Riemann heartbeat with continuous alerting (with exponential backoff time)
(defn- heartbeat-bounce
[alpha min-ttl max-ttl & children]
(fn [event]
(let [ttl (max min-ttl (:ttl event))
ttl (min max-ttl (* alpha ttl))]
(call-rescue (assoc event :ttl ttl :time (unix-time)) children))))
(defn- heartbeat-process
[svc desc index bounce & children]
(fn [event]
(require '[clojure.java.io :as io]
'[clojure.tools.logging :refer [infof]]
'[riemann.common :refer [encode decode-inputstream]]
'[riemann.config :refer [service!]]
'[riemann.service :refer [thread-service]]
'[riemann.time :refer [unix-time]])
(import '[java.io.File FileOutputStream])
(defn index-save
[file index]
@danielkza
danielkza / reddit-update-filters.py
Created December 3, 2016 19:18
Python3 script to synchronize Reddit /r/all filters from a list file
#!/bin/env python3
# Copyright (c) 2016, Daniel Miranda <danielkza2@gmail.com>
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
@danielkza
danielkza / ipsec
Created November 29, 2016 13:54
Strongswan IPSec init script with UCI support
#!/bin/sh /etc/rc.common
START=90
STOP=10
NAME=ipsec-uci
USE_PROCD=1
IPSEC_BIN=/usr/sbin/ipsec
IPSEC_SECRETS=/var/run/ipsec/ipsec.secrets
@danielkza
danielkza / lambda.py
Last active October 19, 2016 20:45
Stacker hook for uploading lambda functions
import os
import os.path
import fnmatch
import stat
import logging
import hashlib
from StringIO import StringIO
from zipfile import ZipFile, ZIP_DEFLATED
import boto3
$ PROFILE_NUM_RUNS=3 command time -v ruby performance/tests/aggregation.rb
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.x-compliant syntax, but you are running 2.3.0.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Profiling Performance::Aggregation
Setup: start
Created 1023 ModuleResults and 4096 MetricResults
Setup: finish
Run 1: start
Run 1: finish