Skip to content

Instantly share code, notes, and snippets.

@magopian
magopian / gist:8915831
Created February 10, 2014 13:22
update from Django 1.4 to 1.5, various notes (not complete)
Not yet! But here are some notes (taken from the release notes):
## New
* use PBKDF2 for passwords
* new URL tags : remove all ```{% load url from future %}``` (and make sure there's no old style ```{% url %}``` tags lurking around)
* **INFO**: [update_fields](https://docs.djangoproject.com/en/dev/ref/models/instances/#specifying-which-fields-to-save) added to save only needed fields on a model
* **INFO**: calls to [call_command](https://docs.djangoproject.com/en/dev/ref/django-admin/#call-command) now propagates exceptions
* **INFO**: [LOGIN_URL](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_URL) and [LOGIN_REDIRECT_URL](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-LOGIN_REDIRECT_URL) settings now also allows view function names and named url patterns
* **INFO**: when using RequestContext, there's now a [perms](https://docs.djangoproject.com/en/dev/ref/templates/api/#django-contrib-auth-context-processors-auth) in the context that allows to do ```{% if 'someapp.so
@magopian
magopian / watch_turtle.py
Last active August 29, 2015 14:25
Auto-reload turtle code on file save (https://docs.python.org/3/library/turtle.html)
"""Reloads the `my_turtle.py` code on save.
Put simple turtle instructions in the `my_turtle.py` file,
and they'll be re-run (on a clean window) on each file save.
Usage:
1/ put some turtle instructions in a `my_turtle.py` file
(eg `turtle.forward(100)`)
2/ run `python watch_turtle.py` on a commandline
(no dependencies needed)
@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 / 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."""
@magopian
magopian / README.rst
Last active December 30, 2015 16:29
A few notes on how to deal with a Raspberry-pi

Raspberry-Pi tips and tricks

Backup SDCard to computer

Check the output of the lsblk command to find the correct device (eg: /dev/mmcblk0):

@magopian
magopian / index.js
Created March 11, 2016 08:54
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var Validator = require('jsonschema').Validator;
var v = new Validator();
var schema = { "allOf" : [
{"type": "boolean"},
{"type": "string"}
]}
console.log(v.validate("foobar", schema));
@magopian
magopian / conftest.py
Created November 27, 2013 10:46
Little hack for pytest_django: load data in your test database before the tests are run, only if the database is being created and not reused.
import pytest
@pytest.fixture(scope='session')
def _django_db_setup(request, _django_db_setup, _django_cursor_wrapper):
"""Load any data needed for the tests after the database is created.
This "overwrites" pytest_django's own _django_db_setup.
"""