Skip to content

Instantly share code, notes, and snippets.

View buddylindsey's full-sized avatar
🚜
Homesteading

Buddy Lindsey, Jr. buddylindsey

🚜
Homesteading
View GitHub Profile
CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix sqlite)/include" pyenv install -f 3.7.4
@buddylindsey
buddylindsey / steps.md
Created January 22, 2019 21:32
Possible Bug with Multi-db in django 2.1

Steps to re-produce a possible bug in using multiple databases in Django 2.1

Goal

The goal is to be able to have an app that all models in that app go to a seperate database, other models like the django-admin, go to default.

Expected

I expect that when I target no database it migrates all existing migrations, not in my new app, to the default database connection.

Then when I run ./manage.py migrate --database=otherdatabase it only migrates those models in the new app, or none at all.

Keybase proof

I hereby claim:

  • I am buddylindsey on github.
  • I am buddylindsey (https://keybase.io/buddylindsey) on keybase.
  • I have a public key ASAmMMY4XxxgKuZbPy6nsNmbv7V3TCMNGYSsgRZyMzNEmAo

To claim this, I am signing this object:

@buddylindsey
buddylindsey / create_cloudwatch_alarms
Last active December 19, 2018 15:03
Examples other people have used to create cloud watch alarms
https://read.acloud.guru/slack-notification-with-cloudwatch-alarms-lambda-6f2cc77b463a
aws cloudwatch put-metric-alarm --region us-east-1
--alarm-name "HighCPUUtilization"
--alarm-description "High CPU Utilization"
--actions-enabled
--alarm-actions "TOPIC_ARN"
--metric-name "CPUUtilization"
--namespace AWS/EC2 --statistic "Average"
--dimensions "Name=InstanceName,Value=demo"
--period 60
var DataLoader = require("DataLoader");
function getUsers(keys) {
console.log("Should be called once");
console.log(keys);
return Promise.resolve(keys);
}
var userLoader = new DataLoader(keys => {
return Promise.resolve(getUsers(keys));
@buddylindsey
buddylindsey / pycharm_django_console.py
Last active June 9, 2017 13:21
pycharm django console to load all models and other useful stuff
# Append to the end of default config in pycharm django console in settings
from django.conf import settings
version = django.get_version().split('.')
if (int(version[0]) < 2 and int(version[1]) > 6):
from django.apps import apps
get_models = apps.get_models
elif bool(int(version[0]) < 2) and bool(int(version[1]) < 7):
from django.db.models.loading import get_models
for _class in get_models():
globals()[_class.__name__] = _class
@buddylindsey
buddylindsey / djangocon-us-2017-cfp.md
Last active April 10, 2017 01:09
Djangocon US 2017 Talk Ideas

The Beauty of ViewSets in Django Rest Framework

Audience Level

BeginnerMediate (Anyone who has a little experience with Django and Django Rest Framework)

Description

ViewSets will make your code shorter, more robust, and save you time during your development, if you let them. I have spent a lot of time dealing with writing view code and dealing with urls only to finally learn ViewSets. It immediately saved development time as well as making my code more simple.

Generally to make a new, basic, endpoint in DRF for a model it would take about 15 minutes. That included creating a serializer, urls, views, and testing it the browser. Now that same endpoint is more easily understood and done, all the steps, in less than 5 minutes.

@buddylindsey
buddylindsey / test_attrs.py
Created February 14, 2017 16:43
test_attrs
class CompanyViewSet(ListModelMixin, GenericViewSet):
authentication_classes = (TokenAuthentication,)
serializer_class = CompanySerializer
filter_backends = (filters.DjangoFilterBackend, filters.OrderingFilter)
ordering_fields = ('name',)
filter_class = CompanyFilterSet
class CompanyViewSetTests(TestCase):
def test_attrs(self):
from django.conf.urls import url
from django.contrib.auth.models imort User
from django.shortcuts import render
from django.views.generic import ListView
# views.py
def index(request):
users = User.objects.all()
staff = User.objects.filter(is_staff=True)
context = {'users': users, 'staff': staff}
from django.conf.urls import url
from django.shortcuts import render
from django.contrib.auth.models import User
from django.views.generic import ListView
urlpatterns = [
url(r'^$', index, name='index'),
url(r'^index2/$', IndexView.as_view, name='index2')
]