Skip to content

Instantly share code, notes, and snippets.

Casey Kinsey ckinsey

Block or report user

Report or block ckinsey

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
@ckinsey
ckinsey / bot.py
Last active Sep 6, 2016
Bot.py, Final
View bot.py
import json
import markovify
import re
import time
from slackclient import SlackClient
BOT_TOKEN = "bot user API token"
GROUP_TOKEN = "slack user API token"
@ckinsey
ckinsey / chain.py
Last active Aug 19, 2018
Chain.py Builds the Markov Models from Slack
View chain.py
import json
import markovify
import re
import time
from slackclient import SlackClient
BOT_TOKEN = "insert bot token here"
@ckinsey
ckinsey / bot.py
Created Sep 6, 2016
Bot.py Basic
View bot.py
import markovify
import time
from slackclient import SlackClient
BOT_TOKEN = "insert bot token here"
GROUP_TOKEN = "insert slack group token here"
@ckinsey
ckinsey / etl_regstry.py
Created Oct 13, 2015
An example implementation of an ETL registry
View etl_regstry.py
class ETLRegistry(object):
"""
The ETL registry stores the relationships between Extract, Transform
and Load classes.
An entry tracks both a string representation (for passing through message queue) and
a reference for the class (for invocation inside the task)
"""
_regsitry = []
@ckinsey
ckinsey / decorators.py
Created Mar 22, 2014
Require SSL for Django views via a decorator. You'll need some setup in your web server to support the request.is_secure() method--see the Django docs.
View decorators.py
from functools import wraps
from django.conf import settings
from django.http import HttpResponseRedirect
def require_ssl(view):
"""
Decorator that requires an SSL connection. If the current connection is not SSL, we redirect to the SSL version of
the page.
View state_machine.py
STATUS_CANCELLED = 'cancelled'
STATUS_NEW = 'new'
STATUS_PENDING = 'pending'
STATUS_PAYMENT_DUE = 'payment-due'
STATUS_PAYMENT_PENDING = 'payment-pending'
STATUS_PAID = 'paid'
NEGOTIABLE_STATUS_CHOICES = (
(STATUS_CANCELLED, 'Cancelled'), # Cancelled, duh
(STATUS_NEW, 'New'), # Default state of request
@ckinsey
ckinsey / gist:7250117
Created Oct 31, 2013
Python flow control as determined by the text of a button set via JavaScript.
View gist:7250117
if self.request.POST.get('action').lower().find('book') > -1:
# if everything on the other side was all set to go and the user making changes,
# the button they are pushing contains "book" on it and we can redirect to booking this session.
return HttpResponseRedirect(reverse('setup_payment_for_session', kwargs={'pk': obj.pk}))
View gist:7204648
@property
def request(self):
"""
just for convenience
"""
return self
View gist:4136999
class DashboardManageUsersFormset(BaseFormSet):
def __init__(self, *args, **kwargs):
self.assignment_perms = kwargs.pop('assignment_perms', None)
super(DashboardManageUsersFormset, self).__init__(*args, **kwargs)
def _construct_forms(self):
self.forms = []
for i in xrange(self.total_form_count()):
self.forms.append(self._construct_form(i, assignment_perms=self.assignment_perms))
@ckinsey
ckinsey / middleware.py
Created Sep 21, 2012
Mobile middleware success!
View middleware.py
from django.conf import settings
class MobileTemplateMiddleware:
def process_request(self, request):
host = request.META.get('HTTP_HOST', '')
host_s = host.split('.')
if len(host_s) > 1:
subdomain = host_s[0]
You can’t perform that action at this time.