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 / cors.py
Last active January 12, 2019 02:09
To enable CORS support in django-tastypie, use the following code snipet. Then create your tastypie resources as a subclass of BaseCorsResource.Basic code courtesy Daniel Conzalez of http://codeispoetry.me/index.php/make-your-django-tastypie-api-cross-domain/.I added documentation and the post_list method.
'''
Add CORS headers for tastypie APIs
Usage:
class MyModelResource(CORSModelResource):
...
class MyResource(CORSResource):
...
@miraculixx
miraculixx / gist:6548200
Created September 13, 2013 08:46
Provide a generic format method for JavaScript strings. Use see fiddle http://jsfiddle.net/UkxE7/
String.format = function(string) {
args = arguments.length == 2 ? arguments[1] : arguments.slice(1);
return string.replace(/{(\w+)}/g, function(match, idx) {
return typeof args[idx] != "undefined" ? args[idx] : match;
});
};
String.prototype.format = function() {
return String.format(this, arguments);
}
@miraculixx
miraculixx / .af_clients
Last active December 26, 2015 00:19
This is manage.py for an appfog hosted django application. It works by connecting to the specified database instance. Note that all django commands that do not target the database will run locally.
mysql:
rmanage: ${name} ${username} ${password} ${port}
@miraculixx
miraculixx / print_git_branch
Last active December 26, 2015 02:59
print the currently active git branch as part of the prompt
## (c) miraculixx 2013
##
## PROVIDED WITH NO WARRANTY OF ANY KIND. NOT FIT FOR PRODUCTION USE.
##
## add this to your ~/.bashrc
## if there is an active git repository in the current directory
## your prompt will show as (branch)$PS1
## where "branch" is the name of the currently active git branch and $PS1 is your normal print
## branch will be printed in green. Change the 1;32 part of the prompt to show a different color (e.g. 1;31 = red)
@miraculixx
miraculixx / get_last_log
Last active December 27, 2015 06:09
view last created log file
ls -lart tmp/app-messages/*log | awk ' END { print $9 }' | xargs less
@miraculixx
miraculixx / README.md
Last active January 1, 2016 04:59
django-multiconfig. Enable environment specific configurations and configuration mix-ins for your django project. With any Django project your settings.py file quickly grows beyond managability. A modular approach is needed and that's what this Gist does for you.

#Django Multiple Modular Configuration

Enables modular settings.py configurations and configuration mix-ins for your django project. With any Django project your settings.py file quickly grows beyond managability. A modular approach is needed and that's what this Gist does for you.

##Installation

  1. create package config
  2. add this gist's config_base.py
  3. create a global configuration class EnvSettings_GLOBAL(EnvSettingsBase)
  4. from your settings.py cut/paste all global settings into the new class
@miraculixx
miraculixx / gist:8349370
Last active January 2, 2016 19:19
Capture Python's stdout and stderr into a log file. This way you can simply use the print statement without any logger configuration. Great for quick prototyping or maintenance code where you need the log output on a web page instead of in a log file.
"""
Author: patrick dot senti at gmx dot net
Use as follows:
capture = Capture('mylog.log')
print "some log"
log = capture.get_log()
You can also use it as part of a Django View, like so:
@miraculixx
miraculixx / rating.ipynb
Last active January 4, 2016 13:19
Python implementation of the sigmoid to map a point value to a rating (where points are milliseconds and the rating is the resulting score).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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: