Skip to content

Instantly share code, notes, and snippets.

💭
workon on https://github.com/omegaml

miraculixx

💭
workon on https://github.com/omegaml
  • Switzerland
Block or report user

Report or block miraculixx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@miraculixx
miraculixx / cors.py
Last active Jan 12, 2019
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.
View cors.py
'''
Add CORS headers for tastypie APIs
Usage:
class MyModelResource(CORSModelResource):
...
class MyResource(CORSResource):
...
@miraculixx
miraculixx / gist:6548200
Created Sep 13, 2013
Provide a generic format method for JavaScript strings. Use see fiddle http://jsfiddle.net/UkxE7/
View gist:6548200
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 Dec 26, 2015
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.
View .af_clients
mysql:
rmanage: ${name} ${username} ${password} ${port}
@miraculixx
miraculixx / print_git_branch
Last active Dec 26, 2015
print the currently active git branch as part of the prompt
View print_git_branch
## (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 Dec 27, 2015
view last created log file
View get_last_log
ls -lart tmp/app-messages/*log | awk ' END { print $9 }' | xargs less
@miraculixx
miraculixx / README.md
Last active Jan 1, 2016
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.
View README.md

#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 Jan 2, 2016
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.
View gist:8349370
"""
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 Jan 4, 2016
Python implementation of the sigmoid to map a point value to a rating (where points are milliseconds and the rating is the resulting score).
View rating.ipynb
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 Feb 4, 2014
Get latest django-south migrations per app
View latest.py
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 Apr 17, 2014
Add a Django-like filter to Backbone Models and Collections
View filters.js
/**
* 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:
You can’t perform that action at this time.