Skip to content

Instantly share code, notes, and snippets.

View bergantine's full-sized avatar

J*Bergantine bergantine

  • London, United Kingdom
View GitHub Profile
@bergantine
bergantine / Filter
Last active October 13, 2015 08:47
#Google #Analytics #Ignore User by User Defined Variable.
Setup a new filter in Google Analytics with the following configuration:
Filter Type: Custom Filter
Filter Field: User Defined
Filter Pattern: no_report
Case sensitive No
@bergantine
bergantine / gist:4128679
Last active July 25, 2020 15:58
Django Template Tag and Filter Test File. #django #djangotemplate
{# asdf #}
{# {{ var }} {% if %} ... {% endif %} #}
{{ asdf }}
<script type="text/javascript">
fruits = new Array('apples', 'oranges', 'bananas');
for (var i=0; i < fruits.length; i++) {
alert(fruits[i]);
@bergantine
bergantine / gist:4035433
Last active October 12, 2015 13:38
Google Analytics Event Tracking. #googleanalytics #javascript
// requires jQuery
// insert after _gaq is declared but before you talk to Google
// track all clicks on links as events
$('a').click(function(e) {
var debug = false; // if set to true will log instead of calling google
if (this.hostname && this.hostname !== location.hostname) {
var eCat = 'External Link';
} else {
@bergantine
bergantine / gist:4035311
Last active June 24, 2022 14:02
Django: Specify Test Database. #django #test #database
# Useful if dev settings are pointed at the production or staging database on a remote host
# In the dev settings, after the `DATABASES` configuration, add a second wrapped in an `if` statement
import sys
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
@bergantine
bergantine / prompt.sh
Created November 7, 2012 20:15 — forked from tobiassjosten/prompt.sh
Bash Prompt with Git. #bash #shell
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
c_user='\[\e[0;32m\]'
c_path='\[\e[1;34m\]'
c_git_clean='\[\e[0;37m\]'
c_git_staged='\[\e[0;32m\]'
c_git_unstaged='\[\e[0;31m\]'
else
c_reset=
@bergantine
bergantine / gist:4033360
Last active October 12, 2015 13:27
Django Template localhost switch. #django #djangotemplate
{% ifequal request.get_host '127.0.0.1:8000' %}
{# Include something only to be executed on "localhost" here. #}
{% else %}
{# Include something only to be executed in production here. #}
{% endifequal %}
@bergantine
bergantine / gist:3900752
Last active October 11, 2015 18:27
Try and catch the button... non minified JS from http://www.romneytaxplan.com/. #demo #javascript
function getDirection(f, b) {
var h = f.width(),
d = f.height(),
a = (b.x - f.offset().left - h / 2) * (h > d ? d / h : 1),
c = (b.y - f.offset().top - d / 2) * (d > h ? h / d : 1),
g = Math.round((Math.atan2(c, a) * (180 / Math.PI) + 180) / 90 + 3) % 4;
switch (g) {
case 0:
return "top";
case 1:
@bergantine
bergantine / Vagrantfile
Last active October 11, 2015 14:57
Vagrantfile for Django-Newproj. #vagrant #vagrantfile #django #python
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
@bergantine
bergantine / gist:3870080
Last active February 18, 2016 12:57
post-merge Git hook to install requirements if changed, compile stylesheets, syncdb, run a south migration on the database, and rebuild the haystack index using the active virtual environment's python installation. #bash #git #hook #django #compass #sass #pip #south #haystack
#!/bin/sh
if [ $(git diff HEAD@{1} HEAD --name-only | grep 'requirements/development.txt' -c) -ne 0 ]
then
sudo $VIRTUAL_ENV/bin/pip install -r /vagrant/myproject/requirements/development.txt
fi
compass compile /vagrant/myproject/myproject/static_media/stylesheets -e production --force
$VIRTUAL_ENV/bin/python /vagrant/myproject/manage.py syncdb
@bergantine
bergantine / gist:3868451
Last active December 16, 2019 19:34
Modernizr 2.6 (Custom Build). #modernizr #javascript
/* Modernizr 2.6.2 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-shiv-cssclasses-load
*/
;window.Modernizr=function(a,b,c){function u(a){j.cssText=a}function v(a,b){return u(prefixes.join(a+";")+(b||""))}function w(a,b){return typeof a===b}function x(a,b){return!!~(""+a).indexOf(b)}function y(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:w(f,"function")?f.bind(d||b):f}return!1}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m={},n={},o={},p=[],q=p.slice,r,s={}.hasOwnProperty,t;!w(s,"undefined")&&!w(s.call,"undefined")?t=function(a,b){return s.call(a,b)}:t=function(a,b){return b in a&&w(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=q.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(q.call(arguments)));return Object(g)