Skip to content

Instantly share code, notes, and snippets.

View davidmoremad's full-sized avatar

David Amrani davidmoremad

View GitHub Profile
@davidmoremad
davidmoremad / google_maps_search_businesses.py
Created June 1, 2021 12:37
Search businesses in different areas on Google Maps
import requests
import json
import csv
MAPS_KEY='YOUR_API_KEY' # Get API_key & Enable Places_API on GCP
MAPS_RADIUS='3000' #3KM radius
MAPS_KEYWORD='PHYSIOTHERAPY' # What are you looking for
CITIES = [
{'name': 'madrid', 'cord': '40.416586, -3.703884'},
@davidmoremad
davidmoremad / security-nginx.conf
Created October 8, 2019 10:50
Security modifications for nginx configuration file
server_tokens off;
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
@davidmoremad
davidmoremad / lambda-public-buckets.py
Created June 12, 2019 10:54
Lambda Python script to private exposed buckets
import boto3
from botocore.exceptions import ClientError
import json
import os
ACL_RD_WARNING = "The S3 bucket ACL allows public read access."
PLCY_RD_WARNING = "The S3 bucket policy allows public read access."
ACL_WRT_WARNING = "The S3 bucket ACL allows public write access."
PLCY_WRT_WARNING = "The S3 bucket policy allows public write access."
RD_COMBO_WARNING = ACL_RD_WARNING + PLCY_RD_WARNING
@davidmoremad
davidmoremad / django_model.py
Created April 9, 2019 14:37
Django - Model fields
from django.db import models
from datetime import datetime
import Pet, Car
# Reference: https://docs.djangoproject.com/en/2.2/ref/models/fields/#choices
COUNTRIES = (
('ES', 'SPAIN'),
('FR', 'FRANCE'),
@davidmoremad
davidmoremad / python-common-tips.md
Last active February 4, 2019 10:02
Common snippets or tips for Python

Python - Common snippets or tips

List methods of a class

# Getting all objects from a class (except parent)
my_object = awspice.ec2
method_list = [ func[0] for func in inspect.getmembers(my_object, predicate=inspect.isroutine) if callable(getattr(my_object, func[0]))]
# Excluding private methods
@davidmoremad
davidmoremad / python_decorator_guide.md
Created February 3, 2019 13:47 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@davidmoremad
davidmoremad / thread_pool.py
Last active April 28, 2022 13:43
Simple class for Threading with Queues
# -*- coding: utf-8 -*-
from threading import Thread
from queue import Queue
class Worker(Thread):
"""
Thread executing tasks from a given tasks queue
http://code.activestate.com/recipes/577187-python-thread-pool/
"""
def __init__(self, tasks):