Skip to content

Instantly share code, notes, and snippets.

@muendelezaji
muendelezaji / bash.git-prompt.sh
Created September 1, 2020 17:24
Customize Bash PS1 prompt to show current status of active Git branch
# Customize Bash PS1 prompt to show current status of active Git branch.
# Adapted from and inspired by http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# Slightly faster prompt, as measured on my machine (TM)
#
# By @muendelezaji, Oct 2015
# Skip if in zsh
[ "$ZSH" ] && return 0
# SETUP CONSTANTS
@muendelezaji
muendelezaji / get_pr.go
Last active November 4, 2022 01:52
Get PR number from a GitHub URL
// Derived from paste at https://pastebin.com/iwqG6zvH
// Lightly edited to make it run
// Original discussion: https://t.me/GolangTZ/475
// You can edit this code!
// Click here and start typing.
package main
import (
"bufio"
@muendelezaji
muendelezaji / diff_email_body.py
Created December 11, 2022 14:28
SendGrid - different email body depending on recipient status
# 1. Create dynamic body depending on status
if user_status == "paid":
body = f"Hello paid user: {user.first_name} {user_status}"
else:
body = f"Hello not paid user: {user.first_name} {user_status}"
# 2. Add it to recipient email substitutions
to_emails.append(
To(
email=user.user_email,
@muendelezaji
muendelezaji / payment-reference.py
Last active May 19, 2023 18:22
Create a simple unique payment reference to send to a provider
from datetime import datetime
def generate_payment_ref(email, method, country):
"""
Generates a unique payment reference that will be sent to the payment provider.
Examples of returned references:
- TENDA-TZ-CARD-20230519-181549-acustomer@somedomain.com
- TENDA-TZ-PUSH-20230519-181549-acustomer@somedomain.com
- TENDA-TZ-BANK-20230519-181549-acustomer@somedomain.com

History

If you work in the shell long enough your history will become your own personal reference. It's like automatic documentation which is the best kind of documentation.

Configuration

Unfortunately, the default configuration for history is not always great. You should already be familiar with variables such as $HISTFILE and $HISTSIZE.