Skip to content

Instantly share code, notes, and snippets.

View morenoh149's full-sized avatar
💭
Working from 🛰

Harry Moreno morenoh149

💭
Working from 🛰
View GitHub Profile
@morenoh149
morenoh149 / view.py
Last active October 11, 2022 21:46
django inspect variable
print('instance', dir(template_context['instance']))
> lists all variable fields
@morenoh149
morenoh149 / app.py
Created October 6, 2022 15:16
django orm optimization count on aggregates
results = myModel.objects.values().annotate(
group_representative=ArrayAggFirstElem('pk', distinct=True),
)
group_representatives = results.values_list('group_representative', flat=True)
assert_(
results.count() == group_representatives.count(),
'Aggregation Spec should partition the results space (no overlaps)'
)
@morenoh149
morenoh149 / local.yml
Created October 3, 2022 17:54
docker cookiecutter local.yml
version: "3"
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django: &django
build:
context: .
@morenoh149
morenoh149 / user-data.sh
Last active September 28, 2022 19:56
aws solution architect certification user data script for ec2 instances
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
@morenoh149
morenoh149 / deploy-django.md
Created September 28, 2022 05:35 — forked from rmiyazaki6499/deploy-django.md
Deploying a Production ready Django app on AWS

Deploying a Production ready Django app on AWS

In this tutorial, I will be going over to how to deploy a Django app from start to finish using AWS and EC2. Recently, my partner Tu and I launched our app Hygge Homes (a vacation home rental app for searching and booking vacation homes based off Airbnb) and we wanted to share with other developers some of the lessons we learned along the way.

Following this tutorial, you will have an application that has:

  • An AWS EC2 server configured to host your application
  • SSL-certification with Certbot
  • A custom domain name
  • Continuous deployment with Github Actions/SSM Agent
@morenoh149
morenoh149 / binary-tree.py
Last active September 8, 2022 17:24
quick binary tree
class Tree:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def insert(self, data):
if self.data:
if isinstance(self.data, int):
if self.left is None:
@morenoh149
morenoh149 / migrate_error.sh
Last active August 12, 2020 10:39
django postgis install
/Users/harrymoreno/.local/share/virtualenvs/litt-api-HgI9cQzm/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "/Users/harrymoreno/.local/share/virtualenvs/litt-api-HgI9cQzm/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: permission denied to create extension "postgis"
HINT: Must be superuser to create this extension.
The above exception was the direct cause of the following exception:
@morenoh149
morenoh149 / django-update-half.py
Last active February 27, 2020 21:32
Django update alternate model instances in shell
"""
Update alternate instances of a model in the database.
"""
from app.models import Post
ids_to_update = list(Post.objects.all().values_list('id', flat=True))[1::2]
Post.objects.filter(id__in=ids_to_update).update(some_field='some value')
$ ./k
2020.02.25 (c) shakti
/
/
\
$k a.k
Verb Adverb Noun Type System
: set ' each char " a" c \l a.k
+ plus flip / over/right i enc name ``ab n *\d [d]
@morenoh149
morenoh149 / smart-contracts.md
Last active February 1, 2020 17:59
Intro to smart contract programming in solidity Oct 2019