Skip to content

Instantly share code, notes, and snippets.

View ppanyukov's full-sized avatar

Philip Panyukov ppanyukov

  • UK
View GitHub Profile
@ppanyukov
ppanyukov / template.sh
Created July 10, 2019 09:57
bash script template
#!/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.
@ppanyukov
ppanyukov / main.go
Created June 18, 2019 19:28
Golang: Demo #2 of panic recovery in HTTP handlers and sending HTTP 500
// 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
@ppanyukov
ppanyukov / main.go
Last active June 18, 2019 17:06
Golang: Demo of panic recovery in HTTP handlers and sending HTTP 500
// 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.
//
@ppanyukov
ppanyukov / sshtunnel.go
Created January 23, 2018 20:13 — forked from iamralch/sshtunnel.go
SSH tunnelling in Golang
package main
import (
"log"
"bufio"
"time"
"os"
"fmt"
"io"
"net"
@ppanyukov
ppanyukov / log.go
Created October 31, 2017 21:41 — forked from cespare/log.go
Golang apache logging
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
#!/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
// See http://ppanyukov.github.io/2017/02/01/golang-with-vsts-repos.html
package main
import (
"strings"
"fmt"
"os"
"log"
"net/http"
@ppanyukov
ppanyukov / dump_headers.go
Last active February 8, 2023 15:26
Simple web server in golang to dump to echo requests
package main
import (
"fmt"
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
var formatted, err = httputil.DumpRequest(r, true)
@ppanyukov
ppanyukov / socketadapter.py
Created November 24, 2016 12:31 — forked from mminer/socketadapter.py
Connection adapter for Requests that allows it to talk with raw UNIX sockets.
"""
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

Having the exitng git repo with this structure:

+
|
+-- bin/
|
+-- html/