Skip to content

Instantly share code, notes, and snippets.

View kenbolton's full-sized avatar

Ken Bolton kenbolton

  • BScientific
  • Beacon, NY
View GitHub Profile
@kenbolton
kenbolton / gist:1436612
Created December 6, 2011 03:42 — forked from alokmishra/gist:835276
deploy with gunicorn django fabric git
"""
This fabric file makes setting up and deploying a django application much
easier, but it does make a few assumptions. Namely that you're using Git,
Apache and mod_wsgi and your using Debian or Ubuntu. Also you should have
Django installed on your local machine and SSH installed on both the local
machine and any servers you want to deploy to.
_note that I've used the name project_name throughout this example. Replace
this with whatever your project is called._
@kenbolton
kenbolton / gist:3438455
Created August 23, 2012 16:37
Taxability Information Code
EXTRA_MODEL_FIELDS = (
(
"cartridge.shop.models.Product.tic",
"CharField",
("Taxability Information Code",),
{"max_length":"5", "blank": True, "default":"00000", },
),
)
@kenbolton
kenbolton / gist:3953717
Created October 25, 2012 16:10 — forked from joshcartme/gist:3943826
cartridge order setup which adds in tax total
from decimal import Decimal
from cartridge.shop.models import Order, SelectedProduct
def setup(self, request):
"""
Set order fields that are stored in the session, item_total, tax_total,
and total based on the given cart, and copy the cart items to the order.
Called in the final step of the checkout process prior to the payment
@kenbolton
kenbolton / gist:4226648
Created December 6, 2012 18:09
checkbox toggle
$(function() {
// Create filter actions.
var checkbox = $('input[name=joins-leaves]')
$('label[for=joins-leaves]').toggle( function () {
$('.joins, .leaves').css({'display': 'none'});
checkbox.prop('checked', true);
}, function () {
$(".joins, .leaves").css({'display': 'table-row'});
checkbox.prop('checked', false);
});
@kenbolton
kenbolton / Vagrantfile
Created January 14, 2013 23:36
This is the base Vagrantfile for my Django work. I don't know how I came to this, but it works. I first run `vagrant box add precise64 http://files.vagrantup.com/precise64.box` and `vagrant init precise64`, drop in this Vagrantfile, then `vagrant up`. Read the current Vagrant documentation, as the values in this gist may no longer be valid!
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.network :hostonly, "192.168.124.10"
end
@kenbolton
kenbolton / fabfile.py
Last active December 12, 2015 01:08
Some tentative Mezzanine fabfile.py additions.
@task
@log_call
def download_media():
media = 'media.tar.gz'
run("tar -czvf %s/%s -C %s/static/media/" % (env.proj_path, media,
env.proj_path))
get('%s/%s' % (env.proj_path, media), media)
@task
@log_call
@kenbolton
kenbolton / profiles.models.py
Created February 13, 2013 18:34
Django-Social-Auth and Mezzanine/Cartridge integration from spring 2012. It looks like `mezzanine.accounts`, but the integration with that app is likely incomplete.
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from mezzanine.core.fields import RichTextField
from cartridge.shop.models import Product
from social_auth.signals import pre_update
from social_auth.backends.google import GoogleOAuth2Backend
@kenbolton
kenbolton / kv_bencher.py
Last active December 14, 2015 17:29 — forked from mikeyk/gist:1329319
Python script to test Redis set/get, hashed sets, memcached, and PostgreSQL hstore for memory consumption.
#! /usr/bin/env python
import redis
import random
import pylibmc
import psycopg2
import sys
from time import clock
r = redis.Redis(host='localhost', port=6379)
def main():
list_of_primes = [2]
while len(list_of_primes) < 1000:
if list_of_primes[-1] % 2 == 0:
value = list_of_primes[-1] + 1
else:
value += 2
is_prime = True
for i in list_of_primes:
if i > value * 0.5:
@kenbolton
kenbolton / admin.py
Last active December 19, 2015 02:48
Remove 'in_menus' from Mezzanine's `Page` instance admin. Insert '_order' at the beginning of the list of fields.
from copy import deepcopy
from django.contrib import admin
from mezzanine.pages.admin import PageAdmin
from mezzanine.pages.models import Page
fieldsets = deepcopy(PageAdmin.fieldsets)
fieldsets[0][1]["fields"].remove('in_menus')
fieldsets[0][1]["fields"].insert(0, '_order')