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 / 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 / .bashrc
Created July 12, 2014 21:31
add and remove pip install/uninstall from requirements.txt automatically
# add pip install/uninstall to requirements.txt automatically
pipr() {
if [ "$1" == "install" ]; then
pip $1 $2
pip freeze | grep -i $2 >> requirements.txt
echo ok, added $2 as:
tail -n1 requirements.txt
fi
if [ "$1" == "uninstall" ]; then
echo y | pip $1 $2 >> .pipremoved
@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-keep
Created October 4, 2014 03:44
create .keep files for empty directories currently ignored by git
#!/bin/bash
# create .keep files for empty directories currently ignored by git
# run git clean -nd to see which directories are empty and therefore ignored by git currently
# run git keep to add these directories by adding a .keep file
# see this discussion http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository/21422128#21422128
git clean -nd | awk '{ print $3 }' | xargs -L1 -I{} touch {}.keep
@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
@miraculixx
miraculixx / rules.py
Last active July 25, 2021 07:18
a simple python based rule engine
"""
(c) 2014 miraculixx at gmx.ch
"""
from shrutil.dictobj import DictObject
class RuleContext(DictObject):
"""
rule context to store values and attributes (or any object)
"""
def __init__(self):
[{"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.
@miraculixx
miraculixx / fieldselect.py
Last active June 7, 2017 15:36
select tastypie fields returned by the api
class FieldSelectionMixin(object):
"""
add ability to Resource to query specific fields. This works by
removing any fields not in the fields list provided by the fields
query parameter.
Programming Use:
class MyResource(FieldSelectionMixin, ModelResource):
...
(as with any normal resource)
"""
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