Skip to content

Instantly share code, notes, and snippets.

Avatar

Matteo Cafasso noxdafox

View GitHub Profile
@noxdafox
noxdafox / conflict.clp
Last active Feb 28, 2019
This snippet shows the behaviour of a simple CLIPS rule set with different conflict resolution strategy.
View conflict.clp
(deftemplate complaint
(slot customer))
(deftemplate manager
(slot name)
; managers have a list of assigned customers
(multislot assigned-customers))
(deffunction respond-to-customer (?customer ?message)
(printout t "Dear " ?customer ", " crlf ?message crlf))
@noxdafox
noxdafox / exchange_level_deduplication.py
Last active Jun 14, 2019
Usage example of RabbitMQ exchange deduplication plugin
View exchange_level_deduplication.py
import pika
from hashlib import md5
RABBITMQ_URL = 'amqp://guest:guest@localhost:5672/'
parameters = pika.URLParameters(RABBITMQ_URL)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
# Declare exchange, queue and bind them together
@noxdafox
noxdafox / tricks.sh
Last active Oct 16, 2019
Collection of bash tricks
View tricks.sh
# Average file size in folder
# Credits: http://www.bradlanders.com/2011/04/27/bash-one-liner-average-file-size-in-current-directory/
ls -l | awk '{s+=$5} END {print "Average file size: " s/NR/1024 "k"}'
# Clear Docker related data
docker kill $(docker ps -q) # Kill running containers
docker rm $(docker ps -a -q) # Remove existing containers
docker rmi $(docker images -q) # Remove images
docker rmi $(docker images -q -f dangling=true) # Remove untagged images
@noxdafox
noxdafox / attach_ebs_volume.sh
Created Mar 18, 2020
AverageWebServices is so bad it requires you to attach EBS volumes to its crappy EC2 instances
View attach_ebs_volume.sh
#!/bin/bash
#
# Attach AverageWebServices EBS volume to EC2 instance.
#
# Usage: attach_ebs_volume.sh <region> <instance-name> <device-name> <mount-point>
# Example: attach_ebs_volume.sh eu-west-1 my-ec2-instance /dev/xvdc /data
#
aws_region=$1
instance_name=$2
@noxdafox
noxdafox / max_queue_size_pool.py
Created Apr 15, 2018
This code snippet shows how to wrap a concurrent.futures.Executor class to provide a limited queue size.
View max_queue_size_pool.py
from threading import BoundedSemaphore
from concurrent.futures import ProcessPoolExecutor
class MaxQueuePool:
"""This Class wraps a concurrent.futures.Executor
limiting the size of its task queue.
If `max_queue_size` tasks are submitted, the next call to submit will block
until a previously submitted one is completed.
You can’t perform that action at this time.