Skip to content

Instantly share code, notes, and snippets.

@barretthugh
barretthugh / client.py
Created July 10, 2023 15:56 — forked from vsajip/README.md
Run a logging socket receiver in a production setting with logging from an example webapp
from concurrent.futures import ThreadPoolExecutor, as_completed
import json
import urllib.request
with open('webapp.json', encoding='utf-8') as f:
config = json.loads(f.read())
URLS = [
'http://localhost:%d/?ident=%d' % (config['port'], ident)
for ident in range(1, 1001)
@barretthugh
barretthugh / list.md
Created June 17, 2021 17:06 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@barretthugh
barretthugh / monitoring.py
Created January 2, 2021 13:38 — forked from vxgmichel/monitoring.py
Command line interface for monitoring asyncio tasks
"""Command line interface for monitoring asyncio tasks."""
import os
import signal
import asyncio
import argparse
import traceback
import linecache
from itertools import count
@barretthugh
barretthugh / aproducer.py
Created December 29, 2019 07:30 — forked from dabeaz/aproducer.py
"Build Your Own Async" Workshop - PyCon India - October 14, 2019 - https://www.youtube.com/watch?v=Y4Gt3Xjd7G8
# aproducer.py
#
# Async Producer-consumer problem.
# Challenge: How to implement the same functionality, but no threads.
import time
from collections import deque
import heapq
class Scheduler:
# -*- coding: utf-8 -*-
from airflow.operators.http_operator import SimpleHttpOperator
from airflow.operators.postgres_operator import PostgresOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import Variable, DAG
from datetime import date, datetime, timedelta
@barretthugh
barretthugh / task-dag-creation.py
Created May 1, 2019 16:54 — forked from tmarthal/task-dag-creation.py
DAG Creation from within a PythonOperator task DOES NOT WORK
# -*- coding: utf-8 -*-
from airflow.operators.http_operator import SimpleHttpOperator
from airflow.operators.postgres_operator import PostgresOperator
from airflow.operators.subdag_operator import SubDagOperator
from airflow.operators.sensors import SqlSensor
from airflow.hooks.postgres_hook import PostgresHook
from airflow.operators.python_operator import PythonOperator
from airflow.models import Variable, DAG
@barretthugh
barretthugh / delete_dag.py
Created May 1, 2019 16:45
Delete Dag Task
def delete_dag(**kwargs):
from airflow import models, settings
from airflow.exceptions import AirflowException
from sqlalchemy import or_
dag_id = kwargs["params"]["dag_id"]
print "Started deleting DAG id: {}".format(dag_id)
session = settings.Session()
DM = models.DagModel
# Written by Aaron Cohen -- 1/14/2013
# Brought to you by BitTorrent, Inc.
# "We're not just two guys in a basement in Sweden." TM
#
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
# See: http://creativecommons.org/licenses/by/3.0/
import sys
import re
import socket