Skip to content

Instantly share code, notes, and snippets.

View pije76's full-sized avatar

panjianom pije76

View GitHub Profile
<?php
// This is a sample PHP script that demonstrates accepting a POST from the
// Unbounce form submission webhook, and then sending an email notification.
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
@pije76
pije76 / dreamhost_python_setup.sh
Created October 20, 2012 19:49 — forked from wting/dreamhost_python_setup.sh
Dreamhost Python Setup script
#!/usr/bin/env bash
# Written by William Ting for the following blog post:
# http://williamting.com/posts/2012/04/18/set-up-python-and-django-on-dreamhost/
rcfile="${HOME}/.bashrc"
version="2.7.3"
setuptools_version="2.7"
tmp_dir="${HOME}/tmp-${RANDOM}"
if [[ ${#} == 0 ]]; then
@pije76
pije76 / class2go.wsgi
Created October 22, 2012 21:30 — forked from nveid/class2go.wsgi
class2go.wsgi
import os, sys
import site
# Remember original sys.path.
prev_sys_path = list(sys.path)
# we add currently directory to path and change to it
pwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(pwd)
sys.path = [pwd] + sys.path
@pije76
pije76 / applicationcontentconfig.py
Created October 24, 2012 06:21
ElephantBlog Config
Page.create_content_type(ApplicationContent, APPLICATIONS=(
('elephantblog.urls', _('Blog')),
))
@pije76
pije76 / settings.py
Created October 24, 2012 06:22
ElephantBlog Config - 2
########## ELEPHANTBLOG CONFIGURATION
def elephantblog_entry_url_app(self):
from feincms.content.application.models import app_reverse
return app_reverse('elephantblog_entry_detail', 'elephantblog.urls', kwargs={
'year': self.published_on.strftime('%Y'),
'month': self.published_on.strftime('%m'),
'day': self.published_on.strftime('%d'),
'slug': self.slug,
})
@pije76
pije76 / multi_contact_form.py
Created October 24, 2012 09:02 — forked from mjtamlyn/multi_contact_form.py
Multi-contact form (FeinCMS content type)
from django.db import models
from django.utils.text import ugettext_lazy as _
from .contact_form_amended import ContactForm, ContactFormContent
class MultiContactFormContent(ContactFormContent):
FORM_CLASSES = {'simple-contact': ContactForm}
FORM_CHOICES = (('simple-contact', _('Simple contact form')),)
@pije76
pije76 / .bashrc
Created October 26, 2012 08:57 — forked from biern/.bashrc
alwaysdata config
export PYTHONPATH=~/modules/
export PATH=~/modules/bin:~/modules/:$PATH
export WORKON_HOME=$HOME/.virtualenvs
source ~/modules/virtualenvwrapper.sh
export PIP_REQUIRE_VIRTUALENV=true
export PIP_RESPECT_VIRTUALENV=true
export PIP_VIRTUALENV_BASE=$WORKON_HOME
# source .bash_profile
@pije76
pije76 / models.py
Created October 28, 2012 00:21
Email/Username Registration
from django.conf import settings
from django.contrib.auth.models import User
class EmailOrUsernameModelBackend(object):
def authenticate(self, username=None, password=None):
if '@' in username:
kwargs = {'email': username}
else:
kwargs = {'username': username}
try:
@pije76
pije76 / models.py
Created October 28, 2012 00:22
Django Login Form
class NextUrlField(forms.CharField):
widget = forms.HiddenInput
def __init__(self, *args, **kwargs):
super(NextUrlField, self).__init__(*args, **kwargs)
self.required = False
def clean(self, value):
if not value:
return getattr(settings, 'LOGIN_REDIRECT_URL', '/')
else:
return value
@pije76
pije76 / admin.py
Created October 29, 2012 05:07 — forked from tomgruner/admin.py
Adding Dojo's rich editor with minimal plugins to Django's Admin that shows the editor on click and hides on blur
# Example how to add rich editor capabilities to your models in admin.
from django.contrib.admin import site, ModelAdmin
import models
# we define our resources to add to admin pages
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',