Skip to content

Instantly share code, notes, and snippets.

Avatar

Bob Belderbos bbelderbos

View GitHub Profile
View bs4-requests_cache-Counter-example.py
import collections
import bs4
import requests
import requests_cache
requests_cache.install_cache('cache')
URL = "https://email-verify.my-addr.com/list-of-most-popular-email-domains.php"
View django-is_new-filter
@register.filter
def is_new(added, days=7):
days_new_deadline = timezone.now() - timezone.timedelta(days=days)
return added > days_new_deadline
# use in template
<a {% with obj.added|is_new as is_new %}
{% if is_new %}class="is_new newLeft"{% endif %}
{% endwith %} href="{% url 'app:view' pk %}">link</a>
View for-empty
{% for book in books %}
<li>{{ book }}</li>
{% empty %}
<li>Sorry, there are no books.</li>
{% endfor %}
View django_middleware_example.py
class TermsEnforcerMiddleware:
"""Django Middleware (add to MIDDLEWARE) to enforce users to sign the terms"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
# only relevant for logged in users
View django-command.py
from django.core.management.base import BaseCommand
# import ORM objects
class Command(BaseCommand):
help = 'help text'
def add_arguments(self, parser):
parser.add_argument(
'--test',
@bbelderbos
bbelderbos / discussed.py
Created Jul 11, 2018
has a topic been discussed on python bytes?
View discussed.py
# caches python bytes podcast links to a file and searches links on first cli
# arg string (case insensitive)
import os
import re
import sys
import time
import feedparser
from cfonts import render, say
@bbelderbos
bbelderbos / upgrade.md
Created Dec 28, 2017 — forked from zulhfreelancer/upgrade.md
How to upgrade Heroku Postgres database plan?
View upgrade.md
  1. Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin      git@bitbucket.org:xxx/xxx.git  (fetch)
origin      git@bitbucket.org:xxx/xxx.git  (push)
production  https://git.heroku.com/xxx.git (fetch)
production  https://git.heroku.com/xxx.git (push)
staging     https://git.heroku.com/xxx.git (fetch)