Skip to content

Instantly share code, notes, and snippets.

View kevinhowbrook's full-sized avatar
☯️
...probably writing a test

Kevin kevinhowbrook

☯️
...probably writing a test
View GitHub Profile
@jacobian
jacobian / models.py
Created February 15, 2011 18:11
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@evildmp
evildmp / gist:3094281
Last active June 30, 2023 10:55
Set up Django, nginx and uwsgi

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

@magnetikonline
magnetikonline / README.md
Last active March 14, 2024 22:48
IE 7/8/9/10/11 Virtual machines from Microsoft - Linux w/VirtualBox installation notes.
@Starefossen
Starefossen / tmux-cheats.md
Last active June 21, 2024 17:26
My personal tmux cheat sheet for working with sessions, windows, and panes. `NB` I have remapped the command prefix to `ctrl` + `a`.

Sessions

New Session

  • tmux new [-s name] [cmd] (:new) - new session

Switch Session

  • tmux ls (:ls) - list sessions
  • tmux switch [-t name] (:switch) - switches to an existing session
@suzannealdrich
suzannealdrich / settings.php
Last active June 28, 2017 22:27
Pantheon site environment base URL logic
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
switch ($_SERVER['PANTHEON_ENVIRONMENT']) {
case 'test':
$base_url = 'http://test-example.gotpantheon.com'; // NO trailing slash!
break;
case 'dev':
$base_url = 'http://dev-example.gotpantheon.com'; // NO trailing slash!
break;
case 'live':
$base_url = 'http://www.example.com'; // NO trailing slash!
@wsargent
wsargent / docker_cheat.md
Last active June 29, 2024 19:32
Docker cheat sheet
@pirhoo
pirhoo / reindex.py
Created October 23, 2013 16:50
This Django command helps us to reindex a model (especialy with Neo4j).
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import get_model
class Command(BaseCommand):
help = "Reindex a given model."
args = 'app.Model'
def handle(self, *args, **options):
if not args:
@wdullaer
wdullaer / install.sh
Last active June 29, 2024 11:54
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@yosemitebandit
yosemitebandit / crop_to_path.py
Created November 18, 2015 04:51
cut an image out based on a path in python with Pillow, Numpy and Shapely
"""Crop a polygonal selection from an image."""
import numpy as np
from PIL import Image
from shapely.geometry import Point
from shapely.geometry import Polygon
im = Image.open('bird.jpg').convert('RGBA')
pixels = np.array(im)
im_copy = np.array(im)
@eyesee1
eyesee1 / wagtail_remote_image.py
Created October 17, 2016 20:23
Grabbing image data from a URL and saving into Wagtail CMS - example code
from io import BytesIO
import requests
from django.core.files.images import ImageFile
from wagtail.wagtailimages.models import Image
# event is a model object, substitute your model
# filename and title are up to you
# in my model, event.event_image is a ForeignKey to wagtailimages.Image
response = requests.get(url)