Skip to content

Instantly share code, notes, and snippets.

@fission6
fission6 / clean_old_slack_files.py
Created March 16, 2017 20:45
Clean out old slack files to free up space
import os
import requests
from datetime import datetime, timedelta
# Days aged
DAYS_AGED = 30
# token from https://api.slack.com/web
TOKEN = os.environ.get('SLACK_TOKEN') # set an env variable for slack token
ENDPOINT = 'https://slack.com/api/{}'
def orders_report(request, company):
import cProfile
pr = cProfile.Profile()
pr.enable()
....code to profile
# stop profiling and output to console
@fission6
fission6 / managers.py
Created June 10, 2016 13:37
Django 1.9.6 Case Insensitive Username Logins
from django.db.models.functions import Lower
from django.db.models import CharField
from django.contrib.auth.models import UserManager as DjangoUserManager
CharField.register_lookup(Lower, 'lower')
class UserManager(DjangoUserManager):
"""
Allow case insensitive usernames for authenticating.
@fission6
fission6 / geos.rb
Created November 23, 2013 21:06
If you are using and old version of django (1.4 or lower) but are installing the latest dependancies for GEO DJANGO, specifically GDAL using brew install gdal. The below maybe helpful. This is a brew recipe to install geos on macos that plays well with older django versions and avoids "django.contrib.gis.geos.error.GEOSException: Could not parse…
require 'formula'
class Geos < Formula
homepage 'http://trac.osgeo.org/geos'
url 'http://download.osgeo.org/geos/geos-3.4.2.tar.bz2'
sha1 'b8aceab04dd09f4113864f2d12015231bb318e9a'
option :universal
option :cxx11
@fission6
fission6 / broken_links.py
Created April 11, 2013 15:05
find broken links contained on page's within a domains sitemap.xml
@fission6
fission6 / services.py
Last active December 15, 2015 18:18
API Wrapper base service class
import requests
import json
import datetime
from .hooks import auth_check
class Service:
""" Base Service Class """
def __init__(self, username=None, password=None):
#/usr/bin/env python3
# -*- coding: utf-8 -*-
# _______ _______ _ _________ _ _______
# |\ /|( ___ )( ____ )( ( /|\__ __/( ( /|( ____ \
# | ) ( || ( ) || ( )|| \ ( | ) ( | \ ( || ( \/
# | | _ | || (___) || (____)|| \ | | | | | \ | || |
# | |( )| || ___ || __)| (\ \) | | | | (\ \) || | ____
# | || || || ( ) || (\ ( | | \ | | | | | \ || | \_ )
# | () () || ) ( || ) \ \__| ) \ |___) (___| ) \ || (___) |
# gunicorn.conf.py: getting gevent and gevent-psycopg2 running
bind = '127.0.0.1:1437'
accesslog = "<some-path>/logs/gunicorn-access.log"
errorlog = "<some-path>/logs/gunicorn-error.log"
workers = 5
try:
# fail 'successfully' if either of these modules aren't installed
from gevent import monkey
import gevent_psycopg2
@fission6
fission6 / gist:4164144
Created November 28, 2012 20:32 — forked from dgouldin/gist:1207636
Django templatetag to output the current page's querystring updated with the specified values including context variables.
from django import template
register = template.Library()
class UpdateQuerystringNode(template.Node):
def __init__(self, **kwargs):
self.kwargs = kwargs
def render(self, context):
@fission6
fission6 / git today
Created November 28, 2012 00:55
git alias for summarizing your/teams day of work (good for invoicing) by showing commit messages for the last day
[alias]
lg = log --graph --oneline --decorate --all
today = log --since=midnight --pretty='format:%an @ %ad%n%Cblue%s%n'
add this to ~/.gitconfig
then go
$ git today