Skip to content

Instantly share code, notes, and snippets.

@magopian
magopian / Makefile
Created November 15, 2012 11:02
Sample Makefile for Django (use with project templates)
.PHONY: all help translate test clean update compass collect rebuild
SETTINGS={{ project_name }}.settings
TEST_SETTINGS={{ project_name }}.test_settings
# target: all - Default target. Does nothing.
all:
@echo "Hello $(LOGNAME), nothing to do by default"
@echo "Try 'make help'"
@magopian
magopian / gist:4078269
Created November 15, 2012 11:53
Reuse the Django admin's javascript (example with prepopulated_fields.js)
<script src="{% static "admin/js/jquery.js" %}"></script>
<script src="{% static "admin/js/jquery.init.js" %}"></script>
<script src="{% static "admin/js/urlify.js" %}"></script>
<script src="{% static "admin/js/prepopulate.js" %}"></script>
<script>
// adaptation from django/contrib/admin/templates/admin/prepopulated_fields_js.html
(function($) {
var field = {
id: '#{{ form.###DESTINATION FIELD NAME###.auto_id }}',
dependency_ids: ['#{{ form.###SOURCE FIELD NAME###.auto_id }}'],
@magopian
magopian / pre-commit
Created November 16, 2012 10:40
git pre-commit hook for sphinx documentation
#!/bin/sh
#
# This pre-commit hook tests that the documentation builds correctly.
# It can be disabled by using the "-n" option with "git commit".
#
# See http://git-scm.com/book/en/Customizing-Git-Git-Hooks for details.
#
# This pre-commit hook requires that you have the "###PROJECT###" project on your python
# path, in order for the DJANGO_SETTINGS_MODULE=###PROJECT###.settings to work.
# This is needed to build the apidoc.
@magopian
magopian / tests.py
Created November 16, 2012 10:55
Unit test to validate django templates
class TemplatesTest(TestCase):
def test_templates(self):
"""Templates can compile properly and there's no mismatched tags"""
# get app template dirs
template_dirs = []
apps = [app for app in settings.INSTALLED_APPS
if app.startswith('rh2')]
for app in apps:
mod = import_module(app)
@magopian
magopian / tests.py
Created November 16, 2012 11:05
Unit test to validate fixtures
class FixturesTest(TestCase):
def test_num_fixtures(self):
"""All fixtures on the project are tested"""
apps = [app.replace('.', '/')
for app in settings.INSTALLED_APPS if app.startswith('rh2')]
fixtures = []
for app in apps:
fixture_dir = path.join(path.dirname(settings.PROJECT_ROOT),
app,
@magopian
magopian / robot.js
Created December 3, 2012 16:31
W00t #1 YEAH!!!! (Zolmesiter)
var Robot = function(robot){
robot.turnLeft(robot.angle % 90);
//robot.turnGunRight(90);
robot.clone();
this.direction = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(1);
if (robot.parentId) {
@magopian
magopian / robot.js
Created December 3, 2012 21:34
L. Ethal
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@magopian
magopian / pre-commit
Created March 8, 2013 10:11
git pre-commit hook
#!/bin/sh
#
# This pre-commit hook tests various conditions to allow the commit.
# It can be disabled by using the "-n" option with "git commit".
#
# To use it, link it to .git/hooks/pre-commit:
#
# ln -s `pwd`/pre-commit .git/hooks/
if git rev-parse --verify HEAD >/dev/null 2>&1
@magopian
magopian / rfpy3.py
Last active April 26, 2018 22:20
rfpy3.py : Ready For Python3? Simple script to be executed locally (in a virtualenv?) to check which of the local packages have the Py3 trove classifier, if they don't, if the newest version on PyPI has.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Ready For Python3?
Checks the locally installed distribution for the py3 trove classifier, and if
it's not found, check on PyPI if there's a newer version of this distribution.
This was done with some help from Matrixise.
@magopian
magopian / conftest.py
Last active December 20, 2015 03:09
fixtures for pytest, using monkeypatch, and providing stub facilities, also allowing to check the calls of the stubbed methods. For a fixture that makes use of the mock library, check pelme's https://gist.github.com/pelme/59a1dee00b5f8afc278e (example usage: https://gist.github.com/pelme/08571132a677485c7e23)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division
import pytest
class Stub(object):
"""Stub methods, keep track of calls."""