Skip to content

Instantly share code, notes, and snippets.

View gjbagrowski's full-sized avatar

Grzegorz Bagrowski gjbagrowski

View GitHub Profile
@gjbagrowski
gjbagrowski / knight_rider.ino
Created June 12, 2017 16:00
Knight Rider leds for particle
int leds[] = {D4, D3, D2, D1, D0};
int led_count = 5;
int timer = 15;
void setup() {
for (int i = 0; i < led_count; i++) {
pinMode(leds[i], OUTPUT);
}
}
#include "RCSwitch/RCSwitch.h"
RCSwitch mySwitch = RCSwitch();
int ledPin = D7;
int inputPin = D3;
int outputPin = D2;
int flagsCount = 6;
bool lightFlags[6];
char* onCodes[] = {
@gjbagrowski
gjbagrowski / views.py
Created January 30, 2017 17:56
Mixin and inheritance example
class OrderStatus(object):
NEW = 'new'
PAID = 'paid'
DELIVERED = 'delivered'
CANCELLED = 'cancelled'
COMPLETED_STATES = (
DELIVERED,
CANCELLED,
@gjbagrowski
gjbagrowski / .env-example
Created January 23, 2017 13:09
Django-environ example
# project-repo/app/settings/.env-example
#
# DJANGO
#
SITE_HOST=localhost:8000
USE_SSL=False
ALLOWED_HOSTS=localhost,127.0.0.1
SECRET_KEY=asdasd
DEBUG=true # never on production, will cause settings including api keys to leak
DJANGO_LOG_LEVEL=DEBUG
@gjbagrowski
gjbagrowski / ldap_logging.py
Created July 26, 2016 07:34
django-auth-ldap + ldap.forumsys.com
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
@gjbagrowski
gjbagrowski / Nested settings test
Created August 20, 2015 11:21
SettingsTestCaseMixin
class XMPPSettingsTestCase(SettingsTestCaseMixin, TestCase):
nested_setting = 'XMPP_SETTINGS'
SETTINGS = (
('host', basestring),
('conference_host', basestring),
('endpoint', basestring),
('archive_timezone', (basestring, datetime.tzinfo)),
)
/* Making jquery ajax POST requests work with django builtin csrf protection.
* Taken from:
* https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
*/
jQuery(document).ajaxSend(function(event, xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
from django.test import TestCase, Client
URLS = (
{}
)
class MyTest(TestCase):
def create_test_client(self, urldata):
def is_enumerable(collection):
"""Checks if the variable is not a basestring instance and can be
enumerated.
"""
try:
# strings can be iterated - that's not what we want
if isinstance(collection, basestring):
return False
# avoid opening a generator
if isinstance(collection, types.GeneratorType):
def model_attrs_unicode(instance, attrs=None):
"""Helper for creating simple instance string descriptions.
Accepts a list of string attributes names or functions that can be given by
specifying attrs or defining __UNICODE__ATTRS on the model.
If a get_{fieldname}_display method exists, it will be used instead of
simple getattr.
Attrs can contain function that accept model instance and return
(attrname, val) pairs, both must be unicode strings.