by a humble sysadmin
No process is an island,
Running all alone;
Every process is a child of another,
A part of the tree.If a thread is killed in silence,
The system is the less,
import sys | |
def cli_function(): | |
"""This is a python function that offers a CLI or does some long running | |
task that you might want to interrupt""" | |
if __name__ == "__main__": | |
try: | |
cli_function() |
Update: I created jq-zsh-plugin that does this.
One of my favourite tools of my trade is jq. It essentially enables you to process json streams with the same power that sed, awk and grep provide you with for editing line-based formats (csv, tsv, etc.).
Another one of my favourite tools is fzf.
#!/bin/bash | |
# Clean all exited containers | |
docker ps -qaf status=exited | xargs docker rm | |
# Remove all unused images | |
docker images -f dangling=true -q | xargs docker rmi |
#!/bin/bash | |
iterations=10 | |
# ----------------------------------------------------------------------------- | |
# Create array of results | |
declare -a results | |
for i in $(seq 1 $iterations); |
"""Examples to show how Python stores the closure metadata in a decorator. | |
Know that this information isn't always just attached to a decorator. It could | |
also be passed around with regular functions, if the conditions match. | |
That is, if a variable from a higher scope is _referenced_ from a variable in | |
another scope, which is passed around, then, a __closure__ meta variable is | |
attached to the object that is passed around, where it has a store of what its | |
'closure' is. |
git_current_branch () { | |
local ref | |
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null) | |
local ret=$? | |
if [[ $ret != 0 ]] | |
then | |
[[ $ret == 128 ]] && return | |
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return | |
fi | |
echo ${ref#refs/heads/} |
""" | |
This module provides a simple WSGI profiler middleware for finding | |
bottlenecks in web application. It uses the profile or cProfile | |
module to do the profiling and writes the stats to the stream provided | |
To use, run `flask_profiler.py` instead of `app.py` | |
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/ | |
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling | |
""" |
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""This is a rot-13 encoded puzzle. Interestingly, this is how the `this` module is implemented | |
in Python. | |
Did you know that the `this` module breaks the Zen of Python in almost *every* possible way? | |
Run this on Python Anywhere and you can see the output on your phone. | |
Here's a `link <https://www.pythonanywhere.com/user/stonecharioteer/shares/61f863777d13449599ecab5bf11ff34d/>`_. |
s = """Jrypbzr gb gur svefg Ivfn OnatClcref zrrghc rirelbar! | |
Guvf vf gur svefg gvzr jr'ir vaivgrq gur Onatnyber Clguba zrrghc pbzzhavgl gb bhe bssvpr, fb rirelbar gnxr n punapr gb argjbex. | |
Funer lbhe xabjyrqtr, lbhe gvcf naq lbhe rkcregvfr bs Clguba. | |
Nobir nyy, unir sha!! | |
Gb bhe ivfvgbef, Ivfn vf uvevat. Ernpu bhg gb hf naq funer lbhe erfhzrf.""" |