Skip to content

Instantly share code, notes, and snippets.

View falkben's full-sized avatar
🚲

Ben Falk falkben

🚲
View GitHub Profile
@Mukei
Mukei / conda_environment_rename.sh
Created November 30, 2017 07:01
How to rename a conda environment (workaround)
#One workaround is to create clone environment, and then remove original one:
#(remember about deactivating current environment with deactivate on Windows and source deactivate on macOS/Linux)
conda create --name new_name --clone old_name --offline #use --offline flag to disable the redownload of all your packages
conda remove --name old_name --all # or its alias: `conda env remove --name old_name`
#There are several drawbacks of this method:
# time consumed on copying environment's files,
# temporary double disk usage.
@anatoly-kussul
anatoly-kussul / sync_async_deco.py
Last active March 1, 2024 16:27
Python sync-async decorator factory
class SyncAsyncDecoratorFactory:
"""
Factory creates decorator which can wrap either a coroutine or function.
To return something from wrapper use self._return
If you need to modify args or kwargs, you can yield them from wrapper
"""
def __new__(cls, *args, **kwargs):
instance = super().__new__(cls)
# This is for using decorator without parameters
if len(args) == 1 and not kwargs and (inspect.iscoroutinefunction(args[0]) or inspect.isfunction(args[0])):
@JustinTArthur
JustinTArthur / reverse_proxy_view.py
Last active April 15, 2024 11:43
A Django 1.4+ view function that acts as a reverse proxy. Great for testing locally or for using as a starting point to code that needs to cache or manipulate the proxied response. If one needs to proxy in production without any response manipulation, performing this in the web container (like nginx or apache) would be recommended instead of thi…
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def reverse_proxy(request):
"""
Reverse proxy for a remote service.
"""
path = request.get_full_path()
#Optionally, rewrite the path to fit whatever service we're proxying to.