Skip to content

Instantly share code, notes, and snippets.

View vincentbernat's full-sized avatar

Vincent Bernat vincentbernat

View GitHub Profile
@vincentbernat
vincentbernat / postinst
Created March 20, 2014 16:03
fpm-cook recipe for Serf
#!/bin/sh
set -e
case "$1" in
configure|reconfigure)
;;
*)
adduser --system --disabled-password --disabled-login --home /nonexistent \
--no-create-home --quiet --force-badname --group _serf
@vincentbernat
vincentbernat / dispatch.sh
Last active August 29, 2015 13:57
More flexible dispatcher for Serf
#!/bin/sh
SERFDIR="${SERFDIR:-/etc/serf}"
# Dispatch an event to the appropriate handlers.
#
# $ tree /etc/serf
# /etc/serf
# └── handlers
# ├── member-failed
@vincentbernat
vincentbernat / iptables-ns.sh
Created April 28, 2014 10:19
Use of Linux network namespace to test and commit a firewall
#!/bin/zsh
# Use a dedicated network namespace to build and test firewall rules
# before applying them.
set -e
zparseopts -D n=dryrun -dry-run=dryrun t=trace -trace=trace f=iptables
[[ -n $trace ]] && setopt xtrace
[[ -z $iptables ]] && {
[Unit]
Description = XBMC Media Center
After = remote-fs.target
After = syslog.target
[Service]
User = xbmc
Group = xbmc
Type = simple
Restart = always
[Unit]
Description = dhclient on %I
Wants = network.target
Before = network.target
BindsTo = sys-subsystem-net-devices-%i.device
After = sys-subsystem-net-devices-%i.device
[Service]
Type = forking
PIDFile = /run/dhclient-%I.pid
#!/bin/zsh
include=()
exclude=()
for exc in $(grep '^ignore = Name ' ~/.unison/home.prf | awk '{print $NF}'); do
exclude=($exclude --exclude='**'/$exc)
done
for exc in $(grep '^ignore = Path ' ~/.unison/home.prf | awk '{print $NF}'); do
exclude=($exclude --exclude=$HOME/$exc)
done
@vincentbernat
vincentbernat / gist:45c00b740a5189a6d87c
Created December 16, 2014 12:32
IAM S3 policy example
{
"Statement": [
{
"Action": [
"s3:DeleteObject",
"s3:PutObject",
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [ "arn:aws:s3:::bucketname/*", "arn:aws:s3:::bucketname" ],
@vincentbernat
vincentbernat / gist:993189afbd0a6e7ddfba
Created January 8, 2015 09:51
Logstash 1.1.1 -> Logstash 1.4.2 - ES migration
input {
elasticsearch {
host => "..."
codec => "oldlogstashjson"
query => "NOT _exists_:@version"
}
}
@vincentbernat
vincentbernat / index.html
Created February 18, 2015 12:29
Angular directive to prevent/allow scrolling.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<!-- ... -->
</head>
<body ped-scrolling="forbid">
<!-- ... -->
# To be run with "python -m unittest -v socketpair"
import socket
import os
import select
import unittest
class TestUnixSocket(unittest.TestCase):
def check_socket(self, socktype):