Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Last active September 16, 2016 09:21
Show Gist options
  • Save Luzifer/6586f6a7b05b34839873b86f206658d8 to your computer and use it in GitHub Desktop.
Save Luzifer/6586f6a7b05b34839873b86f206658d8 to your computer and use it in GitHub Desktop.
"GobNuss" is a neologism form the german word "Kopfnuss" (clout) and the Go encoding method "gob". Send someone an encoded "GobNuss" instead giving them a Kopfnuss…

FAQ

Whats this?

This is just a joke from my team put into code. We were talking about go Go encoding/gob and someone brought up a "Kopfnuss" (clout). From that the word "GobNuss" derived and I said I will put this together. The result is below.

How to use?

Send a GobNuss:

# ./gobnuss write luzifer someoneelse 'Making bad porn references'
MP+BAwEBB0dvYk51c3MB/4IAAQMBBEZyb20BDAABAlRvAQwAAQZSZWFzb24BDAAAADX/ggEHbHV6aWZlcgELc29tZW9uZWVsc2UBGk1ha2luZyBiYWQgcG9ybiByZWZlcmVuY2VzAA==

Read a GobNuss:

# echo "MP+BAwEBB0dvYk51c3MB/4IAAQMBBEZyb20BDAABAlRvAQwAAQZSZWFzb24BDAAAADX/ggEHbHV6aWZlcgELc29tZW9uZWVsc2UBGk1ha2luZyBiYWQgcG9ybiByZWZlcmVuY2VzAA==" | ./gobnuss read
Hi someoneelse, you received a GobNuss from luzifer because of: Making bad porn references

Do I need this? Does it make sense?

Nope. :trollface:

package main
import (
"bytes"
"encoding/base64"
"encoding/gob"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/Luzifer/rconfig"
)
type GobNuss struct {
From, To, Reason string
}
func (g GobNuss) String() string {
return fmt.Sprintf("Hi %s, you received a GobNuss from %s because of: %s", g.To, g.From, g.Reason)
}
var (
cfg = struct{}{}
)
func init() {
gob.Register(GobNuss{})
}
func main() {
rconfig.Parse(&cfg)
if len(rconfig.Args()) == 1 {
log.Fatalf("Try `read` or `write <from> <to> <reason>`", rconfig.Args()[0])
}
switch rconfig.Args()[1] {
case "read":
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Could not read input: %s", err)
}
d, err := base64.StdEncoding.DecodeString(string(data))
if err != nil {
log.Fatalf("Could not base64 decode input: %s", err)
}
buf := bytes.NewBuffer(d)
r := GobNuss{}
if err := gob.NewDecoder(buf).Decode(&r); err != nil {
log.Fatalf("Could not gob decode input: %s", err)
}
fmt.Println(r.String())
case "write":
if len(rconfig.Args()) != 5 {
log.Fatalf("Usage: %s write <from> <to> <reason>", rconfig.Args()[0])
}
buf := bytes.NewBuffer([]byte{})
if err := gob.NewEncoder(buf).Encode(GobNuss{
From: rconfig.Args()[2],
To: rconfig.Args()[3],
Reason: rconfig.Args()[4],
}); err != nil {
log.Fatalf("Could not encode GobNuss: %s", err)
}
fmt.Println(base64.StdEncoding.EncodeToString(buf.Bytes()))
default:
log.Fatalf("Sorry, I don't understand %s. Try `read` or `write <from> <to> <reason>`", rconfig.Args()[0])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment