Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wware
wware / lp_hacks.md
Created April 15, 2022 18:21
A bit of fun with literate programming using Markdown

Literate Programming hacks

Let's try some literate programming. From Don Knuth's original idea, thru Norman Ramsey's noweb reformulation, by way of Jonathan Aquino's Python version, which I tweaked to accept Markdown input and added a few new features.

$ ./noweb.py -R 'outer function' lp_hacks.md | python
Hello world
"""
I've modified John Gaines Jr.'s answer to handle lists. I didn't need editing
or the Taglist for what I'm doing so I removed them. They could certainly be
added back. Since lists can introduce duplication of keys, I replaced the keys
with UUIDs while still showing the original key as text on the left side of the
treeview.
UPDATE: My original answer did not include the editing function that John Gaines Jr.
had implemented. I've now added that to mine, with the caveat that I'm not very
expert regarding Tk/Tkinter layout and spacing, so I stopped tinkering once it
import os
import linecache
import pprint
import sys
from functools import wraps
class IncludeExclude(object):
def __init__(self, inclusions=None, exclusions=None):
self._inclusions = inclusions

Making X Windows work for a Docker container

https://stackoverflow.com/questions/49169055

This is because the container couldn't access the x11 socket of the host. so when doing the docker run, need to include these two flag.

-v /tmp/.X11-unix:/tmp/.X11-unix
-e DISPLAY=unix$DISPLAY

and after this, we need to do another operation. because the default settings of X11 only allows local users to print. so we need to change this to all users.

#!/usr/bin/env python
"""
To run these tests remotely with Ansible, add command line arguments:
./ansible_unit_tests.py -i inventory.yaml hostname
./ansible_unit_tests.py -i inventory.yaml group
To convert docstrings into a Markdown file, type:

Yet another Python debugger hack

Here is the problem I'm trying to solve here. You have some code running in AWS or running in some far-away server rack. Your access to the machine in question is things like SSH or telnet. The code is running a bunch of jobs as part of a CI/CD system. You would like to kick off a job where the code runs with RemotePdb so that you can step through it and examine variables and set breakpoints and all that, without disturbing any other jobs running at the same time.

You can't change the code. You don't have time to get a merge request approved, and it doesn't make sense to do a merge request to facilitate what might be a very brief one-time debugging session. You need some kind of hooks in your production code that make this remote debugging stuff feasible without a fresh push to your CI/CD stack.

@wware
wware / trace_func.py
Last active December 13, 2019 18:48
Decorator to show Python control flow thru a function and the functions it calls
#!/usr/bin/env python
import inspect
import linecache
import pprint
import yaml
import re
import os
import sys
import logging
@wware
wware / 0Gunicorn.md
Last active December 1, 2019 23:17
Wrap my head around this WSGI stuff

Learning about Gunicorn

I need to wrap my head around this WSGI stuff. Let's dockerize this tutorial.

https://en.wikipedia.org/wiki/Gunicorn

The Gunicorn "Green Unicorn" (pronounced jee-unicorn) is a Python Web Server Gateway Interface (WSGI) HTTP server. It is a pre-fork worker model, ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with a

@wware
wware / ansible-summary.md
Last active July 12, 2024 20:06 — forked from andreicristianpetcu/ansible-summary.md
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7), tweaked by Will Ware in 2019

Configuration file

intro_configuration.html

First one found from of