Skip to content

Instantly share code, notes, and snippets.

View gauravtoshniwal1989's full-sized avatar

Gaurav Toshniwal gauravtoshniwal1989

View GitHub Profile
@gauravtoshniwal1989
gauravtoshniwal1989 / find_unused_iam_policies.py
Created August 14, 2024 09:01
Use this script (carefully) to find IAM Policies not attached to any entity
import boto3
from datetime import datetime as dt
import os
from tqdm import tqdm
import json
import datetime
def datetime_handler(x):
if isinstance(x, dt):
@gauravtoshniwal1989
gauravtoshniwal1989 / create_contenttypes_and_permissions.py
Created March 4, 2018 14:45
Create ContentTypes and Permissions in Django
from django.apps.registry import Apps
app_config = apps.get_app_config('<app_name>')
# To create Content Types
from django.contrib.contenttypes.management import create_contenttypes
create_contenttypes(app_config)
# To create Permissions
from django.contrib.auth.management import create_permissions
{{ object.name }}
{{ object.owner }}
class CompanyIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
name = indexes.CharField(model_attr='name')
owner = indexes.CharField()
def get_model(self):
return Company
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
@gauravtoshniwal1989
gauravtoshniwal1989 / statics3upload.py
Created February 22, 2014 11:09
Management command to upload only files that have been changed to S3 The S3 bucket is assumed to be like: Bucket |-static |-media
from django.core.management.base import BaseCommand
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import os
from hashlib import md5
from subprocess import call
# Assuming the project structure is like this: