Skip to content

Instantly share code, notes, and snippets.

Avatar
🐞

Ben Lopatin bennylope

🐞
View GitHub Profile
@bennylope
bennylope / productivity.sh
Last active Sep 30, 2019
Block (from Samuel Mullen on Legacy Rocks slack)
View productivity.sh
# List the domains you want to block, one per line, in your ~/.blocked_sites file,
# then ensure this script is included or sourced in your terminal configuration.
function worktime {
while read -r line; do
echo "127.0.0.1 ${line} # WORKTIME"
echo "fe80::1%lo0 ${line} # WORKTIME"
echo "127.0.0.1 www.${line} # WORKTIME"
echo "fe80::1%lo0 www.${line} # WORKTIME"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
@bennylope
bennylope / custom_backends.py
Created Mar 11, 2014
Extending Django Organizations backends. Use mixin custom functionality to override default backends using your own application. This example takes an optional `connection` argument and passes it to `send_mail`.
View custom_backends.py
from organizations.backends.defaults import RegistrationBackend, InvitationBackend
class SendMailMixin(object):
def _send_email(self, user, subject_template, body_template,
sender=None, connection=None, **kwargs):
"""Utility method for sending emails to new users"""
if sender:
from_email = "%s %s <%s>" % (sender.first_name, sender.last_name,
View cbv-dynamic-template.py
### MODEL
# -*- coding: utf-8 -*-
"""
Models for the "flatpages" project
"""
import time
import socket
from django.db import models
View install.sh
#!/usr/bin/env bash
PACKAGES=(pagecolor titling sourcecodepro mweights ly1 sourcesanspro needspace mdframed csquotes)
for item in ${PACKAGES[*]}
do
tlmgr install $item
done
View mutable_cached_property.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bennylope
bennylope / annotated.py
Created Sep 8, 2018
A Django model instance method decorator for creating queryset annotation compatibility.
View annotated.py
def annotated(attr_name):
"""
Decorator for returning pre-calculated, annotated values
This should be used with model instance methods that fetch some
kind of related or calculated data. If the method is called on
a single instance in isolation, we should expect the method to
execute and return its value. However if the method is called
on a member of a queryset where the `attr_name` was added as an
View numpy_append.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bennylope
bennylope / drain.rb
Last active Jul 12, 2018
A funky little script to download Drip broadcast messages and create Jekyll-ready Markdown files. See https://github.com/bennylope/drain.rb for updated version.
View drain.rb
#!/usr/bin/env ruby
# A little Ruby script to download your Drip broadcast messages to Jekyll-ready
# Markdown files. These could be used as posts or, better yet, as a collection.
# Inspired by Jonathan Stark's Drain https://github.com/jonathanstark/drain/
#
# Copyright Ben Lopatin, 2018
# Shared with an MIT license: https://opensource.org/licenses/MIT
# Since this is a standalone script, installing the dependencies is your responsibility
@bennylope
bennylope / brew-cleanup.sh
Created Nov 22, 2017
A short script for performing brew cleanup for all but specified packages. The 'cleanup' command can either be used for specific packages or for all - there is no exclusion option - and this means cleanup on older packages that I want.
View brew-cleanup.sh
#!/usr/bin/env bash
# Clean all but specified packages of old homebrewed installed packages
declare -a exclude=(python python3 python34 python35 python36 python27 pypy ruby node)
for PACKAGE in $(brew ls)
do
SENTINEL=false
for EXCLUDE in "${exclude[@]}"
@bennylope
bennylope / conftest.py
Created Mar 4, 2017 — forked from asfaltboy/conftest.py
A pytest fixture to test Django data migrations
View conftest.py
# based on https://gist.github.com/blueyed/4fb0a807104551f103e6
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
import pytest
@pytest.fixture()
def migration(transactional_db):