Skip to content

Instantly share code, notes, and snippets.

View DavadDi's full-sized avatar

DavadDi DavadDi

View GitHub Profile
#!/bin/bash
#
# Generates client and server certificates used to enable HTTPS
# remote authentication to a Docker daemon.
#
# See http://docs.docker.com/articles/https/
#
# To start the Docker Daemon:
#
# sudo docker -d \
var (
codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#$%^&*()_="
codeLen = len(codes)
)
func RandNewStr(len int) string {
data := make([]byte, len)
rand.Seed(time.Now().UnixNano())
for i := 0; i < len; i++ {
package main
import (
"crypto/tls"
"net/http"
"time"
"log"
)
@DavadDi
DavadDi / redirectExample.go
Created June 9, 2017 07:41 — forked from d-schmidt/redirectExample.go
How to redirect HTTP to HTTPS with a golang webserver.
package main
import (
"net/http"
"log"
)
func redirect(w http.ResponseWriter, req *http.Request) {
// remove/add not default ports from req.Host
target := "https://" + req.Host + req.URL.Path
if len(req.URL.RawQuery) > 0 {
@DavadDi
DavadDi / GitHub-Forking.md
Created June 16, 2017 01:29 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

import (
"bytes"
"io"
"os"
)
// not thread safe
func captureStdout(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type SearchResult struct {
Date string `json:"date"`
@DavadDi
DavadDi / 1_kubernetes_on_macOS.md
Created January 15, 2019 02:54 — forked from kevin-smets/1_kubernetes_on_macOS.md
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

# cat /var/lib/istio/envoy/envoy_bootstrap_tmpl.json
{
"node": {
"id": "{{ .nodeID }}",
"cluster": "{{ .cluster }}",
{{ if .zone }}
"locality": {
"zone": "{{ .zone }}"
},
{{ end }}
apiVersion: v1
kind: Pod
metadata:
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ""
sidecar.istio.io/inject: "false"
creationTimestamp: 2019-01-15T08:24:23Z
generateName: istio-pilot-f9d78b7b9-
labels:
app: pilot