Skip to content

Instantly share code, notes, and snippets.

View Alir3z4's full-sized avatar
💭
Rock'nRolla

Alireza Savand Alir3z4

💭
Rock'nRolla
View GitHub Profile
@dmutende
dmutende / oauth2_graphql_readme.txt
Last active January 16, 2020 16:35
Warpping GraphQL endpoints with Django OAuth2 Toolkit's ProtectedResourceView to secure them using OAuth2.0
- create a .py file with 2 classes (OAuth2ProtectedResourceMixin and OAuth2ProtectedGraph). see 'utils.py' file
- then in your Django's 'urls.py', wrap the graphql endpoint. see 'urls.py.

CockroachDB + Django ORM

cockroachdb/sqlalchemy-cockroachdb#14

TODO

  1. fork django/contrib/postgres driver
  2. patch blocking postgres compatibility issues
  3. review with cockroachdb team to see if any issues can be fixed by cockroach
  4. review with django team
  5. merge adapter as separate cockroachdb adapter
  6. write docs, any admin work, etc.
@kylefox
kylefox / post_compile.sh
Last active October 23, 2020 08:42
Run Django database migrations after deploy to Heroku. This file must live at `bin/post_compile` within your root project directory.
# !/usr/bin/env bash
# File path should be ./bin/post_compile
# (.sh extension added in Gist just to enable shell syntax highlighting.
# https://discussion.heroku.com/t/django-automaticlly-run-syncdb-and-migrations-after-heroku-deploy-with-a-buildpack-or-otherwise/466/7
echo "=> Performing database migrations..."
python manage.py migrate
@mariocesar
mariocesar / fields.py
Last active December 28, 2021 19:59
Django state field that enforce a workflow path
from collections import namedtuple
from functools import wraps
from itertools import chain
from django.utils.functional import curry
from django.db.models import CharField
class StateField(CharField):
Starts = namedtuple('Starts', ['state'])
@Alir3z4
Alir3z4 / middleware.py
Last active December 16, 2020 13:01
When running on AWS Elastic Beanstalk, we suffer an issue where HTTPS requests arriving at the load balancer are propagated to the individual hosts as HTTP requests. If the host issues a redirect it issues it using the same scheme as its incoming request (HTTP) when it should use HTTPS. This issue isn't unique to AWS EB, it's discussed in the co…
from django.http import HttpResponsePermanentRedirect
class SecureRequestPropagationMiddleware(object):
"""
When running on AWS Elastic Beanstalk, we suffer
an issue where HTTPS requests arriving at the load
balancer are propagated to the individual hosts as
HTTP requests. If the host issues a redirect it
issues it using the same scheme as its incoming
@koenpunt
koenpunt / chosen-bootstrap.css
Last active March 11, 2023 01:01
Bootstrap 3.0 theme for Chosen
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555;
vertical-align: middle;
background-color: #fff;
@Alir3z4
Alir3z4 / middleware.py
Created July 19, 2013 10:54
She's a Rock'nRoll Ruby! -- Simple IP blocker django middleware.
from django.conf import settings
from django import http
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
@Alir3z4
Alir3z4 / bring_mongo_back.sh
Last active December 16, 2020 13:23
setup a simple as dummy mongodb on ubuntu
sudo apt-get update
sudo apt-get upgrade
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
sudo sudo apt-get -y update
sudo apt-get -y install mongodb-10gen
# Start mongodb on startup
sudo update-rc.d mongodb defaults
@Alir3z4
Alir3z4 / decorator.py
Created June 1, 2013 16:45
Decorator to check whether user is super user or not If user is not a super-user, it will raise PermissionDenied or 403 Forbidden.
from functools import wraps
from django.core.exceptions import PermissionDenied
def superuser_required(method):
"""
Decorator to check whether user is super user or not
If user is not a super-user, it will raise PermissionDenied or
403 Forbidden.
"""
@Alir3z4
Alir3z4 / gist:5498409
Created May 1, 2013 21:10
direct_to_template to TemplateView django1.3 to newer ;)
find: direct_to_template, \{'template': ('[a-z/.\w-]+')}
replace: TemplateView.as_view(template_name=$1)