Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tliron
tliron / fixed_thread_pool_executor.py
Last active September 26, 2022 21:32
Python fixed thread pool exuector
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 April 5, 2016 18:29
Give Linux executables the privilege to bind to ports below 1024
#!/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 January 8, 2022 13:34
Simple and functional REST server for Python (2.7) using no dependencies beyond the Python standard library.
#!/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