Skip to content

Instantly share code, notes, and snippets.

Brian Littmann brianlittmann

Block or report user

Report or block brianlittmann

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
brianlittmann / aws_uploader.rb
Last active May 26, 2016
Save image versions with Refile with streaming as a fallback
View aws_uploader.rb
class AwsUploader
BUCKET =["output_bucket"]
def self.upload(file, key)
bucket: BUCKET,
key: key,
body: file,
content_length: file.size
brianlittmann / datetime_range_formatter.rb
Last active Aug 29, 2015
Display summary of Ruby datetimes as range or as single day.
View datetime_range_formatter.rb
def formatted_datetime_range(start_datetime, end_datetime)
start_date = start_datetime.to_date rescue nil
end_date = end_datetime.to_date rescue nil
return "" if start_date.nil?
is_all_day = (start_datetime == start_datetime.beginning_of_day)
is_this_year = (start_datetime.year ==
if end_date && start_date != end_date
brianlittmann / restore_pg_table
Last active Aug 29, 2015
Replace data in a single PG table.
View restore_pg_table
### Source
# shell:
pg_dump -U username --data-only --table=tablename dbname > tablename.sql
### Target
# psql:
delete from tablename *;
# shell:
psql -U username dbname < tablename.sql
brianlittmann /
Created Jul 15, 2013
Django middleware component that wraps the login_required decorator around all URL patterns be default, with exceptions. Can also require user to belong to a group ("admin" in this gist) or be adapted if using the Django admin app.
Middleware component that wraps the login_required decorator around all URL patterns be default, with exceptions.
Define PUBLIC_URLS and ADMIN_URLS using regex in, where:
PUBLIC_URLS do not require user to be logged in.
ADMIN_URLS require user to be in admin group.
brianlittmann /
Last active Aug 2, 2017
Remove Python's smtplib CRAM-MD5 authentication method if getting SMTPAuthenticationError: (535, 'Authentication failed') and you know credentials are correct.
EMAIL_BACKEND = 'backends.SMTPEmailBackend'
"""Custom SMTP email backend class"""
import smtplib
from django.core.mail.utils import DNS_NAME
from django.core.mail.backends.smtp import EmailBackend
class SMTPEmailBackend(EmailBackend):
You can’t perform that action at this time.