Skip to content

Instantly share code, notes, and snippets.

View specialunderwear's full-sized avatar

Voxin Muyli specialunderwear

View GitHub Profile
@specialunderwear
specialunderwear / ▼spyne■delegate.py
Last active December 2, 2016 13:27
Spyne services with inheritance.
import inspect
from functools import partial, update_wrapper
from spyne.decorator import rpc as original_rpc
from spyne.service import ServiceBase, ServiceBaseMeta
__all__ = ('rpc', 'DelegateBase', 'ExtensibleServiceBase')
class SpyneMethodWrapper(object):
"""
[uwsgi]
master = true
workers = 1
reload-mercy = 30
vacuum = 1
socket = my.sock
auto-procname = true
enable-threads = true
lazy = 0
plugin = python
[uwsgi]
master = true
chmod-socket = 660
workers = 1
reload-mercy = 30
vacuum = 1
auto-procname = true
enable-threads = false
lazy = 0
no-orphans = true
>>> import contextlib
>>> from django.db import models
>>>
>>> class Sequence(models.Model):
... pass
>>>
>>> @contextlib.contextmanager
>>> def unique_threadsafe_id():
... try:
... a, created = Sequence.objects.create()
@specialunderwear
specialunderwear / polymorphicserializer.py
Created July 29, 2015 08:37
Polymorphic serializer
from rest_framework import serializers
from rest_framework.utils.serializer_helpers import BindingDict
class PolymorphicModelSerializer(serializers.ModelSerializer):
"""
Serializer that serializes a polymorphic model
Since the whole point of polymorphism is to have models
with different properties in the same queryset, the ``fields`` meta
specification in rest_framework becomes rather useless. That is
@specialunderwear
specialunderwear / exclusive.py
Created May 29, 2015 17:08
Enforce exclusive running of uwsgi cron jobs on aws - where uwsgi legion does not work - using a database lock
"""
Ensure that only 1 process can be running a managment command at the same
time, even across multiple application servers.
Uses a database lock on a table row, in a separate database connection.
"""
import logging
from django.conf import settings
from django.db import models
@specialunderwear
specialunderwear / meta.py
Last active July 22, 2019 12:12
Override model fields of an abstract model baseclass in django, by removing them from the abstract model.
def AbstractClassWithoutFieldsNamed(cls, *excl):
"""
Removes unwanted fields from abstract base classes.
Usage::
>>> from oscar.apps.address.abstract_models import AbstractBillingAddress
>>> from koe.meta import AbstractClassWithoutFieldsNamed as without
>>> class BillingAddress(without(AbstractBillingAddress, 'phone_number')):
... pass
@specialunderwear
specialunderwear / exceptionhandler.py
Created April 2, 2015 09:58
Django rest api exception handler, returns exceptions as json and logs exception.
import json
import logging
import traceback
from django.http import HttpResponseServerError
from oscarapi.middleware import IsApiRequest
logger = logging.getLogger(__name__)
Pod::Spec.new do |s|
s.name = 'GoogleTagManager'
s.version = '3.0b1'
s.summary = 'Google Tag Manager SDK.'
s.description = 'Google Tag Manager enables developers to change configuration values in their mobile applications using the Google Tag Manager interface without having to rebuild and resubmit application binaries to app marketplaces.'
s.homepage = 'http://developers.google.com/tag-manager/ios'
s.license = {
:type => 'Copyright',
:text => <<-LICENSE
Copyright 2013 Google, Inc. All rights reserved.
@specialunderwear
specialunderwear / deploy-devenv.sh
Created March 27, 2013 10:08
install deploy tool development environment
apt-get install git
apt-get install debianize
git clone git@github.com:devopsconsulting/vdt.deploy.git
git clone git@github.com:devopsconsulting/vdt.deployplugin.cloudstack.git
git clone git@github.com:devopsconsulting/vdt.deployplugin.xen.git
git clone git@github.com:devopsconsulting/python-mutexlock.git
git clone git@github.com:devopsconsulting/python-cloudstack.git
apt-get install virtualenv pip
apt-get install python-virtualenv python-pip
pip install virtualenvwrapper