Skip to content

Instantly share code, notes, and snippets.

@tliron
tliron / fixed_thread_pool_executor.py
Last active Apr 19, 2021
Python fixed thread pool exuector
View fixed_thread_pool_executor.py
from threading import Thread, Lock
from Queue import Queue
import itertools, traceback, multiprocessing
class FixedThreadPoolExecutor(object):
"""
Executes tasks in a fixed thread pool.
Makes sure to gather all returned results and thrown exceptions in one place, in order of task
submission.
@tliron
tliron / bind-port-privilege.sh
Created Apr 5, 2016
Give Linux executables the privilege to bind to ports below 1024
View bind-port-privilege.sh
#!/bin/bash
if (( $# != 2 )); then
echo 'Control whether an executable has the privilege to bind to ports < 1024, even if the user is not root'
echo
echo "Usage: $(basename "$0") [enable|disable|status] [path-to-exectuable]"
exit 1
fi
FILE=$(readlink -f "$2")
@tliron
tliron / rest.py
Last active Feb 19, 2021
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library.
View rest.py
#!/usr/bin/env python
'''
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library.
Features:
* Map URI patterns using regular expressions
* Map any/all the HTTP VERBS (GET, PUT, DELETE, POST)
* All responses and payloads are converted to/from JSON for you