Instantly share code, notes, and snippets.

View Rollout strategies for large code changes.md

Getting into production sooner should be part of our business plan.

Rather than spending lots of time getting all planned features 'finished', we should have a plan for slowly rolling out incremental changes. In doing so we would have more confidence that the features we were releasing would not break something in production and make it difficult to rollback. In effect we want to avoid ending up with a 'big bang' rollout.

The following steps could be a useful plan of action to take:

  1. define code 'boundaries'
  2. filter traffic by 'funnels'
  3. build features, then deploy them within our secured boundaries
View Sed Replace Pattern with File Contents.bash
cd -- "$(mktemp -d)"
printf '%s\n' 'nuts' 'bolts' > first_file.txt
printf '%s\n' 'foo' 'bar' 'baz' > second_file.txt
sed -e '/bar/r ./first_file.txt' second_file.txt
### output...
foo
bar
nuts
bolts
View Vim handling stdin.md

Note: for full details, read https://vimways.org/2018/vims-social-life/

Vim doesn't handle stdin like other posix commands...

$ echo foo | vim

Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
View Vim Directory Structure, Start-up and Debugging.md

The vim documentation explains all the various steps that are gone through during 'start-up', see :h startup.

In short, Vim executes :runtime! plugin/**/*.vim meaning any directories listed in the runtime path (:h set runtimepath?) will be searched for a plugin sub-directory and all files ending in ".vim" will be sourced (in alphabetical order per directory).

Note: if you want to debug the start-up process: vim --startuptime some_log_filename.

  • ~/.vim/autoload/... (:h autoload)
  • ~/.vim/plugin/... (:h plugin)
  • ~/.vim/ftplugin/... (:h ftplugin)
  • ~/.vim/after/... (:h after-directory)
View Vim Arm List.md

Start vim:

vim

Check arguments list is empty:

:args
View Python TTL Cache Decorator.py
from datetime import datetime, timedelta
from functools import wraps
from tornado.httpclient import AsyncHTTPClient
AsyncHTTPClient.configure(None, defaults=dict(user_agent="YourService"))
http_client = AsyncHTTPClient()
def network_cache(fn):
"""Cache asynchronous network requests based on cache-control.
View Python String Formatting.md

f-string

f'approx pi: {math.pi:.3f}'  # 'approx pi: 3.142'
f'approx pi: {math.pi:.10f}'  # 'approx pi: 3.1415926536'

# padding...
foo = 'bar'
baz = 'qux'
View Python Tornado UVLoop.py
import asyncio
import tornado.httpserver
import tornado.ioloop
import tornado.platform.asyncio as tornado_asyncio
import tornado.web
import uvloop
class MainHandler(tornado.web.RequestHandler):
def get(self):
View Execute pytest.bash
pytest -svv --color=yes
# https://docs.pytest.org/
View Go Modules.md

Go 1.11 introduced a new concept of 'Modules' which brings first class support for managing dependency versions and enabling reproducible builds.

A Module is a way to group together a set of packages and give it a version number to mark its existence (state) at a specific point in time.

Go Modules use Semantic Versioning for their numbering scheme.

Think of a 'module' as a project repository. Your project consists of many packages, and a module allows you to adequately group and version them.

New Project