Skip to content

Instantly share code, notes, and snippets.

View basicfw.sh
#!/bin/bash
$IPT=/sbin/iptables
#################
# GENERIC INPUT #
#################
$IPT --policy INPUT DROP
# Drop invalid
@dvasilen
dvasilen / ipint.go
Created Sep 12, 2021 — forked from ammario/ipint.go
Golang ip <-> int conversion
View ipint.go
func ip2int(ip net.IP) uint32 {
if len(ip) == 16 {
return binary.BigEndian.Uint32(ip[12:16])
}
return binary.BigEndian.Uint32(ip)
}
func int2ip(nn uint32) net.IP {
ip := make(net.IP, 4)
binary.BigEndian.PutUint32(ip, nn)
@dvasilen
dvasilen / dynamic_crds.go
Created Jul 30, 2020 — forked from tallclair/dynamic_crds.go
Example of using CRDs with the dynamic go client
View dynamic_crds.go
package main
import (
"fmt"
"log"
"os/user"
"path/filepath"
"strings"
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
View k8s-update-secret.md

Hopefully helped another k8s newbie with the following. The question was, how do you update a single key in a secret in k8s? I don't know anything about secrets but I will probably want to know this in the future, so here we go.

First, to create a dummy secret:

apiVersion: v1
kind: Secret
metadata:
  name: test-secret
data:
@dvasilen
dvasilen / gzip.go
Created Jul 3, 2019 — forked from bryfry/gzip.go
Idiomatic golang net/http gzip transparent compression (works with Alice)
View gzip.go
package main
import (
"compress/gzip"
"io"
"net/http"
"strings"
)
// Gzip Compression
@dvasilen
dvasilen / timeout_and_tick.go
Created Nov 15, 2017 — forked from ngauthier/timeout_and_tick.go
Golang timeout and tick loop
View timeout_and_tick.go
// keepDoingSomething will keep trying to doSomething() until either
// we get a result from doSomething() or the timeout expires
func keepDoingSomething() (bool, error) {
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
@dvasilen
dvasilen / watchPods.go
Created Nov 11, 2017 — forked from ctaggart/watchPods.go
Kubernetes watch pods
View watchPods.go
// some updates for https://rsmitty.github.io/Kubernetes-Events/
// and http://blog.ctaggart.com/2016/09/accessing-kubernetes-api-on-google.html
import (
"encoding/base64"
"fmt"
"log"
"net/http"
"time"
@dvasilen
dvasilen / aes.go
Created Nov 10, 2017 — forked from willshiao/aes.go
AES 256-CFB in Node.js and Golang
View aes.go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
"io"
View gist:385eb887d6234fd85b2d876cfee247e3
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@dvasilen
dvasilen / file0.txt
Created Jul 7, 2017 — forked from giwa/file0.txt
Install hive on Mac with Homebrew ref: http://qiita.com/giwa/items/dabf0bb21ae242532423
View file0.txt
$ brew update
$ brew install hive