Skip to content

Instantly share code, notes, and snippets.

@zparnold
zparnold / one_liner.sh
Last active April 25, 2024 21:56
A simply script to delete all failed pods from Kubernetes
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# this lives in superset_config.py
class AirbnbAuthRemoteUserView(AuthRemoteUserView):
def add_role_if_missing(self, sm, user_id, role_name):
found_role = sm.find_role(role_name)
session = sm.get_session
user = session.query(sm.user_model).get(user_id)
if found_role and found_role not in user.roles:
user.roles += [found_role]
session.commit()
@Daenyth
Daenyth / debug_requests.py
Created August 27, 2015 14:35
Enable debug logging for python requests
import requests
import logging
import httplib
# Debug logging
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
req_log = logging.getLogger('requests.packages.urllib3')
req_log.setLevel(logging.DEBUG)
@Zearin
Zearin / python_decorator_guide.md
Last active March 30, 2024 12:28
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

# coding=UTF-8
from __future__ import division
import nltk
from collections import Counter
# This is a simple tool for adding automatic hashtags into an article title
# Created by Shlomi Babluki
# Sep, 2013
@holman
holman / Guthrie IP.md
Last active August 4, 2016 03:30
Woody Guthrie, on intellectual property.

This song is Copyrighted in U.S., under Seal of Copyright # 154085, for a period of 28 years, and anybody caught singin it without our permission, will be mighty good friends of ourn, cause we don’t give a dern. Publish it. Write it. Sing it. Swing to it. Yodel it. We wrote it, that’s all we wanted to do.

  • Woody Guthrie, 1940's —
@nvie
nvie / sift.py
Last active December 18, 2015 15:28
The sift itertool.
from collections import deque
from functools import wraps
def inversify(predicate):
"""Returns a predicate that is the inverses of the given predicate."""
@wraps(predicate)
def _inner(*args, **kwargs):
return not predicate(*args, **kwargs)
return _inner
@nvie
nvie / p.fish
Created February 13, 2013 09:43
This is my favorite way of automatically invoking the best suitable Python REPL. It is smart about the environment that it is invoked in (e.g. will respect your current virtual env) and is smart about which interpreter fits best (e.g. using `ipython` if available, or using `python manage.py shell` in case of Django, or `python manage.py shell_pl…
function p --description 'Start the best Python shell that is available'
set -l cmd
if test -f manage.py
if pip freeze ^/dev/null | grep -q 'django-extensions'
set cmd (which python) manage.py shell_plus
else
set cmd (which python) manage.py shell
end
else
@alex-laties
alex-laties / djangosession.py
Created December 17, 2012 03:06
Accessing django sessions via a WSGI Middleware. Can be used in any python web stack that conforms to the PEP 333 WSGI specification. This includes bottle.
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' #not using env.put as that does not execute immediately
from django.conf import settings
SessionStore = __import__(settings.SESSION_ENGINE, fromlist=['']).SessionStore
class DjangoSessionWSGIMiddleware(object):
transform = false #doesn't transform output of anything above in the stack
def __init__(self, app):
self.app = app