Skip to content

Instantly share code, notes, and snippets.

@tkhn
tkhn / install_exim4_vim.sh
Created April 25, 2017 13:18
syntax highlighting for exim4.conf
#!/bin/sh
mkdir -p ~/.vim/syntax/
cd ~/.vim/syntax/
wget 'http://www.vim.org/scripts/download_script.php?src_id=2724' -O exim.vim
cat > ~/.vim/filetype.vim <<EOF
au BufNewFile,BufRead exim4.conf setf exim
EOF
@tkhn
tkhn / mysql-replication-stats.sh
Created March 20, 2017 15:53 — forked from edmorley/mysql-replication-stats.sh
MySQL replication catch-up stats script
#!/usr/bin/env bash
# Updated/fixed version of the script from:
# https://www.percona.com/blog/2012/08/29/heres-a-quick-way-to-foresee-if-replication-slave-is-ever-going-to-catch-up-and-when/
delay=60
echo -e "Stats will be output every ${delay}s...\n"
cmd="mysql -e 'show slave status\G' | awk '/Seconds_Behind_Master/ { print \$2 }'"
while sleep $delay; do
@tkhn
tkhn / local.cf
Created February 13, 2017 19:57 — forked from sneak/local.cf
spamassassin config
# datavibe.net spamassassin local config as of 2015-07-17
# Add *****SPAM***** to the Subject header of spam e-mails
rewrite_header Subject *****SPAM*****
# Save spam messages as a message/rfc822 MIME attachment instead of
# modifying the original message (0: off, 2: use text/plain instead)
report_safe 1
add_header all RelaysUntrusted _RELAYSUNTRUSTED_
@tkhn
tkhn / pretty.py
Created February 10, 2017 15:49
Command line tool for pretty printing JSON and Python data structures. Accepts input via stdin or as a quoted command line argument.
#!/usr/bin/env python
# --Installation--
# chmod +x pretty.py
# sudo ln -s ~/pretty.py /usr/bin/pretty
import argparse
import ast
import json
import pprint
@tkhn
tkhn / install_nginx_vim.sh
Last active January 27, 2017 12:15 — forked from 2called-chaos/install_nginx_vim.sh
enable nginx vim syntax highlighting (on Ubuntu/Debian/Centos)
#!/bin/sh
mkdir -p ~/.vim/syntax/
cd ~/.vim/syntax/
wget http://www.vim.org/scripts/download_script.php?src_id=19394 -O nginx.vim
cat > ~/.vim/filetype.vim <<EOF
au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif
EOF
@tkhn
tkhn / sync_container_to_folder.py
Last active December 7, 2016 13:48 — forked from sivel/sync_container_to_folder.py
Sync a remote Rackspace CloadFiles container to a local directory. Works with pyrax v1.7.3, and does not with 1.9.7.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2012 Rackspace
# Copyright 2013 Matt Martz
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
@tkhn
tkhn / proxy.py
Created November 16, 2016 17:30 — forked from bxt/proxy.py
A very basic caching python HTTP proxy server.
# Originally from http://sharebear.co.uk/blog/2009/09/17/very-simple-python-caching-proxy/
#
# Usage:
# A call to http://localhost:80000/example.com/foo.html will cache the file
# at http://example.com/foo.html on disc and not redownload it again.
# To clear the cache simply do a `rm *.cached`. To stop the server simply
# send SIGINT (Ctrl-C). It does not handle any headers or post data.
import BaseHTTPServer
import hashlib
@tkhn
tkhn / curl-ttfb.sh
Created August 12, 2016 16:38 — forked from acdha/curl-ttfb.sh
Use curl to measure and report HTTP response times (pre-, start- and total transfer)
#!/bin/bash
#
# Report time to first byte for the provided URL using a cache buster to ensure
# that we're measuring full cold-cache performance
while (($#)); do
echo $1
curl -so /dev/null -H "Pragma: no-cache" -H "Cache-Control: no-cache" \
-w "%{http_code}\tPre-Transfer: %{time_pretransfer}\tStart Transfer: %{time_starttransfer}\tTotal: %{time_total}\tSize: %{size_download}\n" \
"$1?`date +%s`"
@tkhn
tkhn / nginx.conf
Created August 11, 2016 10:05 — forked from leandromoreira/nginx.conf
nginx.conf optmized for http/2 = HTTPS TLS (ssl)
# command to generate dhparams.pen
# openssl dhparam -out /etc/nginx/conf.d/dhparams.pem 2048
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;
limit_req_status 444;
limit_conn_status 503;
proxy_cache_path /var/lib/nginx/proxy levels=1:2 keys_zone=backcache:8m max_size=50m;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
@tkhn
tkhn / README.md
Created August 11, 2016 10:01 — forked from magnetikonline/README.md
Setting Nginx FastCGI response buffer sizes.

Nginx FastCGI response buffer sizes

By default when Nginx starts receiving a response from a FastCGI backend (such as PHP-FPM) it will buffer the response in memory before delivering it to the client. Any response larger than the set buffer size is saved to a temporary file on disk. This process is outlined at the Nginx ngx_http_fastcgi_module page document page.

Introduction

Since disk is slow and memory is fast the aim is to get as many FastCGI responses passing through memory only. On the flip side we don't want to set an excessively large buffer as they are created and sized on a per request basis (i.e. it's not shared memory).