Skip to content

Instantly share code, notes, and snippets.

View zazazack's full-sized avatar

Zachary Wilson zazazack

View GitHub Profile
@zazazack
zazazack / walrus-operator.md
Last active September 2, 2022 14:00
Collecting subsets from JSON: A worthy use case for the Assignment Expression aka "Walrus Operator"?
title author date
assignment expression use case
Zachary Wilson
2022-09-01

Nicknamed the Walrus Operator for its resemblance to the face of a Walrus: :=, the [Assignment Expression][assignment_expression] allows one to assign a value to a variable if and only if it returns a result.

Since its inception, the [Assignment Expression][assignment_expression] has been a highly debated topic within the PSF.

from dataclasses import dataclass, field


@dataclass
class iSort:
    imports: str = field(default=None)

    def _imports(self):
        imports = self.imports
@zazazack
zazazack / probably.py
Created September 29, 2018 06:22
Just about the most satisfying piece of code I've ever written.
#!/usr/bin/env python3
from fractions import Fraction
from itertools import product
import statistics
import random
import logging
from matplotlib import pyplot as plt, style
logging.basicConfig(level=logging.DEBUG)
@zazazack
zazazack / loadlines.py
Created March 17, 2018 15:57
Load JSON from multiple `.json` files stored in the JSON Lines format with Python 3.6 builtins
from pathlib import Path
import json
p = Path() # assuming .json files are located in the current working directory
data = [json.loads(line) for file in p.glob('*.json') for line in file.read_text().splitlines()]
@zazazack
zazazack / docker-machine-create-debug.txt
Created July 17, 2017 14:46
Output error `docker-machine -D create --driver amazonec2 aws-docker`, docker-machine version 0.12.0, build 45c69ad
Docker Machine Version: 0.12.0, build 45c69ad
Found binary path at /usr/local/bin/docker-machine
Launching plugin server for driver amazonec2
Plugin server listening at address 127.0.0.1:63494
() Calling .GetVersion
Using API Version 1
() Calling .SetConfigRaw
() Calling .GetMachineName
(flag-lookup) Calling .GetMachineName
(flag-lookup) Calling .DriverName
@zazazack
zazazack / apple-keyboard-html-entities.txt
Created January 30, 2017 20:33
Apple HTML Keyboard Symbol Entities
HTML Entity GLYPH NAME
  Apple
⌘ ⌘ Command, Cmd, Clover, (formerly) Apple
⌃ ⌃ Control, Ctl, Ctrl
⌥ ⌥ Option, Opt, (Windows) Alt
⇧ ⇧ Shift
⇪ ⇪ Caps lock
⏏ ⏏ Eject
↩ ↩ Return, Carriage Return
↵ ↵ ↵ Return, Carriage Return
@zazazack
zazazack / FileTransfer.py
Created October 31, 2016 17:55 — forked from omz/FileTransfer.py
File Transfer script for Pythonista (iOS)
# File Transfer for Pythonista
# ============================
# This script allows you to transfer Python files from
# and to Pythonista via local Wifi.
# It starts a basic HTTP server that you can access
# as a web page from your browser.
# When you upload a file that already exists, it is
# renamed automatically.
# From Pythonista's settings, you can add this script
# to the actions menu of the editor for quick access.
@zazazack
zazazack / FileBrowser.py
Last active November 1, 2016 15:33 — forked from omz/FileBrowser.py
FileBrowser
import http.server
import socketserver
import webbrowser
import os
os.chdir('/')
Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", 0), Handler)
port = httpd.server_address[1]