This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Connection adapter for Requests that allows it to talk with raw UNIX sockets. | |
| Adapted from requests-unixsocket, which itself was adapted from docker-py. | |
| https://github.com/msabramo/requests-unixsocket | |
| https://github.com/docker/docker-py/blob/master/docker/unixconn/unixconn.py | |
| """ | |
| import socket | |
| from urllib.parse import unquote, urlparse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "net/http/httputil" | |
| ) | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| var formatted, err = httputil.DumpRequest(r, true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // See http://ppanyukov.github.io/2017/02/01/golang-with-vsts-repos.html | |
| package main | |
| import ( | |
| "strings" | |
| "fmt" | |
| "os" | |
| "log" | |
| "net/http" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Installs node.js and azure cli on Centos5 box. | |
| # Lots of hacking because standard installation does not work | |
| # due to SSL (and other) issues. | |
| # Adds nodejs yum repo. | |
| # Parameters: none | |
| function add_node_repo() { | |
| cat <<EOF > /etc/yum.repos.d/nodesource-el.repo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type ApacheLogRecord struct { | |
| http.ResponseWriter | |
| ip string | |
| time time.Time | |
| method, uri, protocol string | |
| status int | |
| responseBytes int64 | |
| elapsedTime time.Duration | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "bufio" | |
| "time" | |
| "os" | |
| "fmt" | |
| "io" | |
| "net" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This example demonstrates how panics in handlers can be recovered, | |
| // and HTTP 500 responses sent to the client when panic happens. | |
| // | |
| // Since the built-in http.ResponseWriter cannot be reset, any panic | |
| // can lead to half-arsed responses in the buffer or worse. | |
| // Also, since our panic handler needs to completely replace the response, | |
| // we need our own fully buffered ResponseWriter. | |
| // | |
| // This demo implements such a buffered response writer as HttpBuffer. | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This example demonstrates a pluggable middleware approach to | |
| // recovering from panics in HTTP handlers and sending HTTP 500 | |
| // responses to the client when panics happen. | |
| // | |
| // The middleware allows to use in any handlers without them | |
| // being aware of anything special. | |
| // | |
| // Utilises middleware concepts, see: | |
| // - https://github.com/justinas/alice | |
| // - https://www.alexedwards.net/blog/making-and-using-middleware |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Copy this entire thing at the beginning of all your bash scripts, | |
| # this will save you a lot of trouble now and in the future. | |
| # -e: Fail on errors | |
| # -u: Fail on undeclared/unbound variables | |
| set -eu | |
| # This is the directory where this script is. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -eu | |
| # Noddy script to encrypt/decrypt files using openssl private (ssh) key. | |
| # Works with files and stdin. | |
| # Results are stdout. | |
| # | |
| # Requirements: | |
| # - openssl | |
| # - ssh private key: ~/.ssh/id_rsa |