Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
@bbelderbos
bbelderbos / upgrade.md
Created December 28, 2017 12:39 — forked from zulhfreelancer/upgrade.md
How to upgrade Heroku Postgres database plan?
  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      [email protected]:xxx/xxx.git  (fetch)
origin      [email protected]: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)
@bbelderbos
bbelderbos / discussed.py
Created July 11, 2018 01:13
has a topic been discussed on python bytes?
# 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
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',
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
{% for book in books %}
<li>{{ book }}</li>
{% empty %}
<li>Sorry, there are no books.</li>
{% endfor %}
@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>
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"
#!/bin/sh
set -e
if [ "$#" -ne 1 ]; then
echo "Usage: $0 package_name" >&2
exit 1
fi
mkdir $1
touch $1/__init__.py
import csv
from itertools import cycle
from faker import Faker
fake = Faker()
teachers = cycle([fake.user_name(), fake.user_name()])
classes = cycle(["Math", "English", "Physics"])
"""
Script to post a code snippet to PyBites CodeImag.es
If you see other use cases (e.g. process a csv file with snippets),
contact @bbelderbos on Twitter, thanks.
"""
from pprint import pprint as pp
# pip install requests python-decouple
import requests
from decouple import config