Skip to content

Instantly share code, notes, and snippets.

View ranelpadon's full-sized avatar

ranelpadon

View GitHub Profile
@riklomas
riklomas / adding-to-user-admin-form.py
Created August 6, 2010 15:01
How to add a field to the Django Admin Add User form using UserCreationForm. Add this to a admin.py and alter to whatever fields you'd like
# How to add a field to the Django Admin Add User form
# using UserCreationForm. Add this to a admin.py and alter
# to whatever fields you'd like
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
@rctay
rctay / gist:527113
Created August 16, 2010 15:18
[django] check if db table exists
"""
Came up with this for satchmo's downloadable product migration, 0001_split.
"""
def db_table_exists(table, cursor=None):
try:
if not cursor:
from django.db import connection
cursor = connection.cursor()
if not cursor:
raise Exception
@issackelly
issackelly / gist:928783
Created April 19, 2011 16:48
Django Template {{ block.super }} example
# Template: A.html
<html>
<head></head>
<body>
{% block hello %}
HELLO
{% endblock %}
</body>
</html>
@dlanger
dlanger / pd.sh
Created July 4, 2012 02:35
Tmux start-up script
#!/bin/sh
cd ~/proj/root
tmux new-session -d -s pdev
tmux new-window -t pdev:1 -n shell
tmux rename-window -t pdev:1 "shell"
tmux send-keys -t pdev:1 "workon pdev" Enter "PS1=\$_OLD_VIRTUAL_PS1" Enter "clear" Enter
@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:

@jacobvosmaer
jacobvosmaer / gist:3187346
Created July 27, 2012 10:35
Open all files with git merge conflicts in Vim

Open all files with git merge conflicts in MacVim

git diff --name-only | uniq | xargs mvim

When git encounters a merge conflict, e.g. during a rebase, it drops you back into the shell with a dirty working directory. I like this one-liner for opening all files with a merge conflict in MacVim.

Once you're in Vim, you can then switch between the files with :n and :prev, or another favourite: :w | n (save current file and open the next command line-supplied file).

UPDATE: see below for a version that works with real terminal commands.

@JustAdam
JustAdam / drupal_taxonomy_content_type.php
Created August 2, 2012 09:49
Drupal 7 - Programmatically create a taxonomy and attach a field to it, then create a content type and attach that taxonomy to it.
<?php
// Machine name for our custom node
define('NODE_NAME', 'the_node_machine_name');
// Machine name for our custom taxonomy
define('TAXONOMY_NAME', 'the_taxonomy_machine_name');
function module_install() {
_create_taxonomy();
_create_content_type();
}
@becw
becw / example.install.php
Last active March 26, 2019 06:53
Enable/revert a feature in a Drupal update hook #drupal7
/**
* EXAMPLE FEATURE UPDATE
* Enable and revert the my_new_feature_name feature.
*/
function example_update_7001() {
// An array of new or changed features; the array keys are feature names,
// values are an array of exportable types as seen in a feature's .info file:
// features[field][] = node-page-body
$features = array(
'my_new_feature_name' => array('field', 'variable'),
@larrybotha
larrybotha / readme.markdown
Last active October 27, 2021 04:28
Postfix Using Gmail SMTP in Mac OSX Mavericks
@igniteflow
igniteflow / env-context.py
Last active December 12, 2023 16:43
A Python context manager for setting/unsetting environment variables
from contextlib import contextmanager
"""
Usage:
with env_var('MY_VAR', 'foo'):
# is set here
# does not exist here
"""