Skip to content

Instantly share code, notes, and snippets.

Tomaž Zaman tomazzaman

  • Codeable ApS
  • Slovenia
Block or report user

Report or block tomazzaman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View glusterfs-endpoints.yml
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 Sep 26, 2016
API middleware for redux
View api.js
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 Sep 20, 2016
PostgreSQL health check through xinetd (with repmgr)
View postgresql
# 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 Sep 14, 2016
Etcd Kubernetes DaemonSet
View etcd.yml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
labels:
name: etcd
name: etcd
spec:
template:
metadata:
labels:
@tomazzaman
tomazzaman / config.py
Created Jul 1, 2016
Set configuration files with Jinja2
View config.py
#!/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 Aug 21, 2019
Kill supervisor on Docker when any of the services fail
View README.md

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.

View apiMiddleware.js
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 Jan 16, 2016
Generate PNG from a React-powered SVG. Server-side.
View generateSVG.js
/**
* 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';
View policy.js
var crypto = require("crypto");
var SECRET_KEY = 'MY_AWS_SECRET_KEY';
var POLICY_JSON = {
"expiration": "2030-12-01T12:00:00.000Z",
"conditions": [
{"bucket": "my-bucket-name"},
["starts-with", "$key", ""],
{"acl": "public-read"},
["starts-with", "$Content-Type", ""],
@tomazzaman
tomazzaman / runner.js
Created Oct 28, 2015
Fast mocha runner with instrumentation support. Run it with `babel-node runner.js`
View runner.js
import fs from 'fs';
import path, { resolve } from 'path';
import assert from 'assert';
import Module from 'module';
import jsdom from 'jsdom';
import Mocha from 'mocha';
import chokidar from 'chokidar';
import { isMatch } from 'micromatch';
import log from 'fancy-log';
import async from 'async';
You can’t perform that action at this time.