A Go version of The Perl Cookbook
The Perl part is copyrighted by O'Reilly & Associates yet freely available.
This copy is based on http://pleac.sourceforge.net/pleac_perl.data
#!/bin/bash -e | |
IFADDR="192.168.3.1/24" | |
if [[ ! ip link show docker0 ]]; then | |
ip link add docker0 type bridge | |
ip addr add "$IFADDR" dev docker0 | |
ip link set docker0 up | |
iptables -t nat -A POSTROUTING -s "$IFADDR" ! -d "$IFADDR" -j MASQUERADE | |
fi |
--- | |
# ^^^ YAML documents must begin with the document separator "---" | |
# | |
#### Example docblock, I like to put a descriptive comment at the top of my | |
#### playbooks. | |
# | |
# Overview: Playbook to bootstrap a new host for configuration management. | |
# Applies to: production | |
# Description: | |
# Ensures that a host is configured for management with Ansible. |
#!/bin/bash | |
# Script for installing tmux on systems where you don't have root access. | |
# tmux will be installed in $HOME/local/bin. | |
# It's assumed that wget and a C/C++ compiler are installed. | |
# exit on error | |
set -e | |
TMUX_VERSION=1.8 |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from sqlsoup import SQLSoup as sql | |
from sys import argv | |
DIGRAPH = """digraph structs { | |
graph [ | |
rankdir= "LR" | |
bgcolor=white | |
] |
A Go version of The Perl Cookbook
The Perl part is copyrighted by O'Reilly & Associates yet freely available.
This copy is based on http://pleac.sourceforge.net/pleac_perl.data
// Parsing arbitrary JSON using interfaces in Go | |
// Demonstrates how to parse JSON with abritrary key names | |
// See https://blog.golang.org/json-and-go for more info on generic JSON parsing | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
) |
Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)
First one found from of
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) { | |
// path/to/whatever does not exist | |
} | |
if _, err := os.Stat("/path/to/whatever"); err == nil { | |
// path/to/whatever exists | |
} |
package main | |
import ( | |
"net/http" | |
"database/sql" | |
"fmt" | |
"log" | |
"os" | |
) |