Skip to content

Instantly share code, notes, and snippets.

View carltongibson's full-sized avatar
🌳
Pruning branches

Carlton Gibson carltongibson

🌳
Pruning branches
View GitHub Profile
@carltongibson
carltongibson / middleware.py
Last active December 3, 2023 02:47
Django Middleware to have `request.is_secure()` always return `True`. Maybe preferred to a WSGI middleware. Refs: https://noumenal.es/notes/til/django/csrf-trusted-origins/
class HTTPSOnlyMiddleware:
"""
Override request.is_secure() to always return True.
Only use if you're **always** serving with HTTPS
**and** SECURE_PROXY_SSL_HEADER is not suitable for your setup.
"""
def __init__(self, get_response):
self.get_response = get_response
Gists are mini-repos.
* Add files.
* Clone
* Use that history.
* Share and comment.
@carltongibson
carltongibson / drf.code-snippets
Last active December 10, 2018 10:03
Sample VS Code snippets for use with Django REST Framework
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
@carltongibson
carltongibson / session.sh
Last active November 28, 2016 15:19
Django Filters 1.0.1 Install check
Last login: Mon Nov 28 15:49:38 on ttys002
~ $ mkvirtualenv df-import-test
Using base prefix '/Users/carlton/.pyenv/versions/3.5.0'
New python executable in df-import-test/bin/python3.5
Also creating executable in df-import-test/bin/python
Installing setuptools, pip, wheel...done.
(df-import-test)~ $ pip install Django djangorestframework django-filter
Collecting Django
Using cached Django-1.10.3-py2.py3-none-any.whl
Collecting djangorestframework
@carltongibson
carltongibson / python_resources.md
Last active August 29, 2015 14:27 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@carltongibson
carltongibson / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@carltongibson
carltongibson / draft.md
Last active August 29, 2015 14:10
Thoughts for DRF Third Party Packages Page

General Outline:

  1. About Third Party Packages
  2. How to create a Third Party Package
  3. Existing Third Party Packages
  4. Other Resources

About Third Party Packages

Third Party Packages allow developers to share code that extends the functionality of Django REST framework, in order to support additional use-cases.

@carltongibson
carltongibson / PrettyJSON.py
Created September 16, 2013 13:35
Pretty JSON for use as a BBEdit Text Filter
#! /usr/bin/python
import fileinput
import json
if __name__ == "__main__":
jsonStr = ''
for a_line in fileinput.input():
jsonStr = jsonStr + ' ' + a_line.strip()
jsonObj = json.loads(jsonStr)
print json.dumps(jsonObj, sort_keys=True, indent=2)