Skip to content

Instantly share code, notes, and snippets.

@TripleDogDare
TripleDogDare / Revel Cache Viewer.go
Last active December 23, 2015 05:49
Revel Cache Viewer creates a text revel.Result that displays the cache in a readable format if it is the "InMemoryCache" (not using memchached).
package controllers
import (
"encoding/gob"
"fmt"
"github.com/robfig/revel"
"github.com/robfig/revel/cache"
"os"
"path/filepath"
"time"
@TripleDogDare
TripleDogDare / FunctionsAsParameters.go
Last active August 29, 2015 13:58
Passing functions as parameters
// http://play.golang.org/p/kmXecwWIMR
package main
import "fmt"
/*
Output:
Hello, playground
A: 1
JSON = {}
function JSON:new (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function JSON:stringify(depthLimit, depth)
@TripleDogDare
TripleDogDare / Mint LiveUSB GRUB2
Created February 12, 2015 11:31
Setup Mint from LiveUSB and fix bootloader
# Primary sources
# Install Grub2: http://community.linuxmint.com/tutorial/view/245
# Update grub2: http://askubuntu.com/questions/145241/how-do-i-run-update-grub-from-a-livecd
# Run LiveUSB in live or persistent mode. You'll need the terminal after installation.
# Install as normal. You'll get an error about not being able to install the bootloader, ignore and continue, do not reboot.
# If you do reboot, just get back into live mode and continue.
# Replace the drive/partition numbers where necessary in the code below and run the following commands to install/update GRUB2
#sudo mount /dev/sdXY /mnt
#!/bin/bash
# Check that we are in a git repository. Will help avoid reckless recursion through files.
git_dir=$(git rev-parse --show-toplevel) && is_git_dir=1
[ -z $is_git_dir ] && {
echo "Must execute inside a git repository"
exit
}
echo "Git repository: $git_dir"
@TripleDogDare
TripleDogDare / pj.go
Created December 15, 2015 05:42
Go pretty print JSON
package main
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"os"
)
package main
import (
"sync"
"fmt"
)
func main() {
defer func() {
fmt.Println("If you see this then success!")
@TripleDogDare
TripleDogDare / port2pid-lsof.sh
Last active September 9, 2023 00:20
Get the PID of process listening on given TCP port
#!/bin/bash
set -eou pipefail
PORT=${1}
# Could use UDP here
lsof -iTCP:${PORT} | grep ${PORT} | tr -s ' ' | cut -d' ' -f2
@TripleDogDare
TripleDogDare / lk
Last active July 29, 2016 20:13
ls/less alias
#!/bin/bash
set -euo pipefail
TARGET=${1:-.}
if [ -d "$TARGET" ]; then
ls -al --color=yes "$TARGET"
elif [ -f "$TARGET" ]; then
less "$TARGET"
else
@TripleDogDare
TripleDogDare / minikube-build.sh
Last active July 6, 2017 22:42
build minikube
#!/bin/bash
# Based on https://github.com/kubernetes/minikube/blob/master/docs/contributors/build_guide.md
# Eventually this should go into a formula to set up dependencies.
set -euo pipefail
MINIKUBE_REPO="https://github.com/kubernetes/minikube.git"
MINIKUBE_HASH=${1:-}
[ -z "$MINIKUBE_HASH" ] && {
git ls-remote --tags "$MINIKUBE_REPO" | sort -k2 -V
>&2 echo "Please select a hash to build: $0 <hash>"