This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_TO_HIT = "https://apikeys.googleapis.com/v2alpha1/projects/your-project-id/keys" | |
from google.auth.transport.requests import AuthorizedSession | |
from google.auth import default | |
# Assuming GOOGLE_APPLICATION_CREDENTIALS env variable is set | |
credentials, default_project_id = default(scopes=['https://www.googleapis.com/auth/cloud-platform']) | |
session = AuthorizedSession(credentials) | |
res = session.get(API_TO_HIT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Doing an API call using some service account credentials | |
API_TO_HIT = "https://apikeys.googleapis.com/v2alpha1/projects/your-project-name/keys" | |
from google.auth.transport.requests import AuthorizedSession | |
from google.oauth2 import service_account | |
credentials = service_account.Credentials.from_service_account_file( | |
filename='/path/to/your_service_account_creds.json', | |
scopes=['https://www.googleapis.com/auth/cloud-platform'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import ndb | |
client = ndb.Client() | |
# client = ndb.Client(project='your-project-name', namespace='your-namespace') | |
class Person(ndb.Model): | |
name = ndb.StringProperty() | |
age = ndb.IntegerProperty() | |
new = ndb.IntegerProperty() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from jsonschema import Draft7Validator | |
schema_file = '/path/to/schema_file/schema.json' | |
json_data = dict() # as ingested | |
# Loading schema file from data file folder | |
with open(schema_file) as fp: | |
json_schema = json.load(fp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/WestHealth/pyvis | |
# pip install pyvis | |
from pyvis.network import Network | |
g = Network(directed=True) | |
# If you want images as nodes | |
# g.add_node(0, label='Attacker', image='https://storage.googleapis.com/aarnav-test-sample/test01/hacker.png', shape='image') | |
# g.add_node(1, label='VM 01', shape='image', image='https://storage.googleapis.com/aarnav-test-sample/test01/monitor.png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sets env variable GOOGLE_CLOUD_PROJECT if not present | |
[[ -z "${GOOGLE_CLOUD_PROJECT}" ]] && read -p "Enter Project ID : " GOOGLE_CLOUD_PROJECT | |
gcloud config set project $GOOGLE_CLOUD_PROJECT | |
# Creating the service accounts | |
gcloud iam service-accounts create sa-2-high | |
gcloud iam service-accounts create sa-1-low |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import json | |
# pip install requests google-auth | |
try: | |
from google.oauth2 import service_account | |
from google.auth import impersonated_credentials | |
from google.auth.transport.requests import AuthorizedSession |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.geeksforgeeks.org/prefix-sum-2d-array/ | |
from copy import deepcopy | |
def get_from_array_if_present(array: list, x: int, y: int, default=None) -> int: | |
# Ensure that -ve indexes are never accessed | |
if x < 0 or y < 0: | |
return default | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for a binary tree node. | |
class TreeNode: | |
def __init__(self, x): | |
self.val = x | |
self.left = None | |
self.right = None | |
class Stack(list): | |
def push(self, node): | |
self.append(node) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disjoint sets are used to find cycles in a graph | |
from typing import Dict, Tuple, Any | |
class DisJointSet: | |
def __init__(self): | |
self.sets: Dict[Any, Tuple[bool, int]] = dict() | |
# tuple => (is_parent(bool), parent/weight(Any/int)) | |
# -> Denotes a node is parent itself | |
def get_parent(self, node): |
OlderNewer