Skip to content

Instantly share code, notes, and snippets.

@ncole458
ncole458 / default
Last active April 18, 2018 10:42
Nginx 'sites-available' rewrite for Ember.js (Ember breaks on refresh 404)
# Ember breaks on refresh (404)
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
# Add the below rule to fix
@ncole458
ncole458 / settings.py
Created February 25, 2016 00:55
Django & Nginx w/Gunicorn full https
# Forward all to https for Django / DRF viewsets
# settings.py
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
# Nginx location header (see also http://nginx.org/en/docs/http/configuring_https_servers.html)
location / {
# ...
proxy_set_header X-Forwarded-Protocol $scheme;
# ...
<!-- Super simple fix for Android keyboard overlapping form inputs -->
<preference name="fullscreen" value="false" />
@ncole458
ncole458 / django
Created April 20, 2016 05:28
CORS for Django /media (FireFox fix)
# Your Django project's media files - amend as required
location /media {
if ($request_filename ~* ^.*?/([^/]*?)$) {
set $filename $1;
}
if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
add_header Access-Control-Allow-Origin *;
}
alias /django/django_project/media;
@ncole458
ncole458 / Postgres Cheatsheet
Last active December 14, 2017 04:29
CLI commands I seem to use sometimes & forget sometimes...
# connect to db
sudo -u postgres psql postgres
# export table as CSV
COPY table_name TO '/tmp/users_export.csv' DELIMITER ',' CSV HEADER;
# create db
CREATE DATABASE <name>;
# create role
@ncole458
ncole458 / django_queryset_group.py
Last active February 8, 2017 03:50
Django Group Multiple Querysets
from itertools import chain
from operator import attrgetter
group1_queryset = group1.objects.all() or filter()
group2_queryset = group2.objects.all() or filter()
result = sorted(
    chain(group1_queryset, group2_queryset),
    key=attrgetter('created'))
    
@ncole458
ncole458 / pycharm-venv.txt
Last active April 18, 2018 10:43
PyCharm VENV (How to configure PyCharm to use virtual environment)
# Reminder for me! How to configure PyCharm to use venv
- create virtual env as per usual via command line
- PyCharm > Preferences > Project / Project Interp.
- click cog > Add Local & and select Python from within local project bin
- Done!
@ncole458
ncole458 / httpd-app.conf
Created July 13, 2017 05:12
Apache Perms for DRF
# need to add the below or DRF will throw auth errors
WSGIPassAuthorization On
@ncole458
ncole458 / nginx.conf
Last active September 16, 2017 08:04
Enable gzip compression & add expires headers in nginx
# /etc/nginx/nginx.conf
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
gzip_vary on;
@ncole458
ncole458 / cli.txt
Last active March 29, 2018 03:23
CLI commands
# view all running processes
ps aux
# kill a process
sudo kill <PID>
# edit SSH keys
cd ~/.ssh
nano authorized_keys