Skip to content

Instantly share code, notes, and snippets.

I've been working with Apache Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥

Get the tools

@cwgem
cwgem / python_tar_fun.md
Created June 30, 2018 21:58
Fun ways to fool with python tar handling

Introduction

Python's tarfile documentation leaves the following nasty warning:

Warning Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".

Let's see what that exactly means.

@mrcfps
mrcfps / bank_test.py
Created February 15, 2018 07:30
Exploration of how to test concurrency in Python
from __future__ import print_function
import platform
import sys
import threading
import time
class UnsyncedBankAccount(object):
"""Bank account with no synchronization lock, prone to race condition."""
@imbilltucker
imbilltucker / Python_Things_I'm_glad_I_know
Last active January 27, 2021 15:09
things I wish I knew starting python
Things I wish I knew when starting python
improve the basic interpreter
PYTHONSTARTUP is an environment variable you can use to fix the command prompt, i.e. provide autocomplete via tab, and suggestions.
set $PYTHONSTARTUP=~/.pythonstartup in .bashrc
export PYTHONSTARTUP=~/.pythonstartup
turn off creation of .pyc files
PYTHONDONTWRITEBYTECODE=1
@monkut
monkut / argparse_date_datetime_custom_types.py
Last active May 10, 2023 15:47
Custom date/datetime type validators for python's argparse module
def valid_date_type(arg_date_str):
"""custom argparse *date* type for user dates values given from the command line"""
try:
return datetime.datetime.strptime(arg_date_str, "%Y-%m-%d")
except ValueError:
msg = "Given Date ({0}) not valid! Expected format, YYYY-MM-DD!".format(arg_date_str)
raise argparse.ArgumentTypeError(msg)
def valid_datetime_type(arg_datetime_str):
"""custom argparse type for user datetime values given from the command line"""
@mkocikowski
mkocikowski / gist:aeca878d58d313e902bb
Last active June 17, 2024 14:44
Setting up Redis to run as a daemon under systemd

This can be used to daemonize anything that would normally run in the foreground; I picked Redis. Put this in /etc/systemd/system/redis.service:

[Unit]
Description=Redis
After=syslog.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
RestartSec=5s
@epicserve
epicserve / example_command.py
Created October 30, 2013 17:05
Example of how to setup logging for a Django management command.
from django.core.management.base import BaseCommand
from mymodule import main
import logging
class Command(BaseCommand):
help = 'Do foo'
def handle(self, *args, **options):
@gnarf
gnarf / ..git-pr.md
Last active April 12, 2024 22:00
git pr - Global .gitconfig aliases for Pull Request Managment

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from remotes:

  • git pr 4 - creates local branch pr/4 from the github upstream(if it exists) or origin remote and checks it out
  • git pr 4 someremote - creates local branch pr/4 from someremote remote and checks it out
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active July 17, 2024 14:20
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@tdd
tdd / gitconfig.ini
Last active April 17, 2024 10:04
Nice, useful global Git configuration
# Put this in your ~/.gitconfig or ~/.config/git/config
# Windows users: "~" is your profile's home directory, e.g. C:\Users\<YourName>
[user]
name = Your Full Name
email = your@email.tld
[color]
# Enable colors in color-supporting terminals
ui = auto
[alias]
# List available aliases