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
{'event': 'opcode', | |
'file_name': 'C:\\py\\quicksand\\triangles.py', | |
'function_name': 'tri2', | |
'line': 12, | |
'number': 4144, | |
'opcode': 'STORE_FAST', | |
'time': 122333.7565349}, | |
{'event': 'line', | |
'file_name': 'C:\\py\\quicksand\\triangles.py', | |
'function_name': 'tri2', |
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
def get_comments(submission): | |
if type(submission) == str: | |
forest = reddit.submission(id=submission).comments | |
else: | |
forest = submission.comments | |
forest.replace_more(limit=None) | |
# now forest is a flat list of comments. Each comment may have children | |
def recur_get_comments(forest, level=0): | |
level += 1 | |
for x in forest: |
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
# run this script using persisted model.joblib from step 3 | |
from typing import Optional, List | |
from pydantic import BaseModel | |
from joblib import load | |
clf = load("model.joblib") | |
class FeatureVector(BaseModel): |
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 base64 | |
import os | |
import boto3 | |
kms = boto3.client('kms') | |
key_id = 'alias/kkey' | |
filename = "./example_b64_encoded_encrypted_file.txt" |
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 praw | |
import configparser | |
config = configparser.ConfigParser() | |
config.read("/secrets/earth-secrets.dev") | |
configs = config['ebooks'] | |
username = configs['username'] | |
password = configs['password'] | |
client_id = configs['client_id'] | |
client_secret = configs['client_secret'] |
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
""" Step 2 -- grant permission | |
Date: June 7, 2020, python 3.8 AWS lambda function | |
First, we have store the bearer token in an string. demo setParameter function below does that. You can run it on your laptop, getting and setting key | |
is for a separate gist. | |
Before we can call it from lambda, have to Attach a policy to the lambda's role. | |
In Lambda GUI, you go to "Permissions" tab; add inline policy; choose a service. | |
For parameters you want "Systems Manager". grant read access to GetParameters. You should also limit it to a specific parameter. |
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
# AWS doesn't allow use of request library we'd normally use, so sub out urllib | |
# Here, we alredy have a bearer token. That gets replaced daily, want to schedule it into parameter store | |
# We'll also write the data to s3 instead of returning it | |
import urllib.request as UR | |
import json | |
url = "https://traffic.ls.hereapi.com/traffic/6.2/flow.xml?bbox=38.93036,-77.17164;38.93154,-77.16965" | |
auth_info = {"access_token":"btJhbGciOiJSXlKaGJHY2lPaUprYVMamAMiAnk5TElUOXpRHAyUjRQRjZMdjGLUQREX1dnTk4wbG. . . .1GUvAlJAXe_qbJoJydw","token_type":"bearer","expires_in":86399} |
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
# 99% copy+paste from article by Vidhan Bhonsle | |
# https://developer.here.com/blog/requesting-here-oauth-bearer-token-using-python | |
# which exlains every line | |
# One addition: use configparser instead of literals | |
# the config file would look like: | |
# [here_api] | |
# oauth_key=98jPbLliAVceKs2hcCMvU-fA | |
# oauth_secret=aGcp8WLC-xT--AYmP-gyet2hcCMv . . . | |
import requests | |
import time |
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
# Here is job that runs a notebook -- hello world for running a job without | |
# logging into the DB GUI. | |
# The secrets file looks like: | |
# | |
# [hello] | |
# token = dapi25c47c... # you get this from databricks account | |
# brix_instance = dbc-bfd54799-f....cloud.databricks.com # url of your instance | |
# brix_user_dir = your username, for me the email address i signed up with | |
# | |
# This includes aws_attributes.instance_profile_arn ... this is an instance profiel |