Skip to content

Instantly share code, notes, and snippets.

@samesense
samesense / README.md
Last active January 11, 2021 15:08 — forked from alexkappa/fleet.go

Reading and writing JSON with GO

Problem: I want to read and serve JSON, but the JSON structure differs by query. I solve this with an interface FleetVehicle, a base Vehicle struct, and additional specialized structs that allow for differetnail parsing. The Fleet struct holds raw json in RawVehicles, and parsed objects/structs in Vehicles. By writing MarsahJSON and UnmarshalJSON for the Fleet struct, and I control how each JSON block is parsed into a different type of struct/vehicle. To run: GOPATH=${PWD} go run helloVariant.go, and check http://localhost:8080/world. This loads multiple JSON files into one Fleet object allowing me to serve a concatenation of the JSON files. For now, each JSON block must use the data field to hold a list of vehicles.

  • helloVariant.go is the main file
  • src/varparse/varparse.go holds structs for variants in JSON
  • testVariant1.json and testVariant2.json are example files used by helloVariant.go
  • hello.go is my initial attempt
  • fleet.go, fleet_test.go, fleet_test_
#!/usr/bin/env python3
"""
The idea here is to have one demo of each common argparse format
type. This is useful for me to be able to copy/paste into a new
script and have something to quickly edit and trim down to get
the functionality I need.
Example (in your terminal):
$ python3 argparse-template.py "hello" 123 --enable
@samesense
samesense / ssh-forward-clipboard.md
Last active August 26, 2019 20:41 — forked from dergachev/ssh-forward-clipboard.md
Forward your clipboard via SSH reverse tunnels

Exposing your clipboard over SSH

I frequently administer remote servers over SSH, and need to copy data to my clipboard. If the text I want to copy all fits on one screen, then I simply select it with my mouse and press CMD-C, which asks relies on m y terminal emulator (xterm2) to throw it to the clipboard.

This isn't practical for larger texts, like when I want to copy the whole contents of a file.

If I had been editing large-file.txt locally, I could easily copy its contents by using the pbcopy command:

@samesense
samesense / 0_reuse_code.js
Created May 31, 2014 23:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console