Skip to content

Instantly share code, notes, and snippets.

View karthicraghupathi's full-sized avatar

Karthic Raghupathi karthicraghupathi

View GitHub Profile
@karthicraghupathi
karthicraghupathi / advanced_requests.py
Last active February 7, 2023 07:18
Advanced usage of python requests - timeouts, retries, hooks
import requests
from requests.adapters import HTTPAdapter, Retry
DEFAULT_TIMEOUT = 5
class TimeoutHTTPAdapter(HTTPAdapter):
"""Set a default timeout for all HTTP calls."""

Brew Bundle Brewfile Tips

Copyright & License

Unless otherwise noted (either in this file or in a file's copyright section) the contents of this gist are Copyright ©️2020 by Christopher Allen, and are shared under spdx:Creative Commons Attribution Share Alike 4.0 International (CC-BY-SA-4.) open-source license.

Sponsor

If you more tips and advice like these, you can become a monthly patron on my GitHub Sponsor Page for as little as $5 a month; and your contributions will be multipled, as GitHub is matching the first $5,000! This gist is all about Homebrew, so if you like it you can support it by donating to them or becoming one of their Github Sponsors.

@karthicraghupathi
karthicraghupathi / mail.py
Last active August 16, 2022 17:59
Send email in Python 3
import smtplib
import traceback
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formataddr, formatdate, parseaddr
from pathlib import Path
from typing import List
@karthicraghupathi
karthicraghupathi / alignment.patch
Created August 14, 2022 17:57
Installing Python 3.6.15 on PopOS / Ubuntu 22.04 via pyenv - Segmentation fault (core dumped) make: *** [Makefile:1102: install] Error 139
--- Include/objimpl.h
+++ Include/objimpl.h
@@ -250,7 +250,7 @@
union _gc_head *gc_prev;
Py_ssize_t gc_refs;
} gc;
- double dummy; /* force worst-case alignment */
+ long double dummy; /* force worst-case alignment */
} PyGC_Head;
@karthicraghupathi
karthicraghupathi / admin.py
Last active August 5, 2022 21:59
A Django Admin Paginator For MariaDB With Many Many Rows
from django.contrib import admin
from django.core.paginator import Paginator
from django.db import connection, transaction, OperationalError
from django.utils.functional import cached_property
class MariaDbInnoDbPaginator(Paginator):
"""
Paginator that enforces a 2 second timeout on the count operation.
If the operations times out, an approximate value is returned.
@karthicraghupathi
karthicraghupathi / time_limited_paginator.py
Created August 4, 2022 15:40 — forked from hakib/time_limited_paginator.py
CountTimeoutLimitPaginator - Paginator that enforced a timeout on the count operation.
class TimeLimitedPaginator(Paginator):
"""
Paginator that enforced a timeout on the count operation.
When the timeout is reached a "fake" large value is returned instead,
Why does this hack exist? On every admin list view, Django issues a
COUNT on the full queryset. There is no simple workaround. On big tables,
this COUNT is extremely slow and makes things unbearable. This solution
is what we came up with.
"""
@karthicraghupathi
karthicraghupathi / .bashrc
Created November 30, 2021 15:43 — forked from kevinoid/.bashrc
GnuPG pinentry script for terminal or graphical interface based on $PINENTRY_USER_DATA.
# ~/.bashrc: executed by bash(1) for non-login shells.
# If file exists (likely) copy fragment below into existing script:
# If stdin is a terminal
if [ -t 0 ]; then
# Set GPG_TTY so gpg-agent knows where to prompt. See gpg-agent(1)
export GPG_TTY="$(tty)"
# Set PINENTRY_USER_DATA so pinentry-auto knows to present a text UI.
export PINENTRY_USER_DATA=USE_TTY=1
@karthicraghupathi
karthicraghupathi / tee.sh
Created November 12, 2021 06:09
Write Output To File While Tailing It
# use the tee command to write to a file while also viewing it
# the following will redirect both stdout and stderr to the file
command 2&>1 | tee output.log
@karthicraghupathi
karthicraghupathi / bg_disown.sh
Created November 12, 2021 05:54
SSH - Keep Tasks Running Through Disconnects
# For a command that is currently running.
# First suspend current command
CTRL + Z
# Get a list of current jobs
jobs -l
# Then resume execution of the command in the background
bg
@karthicraghupathi
karthicraghupathi / install.sh
Created October 19, 2021 03:47
Install Python 3.6.15 on macOS 11.6 (Big Sur)
brew install [email protected] readline sqlite3 xz zlib
ASDF_PYTHON_PATCH_URL="https://github.com/python/cpython/commit/8ea6353.patch?full_index=1" \
CPPFLAGS="-I$(brew --prefix [email protected])/include -I$(brew --prefix zlib)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/System/Library/Frameworks/Tk.framework/Versions/Current/Headers" \
LDFLAGS="-L$(brew --prefix [email protected])/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix readline)/lib" \
asdf install python 3.6.15