Skip to content

Instantly share code, notes, and snippets.

@noxdafox
noxdafox / attach_ebs_volume.sh
Created March 18, 2020 15:56
AverageWebServices is so bad it requires you to attach EBS volumes to its crappy EC2 instances
#!/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 / tricks.sh
Last active October 23, 2022 14:52
Collection of bash tricks
# 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
## one-liner
@noxdafox
noxdafox / conflict.clp
Last active February 28, 2019 07:51
This snippet shows the behaviour of a simple CLIPS rule set with different conflict resolution strategy.
(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 February 24, 2023 14:27
Usage example of RabbitMQ exchange deduplication plugin
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 / max_queue_size_pool.py
Created April 15, 2018 17:58
This code snippet shows how to wrap a concurrent.futures.Executor class to provide a limited queue size.
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.