Skip to content

Instantly share code, notes, and snippets.

View antevens's full-sized avatar

Antonia Stevens antevens

View GitHub Profile

Keybase proof

I hereby claim:

  • I am antevens on github.
  • I am antonia (https://keybase.io/antonia) on keybase.
  • I have a public key whose fingerprint is 63E1 CDD0 8FA8 15A9 7C9C 3BA3 4B73 F0AF 07D2 7861

To claim this, I am signing this object:

Create a script, this can easily be ported/re-written, I used /usr/local/bin/get_real_filename
#!/bin/bash
while read line ; do
abs_path="$(readlink "${line}")"
echo "processing ${line}" >> /tmp/log
if [ -n "${abs_path}" ] ; then
stdbuf --output=0 echo "$(basename "${abs_path}")"
else
stdbuf --output=0 echo 'NULL'
@antevens
antevens / gist:5fe0a2da90c1642229f0977dea92d322
Created August 27, 2019 19:20
Trying to fetch a container image from Crane (3.0.0) with Microk8s 1.16 (dockerd)
astevens@anthill:/var/snap/microk8s$ sudo snap refresh microk8s --channel=1.16/edge
microk8s (1.16/edge) v1.16.0-alpha.3 from Canonical✓ refreshed
astevens@anthill:/var/snap/microk8s$ microk8s.ctr --debug image pull --user user:pass docker.example.com/default_organization-example-docker:latest
DEBU[0000] fetching image="docker.example.com/default_organization-example-docker:latest"
DEBU[0000] resolving
DEBU[0000] do request request.headers=map[Accept:[application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, *]] request.method=HEAD url="https://docker.example.com/v2/default_organization-example-docker/manifests/latest"
DEBU[0000] fetch response received response.headers=map[Content-Type:[text/html; charset=iso-8859-1] Date:[Tue, 27 Aug 2019 1
@antevens
antevens / gist:32646c5ea9bd526d9a19d6d442b2867e
Last active July 5, 2022 13:37
A keyboard layout optimized for all languages that use Latin based character sets (including programming).
* Note that this layout is quite similar to Colekmak in many ways, once optimisations were done I fould that like with * Colemak moving the Z/X/C/V did not have a noticable impact but caused issues with shortcuts.
* The biggest difference is making sure vovels are easily used with accents/diacritics
* Keymap: Layer 0 with Gelatin keyboard layout
* Note that this layout requires a custom OS keyboard map to work correctly.
* Tertiary symbols are accessed using LAlt
* Deadkey functionality is used to combine accents/diacritics and alphabetic letters
* ,--------------------------------------------------. ,--------------------------------------------------.
* | +L1 | 1 !¡ | 2 @ | 3 # | 4 $ §| 5 % ˝|˘ ̑ ˚ | |˘ ̑ · | 6 ^ ̏| 7 & | 8 * | 9 + | 0 = | L0 |
* |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
#include <Python.h>
#include <string.h>
/*
This program imports a Python module and checks for any instances of a
the predefined python class or instances of child classes.
Each instance is considered to represent a subcommand which will be made
available as a subcommand under this program.
Note that under no circumstances should the subcommands be spawned using
any shell or should shells be invoked due to security concerns.
def set_uid_gid(set_rguid_to_eguid=False, set_eguid_to_rguid=False, restore_ids=True):
"""
A decorator to set/swap real/effective UID/GID for the duration of an operation
EUID: Effective user ID, this is what is used to check permissions
RUID: Real user ID, this is used to determine who the original user is
when escalating priv. to determine the original user
SUID: Saved user ID, this is used to store original user ID when a process
needs to temporarily deescalate it's priv but is used to re-escalate.
"""
def run_as_root(func):
"""
A decorator to run a code block as the root user, assumes that user has
permissons to switch to root (see euid, ruid, suid)
"""
def inner(*args, **kwargs):
current_proc = multiprocessing.current_process()
logger.debug("Changing permissions for process: {0} with PID: {1}".format(current_proc.name, str(current_proc.pid)))
if sys.version > "2.7":
ruid, euid, suid = os.getresuid()
echo "satsrtrss" && bash
@antevens
antevens / gist:7603300
Created November 22, 2013 17:02
Bash figure out which OS we are running on
# Figure out OS
osfamily='Unknown'
apt-get help > /dev/null 2>&1 && osfamily='Debian'
yum help help > /dev/null 2>&1 && osfamily='RedHat'
if [ "${OS}" == 'SunOS' ]; then osfamily='Solaris'; fi
if [ `echo "${OSTYPE}" | grep 'darwin'` ]; then osfamily='Darwin'; fi
if [ "${OSTYPE}" == 'cygwin' ]; then osfamily='Cygwin'; fi
echo "Detected OS based on: ${osfamily}"
case ${osfamily} in
"RedHat")
@antevens
antevens / gist:7603277
Created November 22, 2013 17:01
Bash exit on failure command
# Exit on failure function
function exit_on_fail {
echo "Last command did not execute successfully but is required to proceed!" >&2
echo "Exiting and rolling back all changes!" >&2
exit 1
}
#USAGE EXAMPLE
sudo yum install puppet || exit_on_fail