Skip to content

Instantly share code, notes, and snippets.

@pvsune
pvsune / timeout.py
Created May 31, 2020 15:03
A helper function to limit execution of a function in seconds.
import logging
from multiprocessing import Pool, TimeoutError
logging.basicConfig(level=logging.INFO)
def timeout(func, args=None, kwds=None, timeout=10):
"""Call function and wait until timeout.
@pvsune
pvsune / concurrent.kafka.consumer.py
Last active November 2, 2024 03:08
A multiprocess multithreaded Kafka consumer
#!/usr/bin/env python
import logging
import os
import threading
import time
from multiprocessing import Process
from queue import Queue
from confluent_kafka import Consumer
@pvsune
pvsune / django.sqlite.fields.py
Created November 25, 2019 07:44
Django custom Model fields to implement PostgreSQL specific fields in SQLite
import json
from django.conf import settings
from django.contrib.postgres.fields import (
JSONField as DjangoJSONField,
ArrayField as DjangoArrayField,
)
from django.db.models import Field
@pvsune
pvsune / sample.drone.yml
Created April 7, 2019 02:35
Drone CI sample caching config
kind: pipeline
name: default
steps:
- name: publish
image: plugins/ecr
environment:
PLUGIN_STORAGE_DRIVER: overlay2
PLUGIN_CACHE_FROM: xxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/pvsune/myapp:latest
settings: