Skip to content

Instantly share code, notes, and snippets.

View alex-leonhardt's full-sized avatar
❄️

Alex Leonhardt alex-leonhardt

❄️
View GitHub Profile
@Skarlso
Skarlso / main.go
Created February 16, 2019 21:31
Golang SSH connection with hostkey verification
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"golang.org/x/crypto/ssh"
kh "golang.org/x/crypto/ssh/knownhosts"
@colmmacc
colmmacc / shardcalc.py
Last active July 22, 2024 19:52
Calculate the blast radius of a shuffle shard
import sys
# choose() is the same as computing the number of combinations. Normally this is
# equal to:
#
# factorial(N) / (factorial(m) * factorial(N - m))
#
# but this is very slow to run and requires a deep stack (without tail
# recursion).
#
@PurpleBooth
PurpleBooth / Dockerfile
Last active March 21, 2024 09:33
Create a static binary in go and put it in a from scratch docker container
FROM golang:1.9
WORKDIR /go/src/github.com/purplebooth/example
COPY . .
RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go
FROM scratch
COPY --from=0 /go/src/github.com/purplebooth/example/main /main
CMD ["/main"]
@teknoraver
teknoraver / unixhttpc.go
Last active July 8, 2024 10:12
HTTP over Unix domain sockets in golang
package main
import (
"context"
"flag"
"fmt"
"io"
"net"
"net/http"
"os"
@sivel
sivel / go-build.sh
Last active September 28, 2023 18:40
Ansible Binary Golang Module
go build helloworld.go
GOOS=windows GOARCH=amd64 go build helloworld.go
@rafaeltuelho
rafaeltuelho / linux-tcp-conn-test.md
Last active January 5, 2020 11:31
testing a TCP connection on Linux without telnet
  • option 1) just with echo
TCP_PORT_STATUS=`(echo > /dev/tcp/x.x.x.x/yyyy) >/dev/null 2>&1 && echo "UP" || echo "DOWN"`; echo $TCP_PORT_STATUS

where x.x.x.x is a valid IP ADDR or a HOSTNAME accesible on your network; and yyyy is valid TCP PORT

  • option 2) using Netcat tool
nc -vz IP_Address Port
@reiki4040
reiki4040 / signal.go
Created October 2, 2014 14:38
signal handling example for golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
@xkr47
xkr47 / sar.conf
Last active September 7, 2019 15:06
Example logstash configuration for streaming/tailing sysstat "sar" command
input {
pipe {
tags => [ "sar", "loadavg" ]
command => "env LANG=C sar -q 5"
}
pipe {
tags => [ "sar", "cpu" ]
command => "env LANG=C sar -u 5"
}
}
@sacharv
sacharv / gist:3b26d77c16ae1d8518b3
Created June 2, 2014 11:11
nginx + passenger + foreman 1.5
passenger+nginx (SL6 + SCL)
set correct path for SCL ruby:
export PATH=/opt/rh/ruby193/root/usr/bin:$PATH
export LD_LIBRARY_PATH=/opt/rh/ruby193/root/usr/lib64:$LD_LIBRARY_PATH
download latest phusion passenger tarbal (I wrongly put it in /usr/local/src, so that is where the libs are now)
./bin/passenger-install-nginx-module
follow all default steps (have script download and compile nginx)
@ifels
ifels / golang_pipe_http_response.go
Last active February 1, 2023 19:19
golang pipe the http response
package main
import (
"io"
"net/http"
"os/exec"
)
var (
BUF_LEN = 1024