Skip to content

Instantly share code, notes, and snippets.

View raiderrobert's full-sized avatar

Robert Roskam raiderrobert

View GitHub Profile
@raiderrobert
raiderrobert / models.py
Last active May 3, 2016 02:50
Convenience Property for Django
from django.db import models
class Artist(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
class Album(models.Model):
name = models.CharField(max_length=150)
release_date = models.DateField()
@raiderrobert
raiderrobert / tests.py
Last active May 12, 2016 02:37
Why hypothesis is awesome
import unittest
class ActiveTests(TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
@raiderrobert
raiderrobert / date_enforcer.js
Created May 18, 2016 18:30
Date enforcer dependent on jquery and moment
var dateEnforcer = function (startDate, endDate) {
$(startDate).on('focus', function () {
this.previousDate = moment(this.value).format('MM-DD-YYYY');
}).change(function(){
var newDate = moment(this.value).format('MM-DD-YYYY');
var endDateMoment = moment($(endDate).val()).format('MM-DD-YYYY');
if (this.previousDate != 'Invalid date'){
@raiderrobert
raiderrobert / tests.py
Created May 31, 2016 18:13
Testing Views in Django With Hypothesis
from django.core.urlresolvers import reverse
from django.test import TestCase, Client
from hypothesis import given, strategies as st
from .models import User
class ViewsTestCase(TestCase):
PUBLIC_URLS = ['login', ]
@raiderrobert
raiderrobert / models.py
Last active June 10, 2016 22:26
Selected Related Example with Querysets
from django.db import models
from localflavor.us.models import USStateField
class State(models.Model):
name = USStateField(unique=True)
incits_code = models.CharField(max_length=250)
class Meta:
ordering = ['name', ]
@raiderrobert
raiderrobert / mah-styles.css
Created November 4, 2016 13:03
Mah Styles
/* Foundation v2.1.4 http://foundation.zurb.com */
/* Artfully masterminded by ZURB */
/* --------------------------------------------------
Table of Contents
-----------------------------------------------------
:: Shared Styles
:: Page Name 1
:: Page Name 2
*/
@raiderrobert
raiderrobert / responsive-table.css
Created November 4, 2016 13:21
Rsponsive Table
@media screen and (max-width: 600px) {
table {
border: 0;
}
table thead {
display: none;
}
@raiderrobert
raiderrobert / version_checker.py
Last active January 10, 2017 01:34
Version checker
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import click
from netmiko import ConnectHandler
def normalize(v):
class OrganizationSerializer(CreatedWithEpochSerializer):
id = serializers.CharField(source='client_generated_id')
address = UsAddressSerializer(required=False)
role = serializers.CharField(read_only=True, source='Membership__role')
class Meta:
model = Organization
fields = ('id', 'role', 'name', 'url', 'archived', 'created', 'address')
def need_approval(self):
queryset = self
queryset = queryset.annotate(
conflict_group=Concat(
'employee_id', Value('|'), 'date_applied',
output_field=models.CharField()
),
paycode_count=Count('codes')
)
conflicts = queryset.values('conflict_group').annotate(