Instantly share code, notes, and snippets.

View Go

Go Guru

See official doc: Using Go Guru

go get
guru -help

# guru <mode> <position:byte offset>
View Vim

A zero-width negative lookaround assertion looks like:


Note: this would match level='error' or level='debug'.

The equivalent in Vim is:

View Bash loop files in a directory and check their
ignore=("cmd" "lib" "scripts")
for filename in $project/$service/*; do
if [[ -d $filename ]]; then
echo "$filename is a directory"
View Long and Short Flag.go
var myFlagType string
func init() {
const (
flagValue = "default value is foo"
flagUsage = "this is my flag explanation"
flag.StringVar(&myFlagType, "foo", flagValue, flagUsage)
flag.StringVar(&myFlagType, "f", flagValue, flagUsage+" (shorthand)")
View 1. Python Dynamic Log Levels via
import logging
def log_it(msg, level='error'):
fn = getattr(logging, level)
log_it(1, level='warning')
# WARNING:root:1
log_it(1, level='error')
View GitHub Collapsible Drop Down

collapsible markdown?


yes, even hidden code blocks!

print("hello world!")
View Python Tornado Generic Exception
Exception is still sent to stdout, so if your service is configured
to send all stdout to a log aggregator you'll get both a load of
log noise followed by a single log call that consolidates it all.
See for a
logging/metrics abstraction (+ tornado implementation) that ties
this write_error function together nicely.
View Python Decorator
Decorators are 'bottom up', meaning:
The bottom decorator is executed, and its result is
provided as input to the decorator above it.
In the below code this would look something like:
View Modern

Ensure you have Node/NPM installed, then make a project directory:

mkdir modern-js && cd modern-js

Create an empty package.json file:

npm init -y
View Fastly Edge Dictionaries API Examples.bash
#!/usr/bin/env bash
# API documentation here...
# at the end of the day, these are just simple `curl` requests
# along with a HTTP header that holds our api token.
# meaning, you could rewrite all of this much more cleanly in
# a more fully feature language such as Go or Python.