Skip to content

Instantly share code, notes, and snippets.

View alukach's full-sized avatar
🍊

Anthony Lukach alukach

🍊
View GitHub Profile
@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 / 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 / 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
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / admin.py
Created January 5, 2015 04:47
Custom Django Admin Form via Fake Model
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.shortcuts import render
from my_app.forms import CustomForm
class FakeModel(object):
class _meta:
app_label = 'my_app' # This is the app that the form will exist under
@alukach
alukach / thermometer.py
Last active August 29, 2015 14:12
BeagleBone LCD Thermometer
#!/usr/bin/python
"""
This script assumes that you have a LCD connected to a RaspberryPi or BeagleBone
Black as as described in this tutorial:
https://learn.adafruit.com/character-lcd-with-raspberry-pi-or-beaglebone-black
along with a temperature sensor as described in this tutorial:
https://learn.adafruit.com/measuring-temperature-with-a-beaglebone-black
"""
from collections import deque