Skip to content

Instantly share code, notes, and snippets.

@jurrian
jurrian / settings.py
Created September 30, 2021 10:20
Client-side rate limiting for Sentry
import logging
import sentry_sdk
from ratelimitingfilter import RateLimitingFilter
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
# Sentry
sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture info and above as breadcrumbs
@bmcbm
bmcbm / setup-nvdia-suspend.sh
Last active May 16, 2024 16:09
NVIDIA Suspend fix
# Use systemd for managing NVIDIA driver suspend in drivers ====>>> PRIOR to version 470 <<<=====
# https://download.nvidia.com/XFree86/Linux-x86_64/450.66/README/powermanagement.html
# https://forums.developer.nvidia.com/t/unable-to-set-nvidia-kernel-module-parameters/161306
# Please note: In Fedora Linux you may need to just install the xorg-x11-drv-nvidia-power pakage
# as sugested by @goombah88 in the comments below.
TMP_PATH=/var/tmp
TMPL_PATH=/usr/share/doc/nvidia-driver-460/
echo "options nvidia NVreg_PreserveVideoMemoryAllocations=1 NVreg_TemporaryFilePath=${TMP_PATH}" | sudo tee /etc/modprobe.d/nvidia-power-management.conf
@pymen
pymen / advanced_logger.py
Last active April 16, 2021 17:56
AdvancedLogger
import logging
class AdvancedLogger:
"""
AdvancedLogger can be used for fine grained logging temporary modifications
How it works:
Modifications will be enabled when context_manager/decorator starts working and be reverted after
@mnesarco
mnesarco / objects.py
Created July 23, 2020 16:54
Enhanced python properties with some metaprog.
# file: objects.py
# Copyright 2020 Frank David Martínez Muñoz (mnesarco)
# License: MIT
from typing import Union
__all__ = ('self_properties', 'properties')
def self_properties(self, scope: dict, exclude=(), save_args: bool = False):
@prbinu
prbinu / openssh-7.6-ubuntu-16.04.sh
Last active March 14, 2024 08:08
How to build (and install) OpenSSH 7.6 packages on Ubuntu-16.04
# on a fresh Ubuntu 16.04 host
sudo apt-get update
# copy Ubuntu source packages from http://archive.ubuntu.com/ubuntu/pool/main/o/openssh
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_7.6p1-4.dsc
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_7.6p1.orig.tar.gz
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_7.6p1.orig.tar.gz.asc
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_7.6p1-4.debian.tar.xz
@ipmb
ipmb / settings.py
Last active November 24, 2023 20:25
Django logging example
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
@exAspArk
exAspArk / curl.sh
Last active May 1, 2024 03:59
Test CORS with cURL
curl -I -X OPTIONS \
-H "Origin: http://EXAMPLE.COM" \
-H 'Access-Control-Request-Method: GET' \
http://EXAMPLE.COM/SOMETHING 2>&1 | grep 'Access-Control-Allow-Origin'
@zmts
zmts / tokens.md
Last active May 20, 2024 12:40
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@Jc2k
Jc2k / README.md
Last active March 30, 2023 10:31
Database rollback options in Django

Batching migrations

The idea here is that if you know which migrations were in version 2.0.3 of your project and which were in version 2.0.4 then setA - setB gives you the list of migrations you need to undo.

Django migrations give you a directed acyclic graph which describes how to get from the current database state to the target state. But there is no mechanism by which you can perform tasks like revert all the migrations that just ran in the last deployment.

Here is a quick recipe for batching Django migrations to allow you to do things like that.

Before you tag your project you do:

//oauth2 auth
chrome.identity.getAuthToken(
{'interactive': true},
function(){
//load Google's javascript client libraries
window.gapi_onload = authorize;
loadScript('https://apis.google.com/js/client.js');
}
);