Skip to content

Instantly share code, notes, and snippets.

View paragtyagi's full-sized avatar
🎯
Focusing

Parag Tyagi paragtyagi

🎯
Focusing
View GitHub Profile
@paragtyagi
paragtyagi / terraform.tfvars
Created August 4, 2022 21:06
Local settings file for Terraform project
aws_access_key = "AWS_ACCESS_KEY_HERE"
aws_secret_key = "AWS_SECRET_KEY_HERE"
key_name = "AWS_KEY_NAME_HERE"
private_key = "AWS_PRIVATE_KEY_PATH_HERE"
# aws
region = "ap-south-1"
ami = "ami-073c8c0760395aab8"
instance_type = "t2.micro"
@paragtyagi
paragtyagi / get_object.py
Last active April 21, 2016 10:36
Getting any object from a django Queryset (for Django < 1.8, since we don't have .first() or .last())
def get_object(queryset, index=None, get_last=False):
"""
:param queryset: django Queryset
:param index: (integer) index of Queryset. 0 will return first object of queryset
:param get_last: (bool) if True returns last object of queryset
:return: django Model object
"""
from django.db.models.query import QuerySet
if not isinstance(queryset, QuerySet):
raise ValueError('{} is not a Queryset instance'.format(queryset.__class__))
@paragtyagi
paragtyagi / manage_custom.py
Last active April 6, 2016 14:24
A custom manage.py file for managing pending migrations (only)
__author__ = "Parag Tyagi"
# set environment
import os
import sys
import django
sys.path.append('../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
django.setup()
@paragtyagi
paragtyagi / get_property.py
Last active February 2, 2016 12:09
Python - get property from data (object, dictionary, list, tuple or any complex combination of these) easily
from collections import OrderedDict
def get_property(data, prop, is_data=False):
"""
Input:
1) data: object, dictionary, list, tuples, or any complex combination of these
2) prop: string (property separated by dots)
Output:
If value found returns value, else None