Skip to content

Instantly share code, notes, and snippets.

@lfaoro
lfaoro / tmux_cheatsheet.markdown
Created September 29, 2019 13:32 — forked from henrik/tmux_cheatsheet.markdown
tmux cheatsheet

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

// Copyright (c) 2019 Leonardo Faoro. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"io/ioutil"
info, err := os.Stat(fileName)
if err != nil {
return err
}
if info.IsDir() {
message := fmt.Sprintf(`
Sorry, I can't upload a whole directory.
Try:
$ tar -cvf %s.tar %s/
$ ncrypt %s.tar
// From return client's real public IP address from http request headers.
func From(r *http.Request) string {
// Fetch header value
xRealIP := r.Header.Get("X-Real-IP")
xForwardedFor := r.Header.Get("X-Forwarded-For")
// If both empty, return IP from remote address
if xRealIP == "" && xForwardedFor == "" {
var remoteIP string
@lfaoro
lfaoro / mux_routes.go
Created March 11, 2019 11:29 — forked from elico/mux_routes.go
A trial to use gorilla mux router Walk function
package main
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
)
func signupHandler(w http.ResponseWriter, request *http.Request) {
@lfaoro
lfaoro / logger.go
Created March 6, 2019 10:21
logging handler
package httpLogger
import (
"log"
"net/http"
"os"
"strings"
"time"
"git.vlct.io/vaultex/vaultex/internal/realip"
@lfaoro
lfaoro / EmacsKeyBinding.dict
Created December 9, 2018 13:58 — forked from jwreagor/EmacsKeyBinding.dict
Global Emacs Key Bindings for OS X
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
// CreditCardRegex is the pattern used to identify a credit card PAN.
var CreditCardRegex = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"
var rxCreditCard = regexp.MustCompile(CreditCardRegex)
var rxNotNumber = regexp.MustCompile("[^0-9]+")
// IsCreditCard checks if the string is a credit card.
func IsCreditCard(s string) bool {
sanitized := rxNotNumber.ReplaceAllString(s, "")
if !rxCreditCard.MatchString(sanitized) {
return false
@lfaoro
lfaoro / Dockerfile
Created October 12, 2018 22:58
Compile multiple Go programs and load them all in a light container
FROM golang:alpine as builder
WORKDIR /build
COPY . .
RUN apk update && apk upgrade && \
apk add git gcc
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go install -gcflags "-N -l" ./cmd/...
FROM alpine:latest
RUN apk update && apk add ca-certificates && \
@lfaoro
lfaoro / batch-sql-backup.yaml
Last active June 25, 2018 10:32
batch-sql-backup.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: batch-sql-backup
spec:
schedule: "* */60 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template: