Skip to content

Instantly share code, notes, and snippets.

View miraculixx's full-sized avatar
💭
working on https://github.com/omegaml

miraculixx

💭
working on https://github.com/omegaml
  • Switzerland
View GitHub Profile
@miraculixx
miraculixx / latest.py
Created February 4, 2014 08:43
Get latest django-south migrations per app
def get_latest_migrations():
"""
using South' MigrationHistory, get the latest migration id per app
using this, we can apply a --fake later on to get back the previous
state
"""
from south.models import MigrationHistory
from django.db.models.aggregates import Max
latest = MigrationHistory.objects.values('app_name').annotate(latest=Max('applied'))
migrations = {}
@miraculixx
miraculixx / filters.js
Created April 17, 2014 13:39
Add a Django-like filter to Backbone Models and Collections
/**
* Backbone filter. This adds a filtering mechanism
* similar to Django ORM filters:
*
* var MyModel = Backbone.Model.extend(...);
* var model = new MyModel(...);
* model.filter("somekey", "somevalue");
* model.filter("anotherkey", "anothervalue");
* Doing so will result in the query() method to
* return a query string of all filters:
@miraculixx
miraculixx / README
Created April 23, 2014 16:59
shrink size of git repository
Source: http://stevelorek.com/how-to-shrink-a-git-repository.html
I adopted Steve's script so that you can now do:
# list top 10
./gitsize.sh
# delete for sure
./gitsize.sh --delete file ...
@miraculixx
miraculixx / cleanzipextract
Last active August 29, 2015 14:04
remove files extracted from a zip file
#!/usr/bin
# Purpose:
#
# you have unzipped a zip file and realise the files are in the wrong place?
# simply remove the files again using this command
#
# Usage: cleanzipextract <zipfile>
#
# WARNING: this will list all files and then unconditionally remove all files it finds
# USE WITH CAUTION
@miraculixx
miraculixx / export.py
Last active August 29, 2015 14:05
Django Queryset CSV Exporter
class CSVExport(object):
"""
A generic CSV exporter for any queryset. Use with a
file object or the default storage class.
Use with a file object:
queryset = SomeModel.objects.all()
exporter = CSVExport(queryset)
export.export(file)
@miraculixx
miraculixx / git-graph
Created October 6, 2014 08:38
git branch history in extended or dense format using git log, similar to git-cola's branch visualizatoin
#!/bin/bash
# print a pretty branch graph
# (c) miraculixx 2014
#
# Installation:
# 1. Put this file in /usr/local/bin
# 2. chmod +x /usr/local/bin/git-graph
#
# Usage:
# $ git graph -h
[{"pk": 1, "model": "shrcoach.operatoraddress", "fields": {"city": 1, "display_name": "Z\u00fcrich, Schweiz, Suisse, Svizzera, Svizra", "country": 1, "street": null, "normalized": "Zurich, Schweiz, Suisse, Svizzera, Svizra", "position": "47.3719943,8.5415277"}}, {"pk": 2, "model": "shrcoach.operatoraddress", "fields": {"city": 2, "display_name": "Z\u00fcrich, Schweiz, Suisse, Svizzera, Svizra", "country": 1, "street": null, "normalized": "Zurich, Schweiz, Suisse, Svizzera, Svizra", "position": "47.3719943,8.5415277"}}, {"pk": 1, "model": "shrcoach.itenaryaddress", "fields": {"itenary_code": "ZUR", "city": 4, "display_name": "Z\u00fcrich, Schweiz, Suisse, Svizzera, Svizra", "country": 1, "street": null, "normalized": "Zurich, Schweiz, Suisse, Svizzera, Svizra", "position": "47.3719943,8.5415277"}}, {"pk": 2, "model": "shrcoach.itenaryaddress", "fields": {"itenary_code": "HAM", "city": 5, "display_name": "Hamburg, Deutschland", "country": 2, "street": null, "normalized": "Hamburg, Deutschland", "position": "53.
"""
This is a temporary fix for django-cms 3.0 failing to logout
a user correctly (I don't currently have the time to setup a
PR). The fix goes into cms.middleware.user
The problem is manifest in unit tests where there are multiple
tests that repeatedly login/logout using Django's test Client()
and which use fixtures referencing auth_user.
The first test that runs will install the fixtures fine. Any
@miraculixx
miraculixx / alphabet.js
Created October 28, 2014 09:36
transform a list of names into an alphabet-keyed dictionary.
// transform a list of names into an alphabet-keyed dictionary.
// e.g. input is
//
// var list = ["Elsie Chambers", "Gene Keller", "Glen Hall", "Lawrence Burke", "Lenora Robbins", "Lillian Stone", "Lucy Roberson", "Mario Curry",
// "Shawn Matthews", "Terry Joseph"]
//
// asAlphabetDictionary(list) =>
// {"A":["Adrian Stanley"],"F":["Fred Houston"],"H":["Hilda Hart"],
// "I":["Irene Coleman"],"J":["Jeffery Castillo","Jon Floyd","Jonathan
// Conner"],"L":["Leon Higgins"],"N":["Nettie Jensen"],"S":["Sally
@miraculixx
miraculixx / moneyfield.py
Last active August 29, 2015 14:10
MoneyField for tastypie
from decimal import Decimal
from moneyed.classes import Money
from tastypie.fields import CharField, DecimalField
from tastypie.resources import ModelResource
from djmoney.models.fields import MoneyField as ModelMoneyField
class MoneyFieldMixin(object):
"""