Skip to content

Instantly share code, notes, and snippets.

View Nagyman's full-sized avatar

Craig Nagy Nagyman

View GitHub Profile
jQuery.facebox([
"<h1>Waitlist Availability Only</h1>",
"<p>If you continue this booking, the booking will be placed on a waitlist until",
" there is room for all passengers.",
"</p>"
].join(''));
@Nagyman
Nagyman / fabfile.py
Created February 15, 2012 19:55
Skeleton for point-release from git
def deploy():
env.release = time.strftime('%Y%m%d%H%M%S')
upload_tar_from_git()
symlink_current_release()
restart_webserver()
def deploy_version(version):
"Specify a specific version to be made live"
require('hosts', provided_by=[localhost,webserver])
require('releases')
@Nagyman
Nagyman / git-big.py
Created April 23, 2012 17:50
Python Script to Identify Git Commits with Files Over a Specific Size
#!/usr/bin/env python
'''
Modified version from:
http://stackoverflow.com/questions/298314/find-files-in-git-repo-over-x-megabytes-that-dont-exist-in-head
Examples:
# Commits bigger than 1MB
python git-big.py 1048576
@Nagyman
Nagyman / strict_roles.py
Created June 22, 2012 18:08
Decorator to strictly enforce the roles defined for a fabric task
from fabric.api import env
from fabric import tasks
from functools import wraps
def _wrap_as_new(original, new):
if isinstance(original, tasks.Task):
return tasks.WrappedCallableTask(new)
return new
def strict_roles(*role_list):
@Nagyman
Nagyman / createinitialrevisions.diff
Created July 18, 2012 18:58
django-reversion createinitialrevisions performance improvement
from optparse import make_option
+from django.db import reset_queries
from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
@@ -93,17 +94,28 @@ class Command(BaseCommand):
live_objs = live_objs.exclude(
pk__in = list(versioned_pk_queryset.values_list("object_id", flat=True).iterator())
)
@Nagyman
Nagyman / gist:5452466
Created April 24, 2013 14:19
Errors deploying gapi-web to staging
[devgapi01.gadventures.internal] out: Traceback (most recent call last):
[devgapi01.gadventures.internal] out: File "/var/www/gapi-web/gapi_docs/gext/pouch.py", line 251, in make_rst
[devgapi01.gadventures.internal] out: response = self.make_request(uri, method.lower(), accept=accept)
[devgapi01.gadventures.internal] out: File "/var/www/gapi-web/gapi_docs/gext/pouch.py", line 134, in make_request
[devgapi01.gadventures.internal] out: auth_key = self.gapi_config.PASSTHROUGH_AUTHENTICATION_KEYS[0]
[devgapi01.gadventures.internal] out: AttributeError: 'DefaultConfig' object has no attribute 'PASSTHROUGH_AUTHENTICATION_KEYS'
from trips.models import *
import matplotlib.pyplot as plt
counts = []
for t in Trip.objects.published():
counts.append(len(t.visited_countries.all()))
plt.hist(counts)
plt.title("Visited Countries")
plt.xlabel("Number of Countries")
plt.ylabel("Frequency")
@Nagyman
Nagyman / sass.py
Created September 12, 2013 19:36
import os
import logging
from compressor.filters import CompilerFilter
from django.conf import settings
logger = logging.getLogger(__name__)
class SassMapFilter(CompilerFilter):
'''
@Nagyman
Nagyman / jActivityTracker.js
Created October 4, 2013 19:01
jquery activity tracking plugin for google analytics events
/**
* DESCRIPTION:
* Searches for elements with an 'activity' attribute and pushes the activity
* to the Google Tag Manager (GTM) dataLayer. GTM must be configured to capture
* the event data, which is structured as follows:
* {
* 'event': 'eventCategory', // The primary divisions of the types of Events you have on your site.
* 'eventAction': 'action', // For example, you could define Play or Pause as Actions for a Video
* 'eventLabel': 'label', // An optional descriptor that you can use to provide further granularity. You can specify any string for a label.
* 'eventValue': 10 // An optional numerical variable.
@Nagyman
Nagyman / workflows-in-django.md
Last active January 27, 2024 08:29
Workflows in Django

Workflows (States) in Django

I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)