Skip to content

Instantly share code, notes, and snippets.

@e-roux
e-roux / receive.py
Last active November 30, 2020 22:30
Pika: basic consume
#!/usr/bin/env python
import pika, sys, os
def main():
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
@e-roux
e-roux / parity.py
Last active November 30, 2020 22:18
Python traitlets: example from documentation
# Example from traitlets documentation
from traitlets import Bool, HasTraits, Int, TraitError, observe, validate
class Parity(HasTraits):
value = Int()
parity = Int()
@validate("value")
#!/usr/bin/env zsh
hooks=(chpwd periodic precmd preexec zshaddhistory zshexit)
for hook in $hooks; do
# First eval the hook function, stored as string
eval "hook_func_str=$\"${hook}_functions\""
# [expansion rule](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Rules)
# [Parameter expansion flags](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags)
eval "hookfunc=\"${hook_func_str}\""
@e-roux
e-roux / setup.sh
Created September 26, 2020 08:58
Setup for zsh glob demo
# This gist is from
# https://reasoniamhere.com/2014/01/11/outrageously-useful-tips-to-master-your-z-shell/
cd ${TMP:-/tmp}
# create the folder structure
mkdir -p zsh_demo/{data,calculations}/africa/{kenya,malawi}/ \
zsh_demo/{data,calculations}/europe/{malta,poland}/ \
zsh_demo/{data,calculations}/asia/{nepal,laos}/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@e-roux
e-roux / vmware.md
Last active November 30, 2020 22:19

VMware

Troubleshooting on hosts with secure mode enabled

UEFI[^1] Secure Boot[^2] (SB) is a verification mechanism for ensuring that code launched by a computer's UEFI firmware is trusted. Unsigned drivers are therefor not allowed to load.

2 kernels modules are compiled at installation time and must be loaded. If the host provides the proper kernel headers and gcc, these two modules will be built silently. The progress is logged into /tmp/vmware-root/vmware-PID.log [^3].

On error type like:

@e-roux
e-roux / pydantic.py
Created February 5, 2020 07:02
Pydantic
from xml.etree.ElementTree import Element
import xml.etree.ElementTree as ET
from collections.abc import Iterator
from pydantic import BaseModel
from typing import Optional
def get_children(fragment, eltname):
return filter(lambda elt: elt.tag != eltname, fragment.find(eltname))
@e-roux
e-roux / marshmallow_xml.py
Created February 3, 2020 21:19
Sample pre_load and xml in marshmallow
from xml.etree.ElementTree import Element
import xml.etree.ElementTree as ET
from marshmallow import (Schema, pre_load)
from marshmallow.fields import (
Str,
Integer,
List,
Nested