Skip to content

Instantly share code, notes, and snippets.

View tomazzaman's full-sized avatar

Tomaž Zaman tomazzaman

  • Codeable ApS
  • Slovenia
View GitHub Profile
@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 / 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
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 / 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',
@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 / 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 / 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 / README.md
Last active April 19, 2024 17:01
Kill supervisor on Docker when any of the services fail

Killing supervisor if any of it's child processes fail

The trick is to only register the listener for events that indicate failure, namely

  • PROCESS_STATE_STOPPED
  • PROCESS_STATE_EXITED
  • PROCESS_STATE_FATAL

Once they do, we should send a SIGQUIT to Supervisor.

import superagent from 'superagent';
import merge from 'lodash/merge';
import { camelizeKeys, decamelizeKeys } from 'humps';
import config from 'config';
const CALL_API = Symbol.for('Call API');
/**
* Prepare headers for each request and include the token for authentication.
* @param {Boolean} token Authentication token
@tomazzaman
tomazzaman / generateSVG.js
Created January 16, 2016 19:33
Generate PNG from a React-powered SVG. Server-side.
/**
* Run this with `babel-node generateSVG.js`
*/
import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import childProcess from 'child_process';
import phantomjs from 'phantomjs';
import im from 'imagemagick';
import tmp from 'tmp';