Skip to content

Instantly share code, notes, and snippets.

View pydanny's full-sized avatar

Daniel Roy Greenfeld pydanny

View GitHub Profile
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

[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
import sys
from django.core.signals import got_request_exception
from django.core.urlresolvers import reverse
from django.views.debug import technical_500_response
from django.utils.deprecation import MiddlewareMixin
class UserBasedExceptionMiddleware(MiddlewareMixin):
"""Allows superusers to see 500 debug pages in production"""
@pydanny
pydanny / Makefile.bash
Created June 20, 2020 18:10
Fixing OSX Upload Speed
ls:
ls -l /Library/Preferences/SystemConfiguration/
backup:
sudo mv /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist ~/projects/wifi-backup
sudo mv /Library/Preferences/SystemConfiguration/com.apple.network.eapolclient.configuration.plist ~/projects/wifi-backup
sudo mv /Library/Preferences/SystemConfiguration/com.apple.wifi.message-tracer.plist ~/projects/wifi-backup
sudo mv /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist ~/projects/wifi-backup
sudo mv /Library/Preferences/SystemConfiguration/preferences.plist ~/projects/wifi-backup
@pydanny
pydanny / simple_async_update_view.py
Last active June 8, 2020 18:07
simple_async_update_view.py 
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render, redirect
from django.views.generic import View
from asgiref.sync import sync_to_async
class AsyncViewMixin:
async def __call__(self):
return super().__call__(self)