Skip to content

Instantly share code, notes, and snippets.

View sleekslush's full-sized avatar

Craig Slusher sleekslush

  • Philadelphia, PA
View GitHub Profile
@wojteklu
wojteklu / clean_code.md
Last active July 23, 2024 07:47
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

tvheadend dbus-1/ root~# cat /usr/local/etc/dbus-1/system.d/avahi-dbus.conf
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root or user avahi can own the Avahi service -->
<policy user="avahi">
<allow own="org.freedesktop.Avahi"/>
</policy>
@rduplain
rduplain / app.py
Created April 10, 2012 15:58
Flask: serving static file from a separate domain
# http://flask.pocoo.org/mailinglist/archive/2012/4/10/serving-static-file-from-a-separate-domain-in-production/
from flask import Flask, url_for
# Uncomment to set server name.
# SERVER_NAME = 'mianos.com'
app = Flask(__name__, static_folder=None)
app.config.from_object(__name__)
app.add_url_rule('/<path:filename>', endpoint='static',
@ask
ask / gist:1834966
Created February 15, 2012 10:43 — forked from sleekslush/gist:1828464
-When I'm configuring in a Django app, what is the purpose of the djcelery models? Right --now tables get created, but nothing flows into them. Is this the database backend
---- replacement for Redis and RabbitMQ? Or is it something else?
- Several database tables are used:
* Monitoring
When you use the django-admin monitor the cluster state is written
to the TaskState and WorkerState tables.
@sleekslush
sleekslush / formset_updateview_example.py
Created January 6, 2012 06:42
An example of extending UpdateView to use a formset instead of a form
class UserUpdateView(AuthenticatorViewMixin, UpdateView):
model = User
template_name = 'manager/authenticator/user_list.html'
def get_form_class(self):
return modelformset_factory(User, extra=0)
def get_form_kwargs(self):
kwargs = super(UserUpdateView, self).get_form_kwargs()
kwargs['queryset'] = kwargs['instance']
@benjaminws
benjaminws / runin.sh
Created October 6, 2011 21:24
Wrapper to run scripts that need a virtualenv
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: $0 [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(