Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile

Want to to come work with me at a $US2 billion dollar unicorn fighting climate change so our children have a greener future?

If you can you legally work right now in the USA, UK, Australia, Japan, Germany, or New Zealand, please apply by clicking the link below. We're hiring for many kinds of skills (marketing, design, customer support, etc), not just writing software.

If you can't yet legally work in one of the listed countries, don't worry. In the months and years to come we'll be opening offices in more countries around the world.

https://jobs.lever.co/octoenergy

# Python start-up file
# --------------------
# Ensure a PYTHONSTARTUP environment variable points to the location of this file.
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP
# Stolen 100% from David Winterbottom's file that I can't find right now.
# Always have pp available
from pprint import pprint as pp
# Pre-emptively import datetime as I use it a lot.
zip = 90213 # common US developer mistake
id = 46
map = Map()
object = MyObject()
obj = MyObject()
object_ = MyObject()
map_obj = Map()
@pydanny
pydanny / more_married.py
Last active December 30, 2020 01:12
More Married
"""
Audrey and I met on February 18, 2020. We were married on December 27th, 2020.
This programs calculates how much more we've been married than not married.
1. On November 4, 2017 our time married was now half the time we had been together.
2. On September 9, 2021 our time married will be twice as much as we knew each other.
3. On July 21, 2025, we
"""
from datetime import datetime
@pydanny
pydanny / badges.md
Last active September 21, 2020 19:01

Click "raw" and grab all the markdown!

PyPI

Code style: black

# settings/base.py
import os
# Normally you should not import ANYTHING from Django directly
# into your settings, but ImproperlyConfigured is an exception.
from django.core.exceptions import ImproperlyConfigured
def get_env_variable(var_name):
""" Get the environment variable or return exception """
try:
return os.environ[var_name]
[pytest]
addopts = --ds=config.settings.test --reuse-db -p no:warnings
python_files = tests.py test_*.py
@pydanny
pydanny / response-to-abusive-customer.md
Last active August 2, 2020 21:50
Within 12 hours of sending this email I got an apology. Sometimes it's better to write this out than quickly fire a customer.

There is nothing wrong in wanting to feed our families.

If I wanted to profit, I would stop selling digital versions of our books and only do printed versions. The last time we did that was for Two Scoops of Django 1.6, which made more than 1.5, 1.8, and 1.11 combined. That's the only way to put a halt to digital piracy: don't sell digital works. But that denies people in a lot of places access to our works. And means we're about pedagogy over profit.

We give hundreds of unpaid hours per year to open source projects. For years, every single book we've released we've given hundreds of print copies away as charity. Through books, articles, and open source contributions we have furthered people's knowledge around the world for over a decade.

All this means we're running a charity for the Python and Django community. These live classes are our means to hopefully do open source work for a living, with a few classes per month to cover our bills.

Can we make more money building apps for other people? Absolutely

# TODO: Add a comment above each line explaining what it does
# TODO: Add the ability to specify a game
# TODO: Make it so you don't have to run the script each time (while loop!)
# TODO: Convert this to use the Python built-in CSV library
from datetime import datetime
score = input("What score did I get? ")
with open("score.csv", "a") as f:
f.write(f"{datetime.now()}, {score}\n")
@pydanny
pydanny / method1.py
Created July 8, 2020 23:17
Which one is more legible?
def fun_function(name=None):
"""Find working ice cream promo"""
results = Promo.objects.active()
results = results.filter(
Q(name__startswith=name) |
Q(description__icontains=name)
)
results = results.exclude(status='melted')
results = results.select_related('flavors')
return results