Skip to content

Instantly share code, notes, and snippets.

@ckinsey
ckinsey / bathtub.sh
Created May 12, 2020 03:38
bathtub.sh
#!/bin/bash
# friday.hirelofty.com
on="1"
if [ $1 -eq $on ]
then
echo "Removing desktop icons and restarting finder"
defaults write com.apple.finder CreateDesktop false
killall Finder
@ckinsey
ckinsey / bot.py
Last active September 6, 2016 16:44
Bot.py, Final
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 August 19, 2018 04:05
Chain.py Builds the Markov Models from Slack
import json
import markovify
import re
import time
from slackclient import SlackClient
BOT_TOKEN = "insert bot token here"
@ckinsey
ckinsey / bot.py
Created September 6, 2016 14:08
Bot.py Basic
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 October 13, 2015 02:49
An example implementation of an ETL registry
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 March 22, 2014 16:34
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.
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.
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 October 31, 2013 13:51
Python flow control as determined by the text of a button set via JavaScript.
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}))
@property
def request(self):
"""
just for convenience
"""
return self
@ckinsey
ckinsey / gist:4136999
Created November 23, 2012 19:40
Formset magic
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))