Skip to content

Instantly share code, notes, and snippets.

View dustinfarris's full-sized avatar
💭
🇺🇸

Dustin Farris dustinfarris

💭
🇺🇸
View GitHub Profile
@dustinfarris
dustinfarris / drf_serializer_permissions_example.py
Last active August 29, 2017 05:36
Exposing permission policies using DRF
class UserSerializer(serializers.ModelSerializer):
"""
Exposing permissions as an established policy.
"""
is_team_captain = serializers.SerializerMethodField('get_is_team_captain')
class Meta:
model = User
def get_is_team_captain(self, obj):
App.TeamEditRoute = Ember.Route.extend({
beforeModel: function(transition) {
if (!this.controllerFor('user').get('is_team_captain')) {
this.transitionTo('index');
}
}
});
<ul class="nav">
{{#if is_team_captain}}
<li>{{#link-to 'teams.edit' team}}Edit Team{{/link-to}}</li>
{{/if}}
<li>{{#link-to 'users.edit' this}}Edit Profile{{/link-to}}</li>
</ul>
@dustinfarris
dustinfarris / kivy_logger.py
Last active November 12, 2015 21:38
Logging wrapper for Kivy projects
from kivy.logger import Logger
class KivyLoggerWrapper:
"""
Custom logging wrapper to make use of Kivy's built in logger.
"""
def __init__(self, title):
self.title = title
@dustinfarris
dustinfarris / list.kv
Last active February 20, 2021 17:40
Dynamic lists in Kivy
#:import la kivy.adapters.listadapter
#:import listview kivy.uix.listview
<MyList>:
adapter: la.ListAdapter(
data=[],
args_converter=self.list_item_args_converter,
cls=listview.ListItemButton)
<MyScreen>:
@dustinfarris
dustinfarris / conftest.py
Last active April 28, 2023 13:57
Stubbing out Kivy windows for your unit tests (using py.test)
"""
Unit testing Kivy is easy, but requires a little boiler plate to keep the
window quiet while you test your code. This is one way to set up py.test,
but the same technique can probably be used with other test runners as well.
More information on how these py.test hooks work:
http://pytest.org/latest/plugins.html#generic-runtest-hooks
"""
import mock
@dustinfarris
dustinfarris / main.py
Last active March 30, 2021 11:20
Download a file in a Kivy application then open it in a separate application
#!/usr/bin/env python
import sys
sys.platform = 'linux2'
import os.path
import mimetypes
import urlparse
import requests
@dustinfarris
dustinfarris / circle.yml
Last active February 14, 2017 19:48
CircleCI script for Ember-CLI projects
machine:
node:
version: 0.10.28
dependencies:
pre:
- npm install -g bower
override:
- npm i
- bower i
deployment:
@dustinfarris
dustinfarris / df.sh
Last active August 29, 2015 14:02
A couple handy git shortcuts
#!/bin/sh
MASTER_BRANCH="master"
STAGING_BRANCH="staging"
function new_issue() {
#
# Create a new branch from master using the provided name
#
if [ -z $2 ]; then
@dustinfarris
dustinfarris / safe-string.js
Last active August 29, 2015 14:03
Basic SafeString Handlebars helper
// app/helpers/safe-string.js
import Ember from 'ember';
/**
* Do not escape special characters.
*
* Usage:
*
* ```hbs
* {{safe-string "<span>My raw HTML code</span>"}}