Skip to content

Instantly share code, notes, and snippets.

View tomazzaman's full-sized avatar

Tomaž Zaman tomazzaman

  • Mono Technologies Inc.
  • Slovenia
View GitHub Profile
@tomazzaman
tomazzaman / config.py
Created July 1, 2016 20:36
Set configuration files with Jinja2
#!/usr/bin/env python
import os
import sys
from jinja2 import Environment, FileSystemLoader
def set_environment(template_dir):
env = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True)
env.globals['env_var'] = lambda varname, default='': os.getenv(varname, default)
env.globals['exists'] = lambda varname: varname in os.environ
@tomazzaman
tomazzaman / etcd.yml
Created September 14, 2016 07:59
Etcd Kubernetes DaemonSet
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
labels:
name: etcd
name: etcd
spec:
template:
metadata:
labels:
@tomazzaman
tomazzaman / postgresql
Created September 20, 2016 11:43
PostgreSQL health check through xinetd (with repmgr)
# description: An xinetd service to show PSQL status
# put this file into /etc/xinetd.d
service postgrescheck
{
type = UNLISTED
flags = REUSE
wait = no
disable = no
socket_type = stream
protocol = tcp
@tomazzaman
tomazzaman / api.js
Created September 26, 2016 15:10
API middleware for redux
import superagent from 'superagent';
import { merge } from 'lodash';
import { camelizeKeys, decamelizeKeys } from 'humps';
import config from 'config';
const CALL_API = Symbol.for('Call API');
export const GENERIC_ERROR = 'GENERIC_ERROR';
const genericErrors = {
400: 'You\'ve attempted to make a request the server didn\'t expect',
kind: Endpoints
apiVersion: v1
metadata:
name: glusterfs
subsets:
- addresses:
# Change the following to match your GlusterFS instance IPs
- ip: 10.132.0.5
- ip: 10.132.0.6
ports:
@tomazzaman
tomazzaman / pushover.sh
Created September 11, 2022 10:41
Messaging script for pushover.net
#!/usr/bin/env bash
# Messaging script for pushover.net (make sure you have an account)
# put this somewhere in your $PATH and make it executable
if [ $# -eq 0 ]; then
echo "Usage: pushover <title> <message>"
echo "Example: $ pushover \"This is the title\" \"This is a nice message\""
exit
fi
@tomazzaman
tomazzaman / README.md
Created May 24, 2023 19:58
Simple Active Storage direct upload form with a Stimulus controller

Title pretty much sums it up. I wanted it to support drag and drop as well, which is why the .droparea is positioned absolutely; It's below the input field and the field itself gets its opacity set to 0, for better UX experience.

@tomazzaman
tomazzaman / resolver.sh
Created January 2, 2025 17:39
Automatically add hostnames to Pihole whenever containers get updated
#!/bin/sh
#
# Update Pihole's custom.list based on the "hostname" property of a container.
#
# Environment variables
# - OVERRIDE_IP sets the IP of the container in Pihole's DNS records. Defaults to container IP in Docker network.
# - DOMAIN_FILTER only triggers the updates on a match. If empty, it'll always update the records file.
# - PIHOLE_CUSTOM_LIST_FILE /etc/hosts compatible DNS records file in format "IP hostname".
# - PIHOLE_CONTAINER_NAME because we need to reload Pihole's internal resolver when making changes
#