This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def partition(thelist, n): | |
try: | |
n = int(n) | |
list(thelist) | |
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):]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# filters.py | |
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | |
@classonlymethod | |
def as_view(cls, **initkwargs): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def partition_horizontal(thelist, n): | |
""" | |
break a list into 'n' pieces horizontally | |
""" | |
try: | |
n = int(n) | |
thelist = list(thelist) |
OlderNewer