Skip to content

Instantly share code, notes, and snippets.

View readytheory's full-sized avatar

Levin readytheory

  • Omaha, NE
  • 04:20 (UTC -05:00)
View GitHub Profile
{'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',
@readytheory
readytheory / praw_print_comments.py
Created April 24, 2022 02:33
praw get comments depth first
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:
@readytheory
readytheory / data_type_confusion_trained_model.py
Created March 2, 2022 12:18
Anomalous Dex -- Stuck on 4.1.c.3
# 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):
import base64
import os
import boto3
kms = boto3.client('kms')
key_id = 'alias/kkey'
filename = "./example_b64_encoded_encrypted_file.txt"
@readytheory
readytheory / main.py
Created December 26, 2020 18:50
list reddit subs you've posted to
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']
@readytheory
readytheory / lambda2.py
Last active June 7, 2020 17:21
Call here.com from AWS lambda -- Part 2 use AWS parameters for bearer token
""" 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.
@readytheory
readytheory / lambda.py
Created June 7, 2020 15:17
Call here.com from AWS lambda -- Part 1 urllib instead of requests --
# 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}
@readytheory
readytheory / here_api_bearer_token.py
Last active March 16, 2021 16:09
how to get a bearer token from here.com -- June 2020
# 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
@readytheory
readytheory / hello_databricks_api.py
Created May 28, 2020 00:01
Databrick Notebook launch from laptops script
# 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