Skip to content

Instantly share code, notes, and snippets.

View nlm's full-sized avatar
🚀

Nicolas Limage nlm

🚀
View GitHub Profile
@nlm
nlm / gist:a69407a3f652cfc7e2905909008c1633
Created December 2, 2016 14:16
Install pip package directly from Github
pip install git+https://github.com/USER/REPO.git
@nlm
nlm / demo_asyncio_queue_interrupt.py
Last active November 16, 2016 08:26
Demo of asyncio feeder/worker model using queue + interruption handling
import asyncio
import random
queue = asyncio.Queue()
@asyncio.coroutine
def feeder():
try:
fid = random.randint(100, 999)
print('feeder {} activated'.format(fid))
@nlm
nlm / ipaddr_sorter.py
Created October 28, 2016 12:18
Object to sort IP addresses according to a best-match in an ip networks list
from ipaddr import IPv4Network, IPv4Address
"""
A module to sort ip addresses according to the best-match
in an ip networks list. If no matching network is found, ip
is sorted last.
example:
>>> networks = ['10.0.0.0/8', '172.16.0.0/12', '172.16.9.0/24']
@nlm
nlm / async_loop.py
Created October 18, 2016 08:18
python async loop demo to understand asyncio basics
from functools import wraps
from types import FunctionType, GeneratorType
import logging
import time
def coroutine(f):
@wraps(f)
def wrapper(*args, **kwargs):
logging.debug('coroutine starting: {}'.format(f.__name__))
return f(*args, **kwargs)
@nlm
nlm / connect-qemu-serial.sh
Created September 13, 2016 15:37
Connect to QEMU unix socket serial port
#!/bin/sh
SOCKDIR="/var/lib/qemu/sockets"
HOSTNAME="$1"
if [ -z "$HOSTNAME" ]
then
echo "usage: $0 HOSTNAME" >&2
exit 1
fi