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. 🔥
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from mymodule import main | |
import logging | |
class Command(BaseCommand): | |
help = 'Do foo' | |
def handle(self, *args, **options): |
Either copy the aliases from the .gitconfig
or run the commands in add-pr-alias.sh
Easily checkout local copies of pull requests from remotes:
git pr 4
- creates local branchpr/4
from the githubupstream
(if it exists) ororigin
remote and checks it outgit pr 4 someremote
- creates local branchpr/4
fromsomeremote
remote and checks it out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder