Skip to content

Instantly share code, notes, and snippets.

@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}/
#!/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 / 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")
@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):