Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / Install Python package directly for the interpreter Vim is using.md
Created Oct 2, 2020
[Install Python package directly for the interpreter Vim is using] #vim #python
View Install Python package directly for the interpreter Vim is using.md

Sometimes Vim's Python binary can't find a package you've installed.

  • in vim
    :py3 import sys; print(sys.path)

  • navigate to that location and find the python binary, in my case:
    cd /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/bin

  • install isort using this binary
    ./python3.8 -m pip install isort

@Integralist
Integralist / curl to json.bash
Created Oct 2, 2020
[Curl to JSON] #curl #bash #shell #json
View curl to json.bash
# https://daniel.haxx.se/blog/2020/03/17/curl-write-out-json/
#
curl --write-out '%{json}' https://example.com -svo /dev/null | jq
{
"url_effective": "https://example.com/",
"method": "GET",
"http_code": 200,
"response_code": 200,
"http_connect": 0,
@Integralist
Integralist / tornado logging when request has completed.py
Last active Sep 28, 2020
[Python tornado logging when request has completed] #python #python3 #tornado #logging #logs #server #http
View tornado logging when request has completed.py
"""
That Application.log_request approach uses very explicit naming,
and yet the tornado docs for RequestHandler.on_finish says...
> Override this method to perform cleanup, logging, etc.
So theres two ways to essentially do the same thing 🤔
My understanding for the difference would be log_request is useful for
generic logging behaviour, while on_finish could be customized per
@Integralist
Integralist / Asyncio built-in Socket Server.py
Created Sep 25, 2020
[Asyncio built-in Socket Server] #python #python3 #asyncio #server #socket #web #http
View Asyncio built-in Socket Server.py
import asyncio
async def handle_request(reader, writer):
writer.write("hello world".encode()) # needs to be bytes not string
writer.close()
async def main():
srv = await asyncio.start_server(handle_request, '127.0.0.1', 8081)
@Integralist
Integralist / 0. README.md
Last active Sep 25, 2020
[Python Context and ContextVars] #python #python3 #context #contextvars
View 0. README.md

Context variables are variables that can have different values depending on their context. They are similar to Thread-Local Storage in which each execution thread may have a different value for a variable. However, with context variables, there may be several contexts in one execution thread. The main use case for context variables is keeping track of variables in concurrent asynchronous tasks. -- https://realpython.com/python37-new-features/#context-variables

"""Example copied verbatim from Real Python."""

import contextvars

name = contextvars.ContextVar("name")
contexts = list()
@Integralist
Integralist / Golang Named Return Zero Value.go
Created Sep 23, 2020
[Golang Named Return Zero Value] #go #golang #zero #named #return
View Golang Named Return Zero Value.go
package main
import (
"fmt"
)
func GetString(key string) (val string) {
// 'named' return value are initialized to their zero value
// meaning we can proxy the zero value through to a nested function
//
@Integralist
Integralist / YouTube 'Watch' Channels.md
Created Sep 21, 2020
[YouTube 'Watch' Channels] #youtube #watches
View YouTube 'Watch' Channels.md
  • Bark and Jack: great down to earth personality, cool watches, very easy to listen to.
  • WatchFinder: awesome/expensive unique watches and their backgrounds (exquisite close-up footage)
  • Theo and Harris: high end quality pieces reviewed/discussed
  • The Urban Gentry: can waffle on, but he does great historical deep dives
  • Watch Advisor: I just enjoy listening to him talk because of his accent lol
  • Long Island Watches: cheaper end watches, interesting selections come up
  • Jenni: female watch reviewer (great quality footage)
  • WatchBox Reviews: short reviews
  • [WatchBox Studi
@Integralist
Integralist / Go Module Versioning.md
Last active Sep 22, 2020
[Go Module Versioning] #go #golang #modules #versioning #semver
View Go Module Versioning.md

Reference: https://blog.golang.org/v2-go-modules

You have a dependency you want to use, like github.com/integralist/delete-just-testing.

// delete-just-testing/foo/foo.go 
//
package foo

import "fmt"
@Integralist
Integralist / macOS System Information.bash
Last active Sep 18, 2020
[macOS System Information] #macos #system #information #shell #bash
View macOS System Information.bash
# Documentation:
#
# - man sw_vers
# - man system_profiler
#
# Product Name:
# Neither of the above solutions provide the OS 'product name' (e.g. Catalina, Mojave, High Sierra etc.)
# So I curl Wikipedia's macOS version history page and parse out the name.
#
# The problem in doing so is that I need a version number (e.g. 10.15)
@Integralist
Integralist / git revision range.md
Created Sep 16, 2020
[Git Revision Range] #git #revision #range
View git revision range.md

Reference: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection

Log commits in feature branch that aren't in master:

git log master..feature

If you git pull your master branch you might find there are additional commits from your colleagues. So you might want to check what commits were recently merged into master that aren't in your feature branch:

You can’t perform that action at this time.