Skip to content

Instantly share code, notes, and snippets.

Liftoff #fpvracing

Craig Derington craigderington

Liftoff #fpvracing
  • Craig Derington
Block or report user

Report or block craigderington

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
craigderington /
Last active Mar 27, 2016
Break a list into 'n' pieces. The last list may be larger than the rest if the list doesn't break cleanly.
def partition(thelist, n):
n = int(n)
except (ValueError, TypeError):
return [thelist]
p = len(thelist) / n
return [thelist[p*i:p*(i+1)] for i in range(n - 1)] + [thelist[p*(i+1):]]
craigderington /
Last active Mar 29, 2016
Django Tables2 - Create Customer Data Table
import django_tables2 as tables
from django_tables2.utils import A
from .models import Customer
class CustomerTable(tables.Table):
account_number = tables.LinkColumn('customer-detail', args=[A('pk')])
customer_first_name = tables.LinkColumn('customer-detail', args=[A('pk')])
customer_last_name = tables.LinkColumn('customer-detail', args=[A('pk')])
customer_email = tables.LinkColumn('customer-detail', args=[A('pk')])
craigderington /
Last active Apr 1, 2016
Generic Customer List View - Search & Filter QuerySet
from django.views.generic import ListView
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.query_utils import Q
from django_tables2 import RequestConfig
from braces.views import LoginRequiredMixin, GroupRequiredMixin
from .tables import CustomerTable
from .filters import CustomerListFilter
from .utils import PagedFilteredTableView
from .models import Customer
from .forms import CustomerListFormHelper
craigderington /
Last active Apr 1, 2016
Django Filters - PagedFilteredTableView
from django_tables2 import SingleTableView
from django_tables2.config import RequestConfig
class PagedFilteredTableView(SingleTableView):
filter_class = None
formhelper_class = None
context_filter_name = 'filter'
def get_queryset(self, **kwargs):
craigderington /
Last active Apr 1, 2016
Django Filters - FilterSet
import django_filters
from .models import Customer
class CustomerListFilter(django_filters.FilterSet):
class Meta:
model = Customer
fields = ['account_number', 'customer_first_name', 'customer_last_name',
craigderington /
Created Apr 4, 2016
Django Generic Detail View
from django.views.generic import DetailView
from .models import Customer
class CustomerDetailView(LoginRequiredMixin, DetailView):
def _allowed_methods(self):
return [m.upper() for m in self.http_method_names if hasattr(self, m)]
def as_view(cls, **initkwargs):
craigderington / json_api_server.js
Created Jun 29, 2016
JSON API Server for NodeJS
View json_api_server.js
var http = require('http');
var url = require('url');
var portNumber = Number(process.argv[2]);
function parseTime(time) {
return {
hour: time.getHours(),
minute: time.getMinutes(),
second: time.getSeconds()
craigderington /
Created Jul 14, 2016
Customer List Filtered Table View Form Helper
class CustomerListFormHelper(FormHelper):
form_id = 'customer-search-form'
form_class = 'form-inline'
field_template = 'bootstrap3/layout/inline_field.html'
field_class = 'col-xs-3'
label_class = 'col-xs-3'
form_show_errors = True
help_text_inline = False
html5_required = True
layout = Layout(
from flask import Flask
from flask import render_template, redirect, url_for, request, flash
from flask_pymongo import PyMongo
from bson.objectid import ObjectId
import os
import requests
import json
import datetime
app = Flask(__name__)
View index.html
{% extends "layout.html" %}
{% block title %}
Reddit Reader | Public Timeline
{% endblock %}
{% block body %}
<h2><i class="fa fa-reddit-square"></i> Recent Reddits
<a style="margin-left:5px;" href="#menu-toggle" class="btn btn-default" id="menu-toggle"><i class="fa fa-toggle-left"></i> Toggle Menu</a>
You can’t perform that action at this time.