Skip to content

Instantly share code, notes, and snippets.

View alukach's full-sized avatar
🍊

Anthony Lukach alukach

🍊
View GitHub Profile
@alukach
alukach / admin.py
Last active August 29, 2015 14:12
Intermediate Admin Action
from django.contrib import admin, messages
from django.shortcuts import render
from my_app.models import MyModel
from my_app import forms
class MyModelAdmin(admin.ModelAdmin):
actions = ['my_action']
@alukach
alukach / CALGIS_CITY_AMENITY.geojson
Last active August 29, 2015 14:14
Names and addresses of city amenities including arenas, arts centres, athletic parks, cemeteries, city parks, EMS stations, fire stations, golf courses, hazardous good drops, indoor pools, landfills, leisure centres, off leash dog areas, outdoor pools, police services, public toilets and recycle depots.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alukach
alukach / dogparks.geojson
Last active August 29, 2015 14:14
Calgary Off-Leash Parks and Natural Areas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alukach
alukach / union1.geojson
Created April 15, 2015 01:13
Union Test Files
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alukach
alukach / serializer_mixins.py
Created April 8, 2016 16:30
A ModelSerializer that allows for optional fields to be added to a serializer. These fields only appear when they are referred to by name with a `include` GET parameter. Additionally, a user can provide a `fields` GET parameter to limit which fields are serialized for output.
from rest_framework import serializers
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that allows for optional fields to be added to a
serializer. These fields only appear when they are referred to by
name with a `include` GET parameter.
Additionally, a user can provide a `fields` GET parameter to limit
@alukach
alukach / twisted_deferreds_callback_example.py
Last active June 1, 2016 23:16
An example of using Twisted to write asynchronous code while using blocking functions.
from twisted.internet import inotify, reactor, threads
from twisted.python import filepath
# Resources:
# Introduction to Deferreds:
# http://twisted.readthedocs.io/en/twisted-16.1.1/core/howto/defer-intro.html
# Returning Deferreds from synchronous functions:
# https://twistedmatrix.com/documents/current/core/howto/gendefer.html#returning-deferreds-from-synchronous-functions
# addCallbacks Docs:
# https://twistedmatrix.com/documents/16.1.1/api/twisted.internet.defer.Deferred.html#addCallbacks
@alukach
alukach / test.py
Created June 9, 2016 15:28
A test script to demonstrate that Twisted was locking up after 30k file deletions
import sys
from twisted.internet import inotify, reactor, threads
from twisted.python import filepath
# Resources:
# Introduction to Deferreds:
# http://twisted.readthedocs.io/en/twisted-16.1.1/core/howto/defer-intro.html
# Returning Deferreds from synchronous functions:
# https://twistedmatrix.com/documents/current/core/howto/gendefer.html#returning-deferreds-from-synchronous-functions
@alukach
alukach / drf-custom-token-auth.py
Last active April 6, 2017 02:42
A custom token authentication system for DRF.
#
# Token Manager
# https://docs.djangoproject.com/en/1.10/topics/signing/
#
from django.core import signing
from django.contrib.auth import get_user_model
class TemporaryApiToken():
"""
@alukach
alukach / threading.py
Created May 11, 2017 20:52
Threading Context Manager
from multiprocessing import cpu_count
import threading
import queue
import logging
logger = logging.getLogger(__name__)
class ThreadQueue(object):