Skip to content

Instantly share code, notes, and snippets.

@pymen
pymen / popcorntime-vpn.sh
Created September 25, 2023 07:51 — forked from Schnouki/popcorntime-vpn.sh
OpenVPN for a single application using network namespaces -- helper scripts
#!/usr/bin/env zsh
# Initialize VPN
sudo vpnns up
sudo vpnns start_vpn
# Popcorn time!
sudo ip netns exec frootvpn sudo -u $USER popcorntime
# Cleanup
@pymen
pymen / autovpn.py
Created August 8, 2023 07:46 — forked from domenkozar/autovpn.py
AutoVPN for NetworkManager
#!/usr/bin/env python
"""
Copyright 2011 Domen Kozar. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
@pymen
pymen / transactionawaretask.py
Created December 3, 2022 14:46 — forked from miohtama/transactionawaretask.py
Transaction-aware Celery tasks for Pyramid - only run the task after the transaction has committed
"""Transaction-aware Celery task handling.
Core originally written for Warehouse project https://raw.githubusercontent.com/pypa/warehouse/master/warehouse/celery.py
"""
from celery import Task
from pyramid import scripting
from pyramid.interfaces import IRequest
from pyramid.request import Request
@pymen
pymen / setup-nvdia-suspend.sh
Created August 22, 2022 05:33 — forked from bmcbm/setup-nvdia-suspend.sh
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 / remove_stale_contenttypes2.py
Created April 28, 2022 09:16
remove_stale_contenttypes
import itertools
from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.core.management import BaseCommand
from django.db import DEFAULT_DB_ALIAS, router
from django.db.models.deletion import Collector
class Command(BaseCommand):
@pymen
pymen / LazyObject
Created January 13, 2022 15:06
LazyPython Object (set lazy python attribute as func + kwargs)
import operator
class LazyObject:
_wrapped = None
_is_init = False
def __init__(self, factory, **factory_kwargs):
# Assign using __dict__ to avoid the setattr method.
self.__dict__['_factory'] = factory
@pymen
pymen / script-template.sh
Created November 23, 2021 09:21 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@pymen
pymen / celery.sh
Created February 12, 2021 14:45 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@pymen
pymen / squashmigrations19.py
Created October 20, 2020 13:30
Django Squash Migrations From To [from Django 1.9]
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections, migrations
from django.db.migrations.loader import AmbiguityError, MigrationLoader
from django.db.migrations.migration import SwappableTuple
from django.db.migrations.optimizer import MigrationOptimizer
from django.db.migrations.writer import MigrationWriter
from django.utils import six
from django.utils.version import get_docs_version