Skip to content

Instantly share code, notes, and snippets.

View spencerkittleson's full-sized avatar

Spencer Kittleson spencerkittleson

  • NICE / MindTouch
  • San Diego, CA
View GitHub Profile
from machine import Pin,I2C,SPI,PWM,ADC
import framebuf
import time
import math
DC = 8
CS = 9
SCK = 10
MOSI = 11
@spencerkittleson
spencerkittleson / main.py
Last active March 21, 2024 18:27
Validate a JWT token is from a configured issuer
import requests
import json
import jwt
from dotenv import dotenv_values
def get_json(endpoint: str):
response = requests.get(endpoint)
response.raise_for_status()
return json.loads(response.content)
public async Task<DataResponse> GetAsync(string uri, List<KeyValuePair<string, string>> formValues) {
try {
var auth = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(Encoding.UTF8.GetBytes(
$"{HttpUtility.UrlEncode(_clientId)}:{HttpUtility.UrlEncode(_clientSecret)}")));
var request = new HttpRequestMessage(HttpMethod.Post, uri) {
Headers = { Authorization = auth },
Content = new FormUrlEncodedContent(formValues)
};
using var response = await HttpClient.SendAsync(request);
@spencerkittleson
spencerkittleson / loadTest.py
Created July 12, 2023 14:27
Parallel Executions (taken from somewhere else)
import asyncio
import aiohttp
import time
async def get(url, session):
try:
async with session.get(url=url) as response:
resp = await response.read()
print("Successfully got url {} with resp of length {}.".format(url, len(resp)))
# https://python.langchain.com/docs/modules/model_io/models/llms/integrations/llamacpp
import os
from langchain import PromptTemplate, LLMChain
from langchain.llms import LlamaCpp
from langchain import PromptTemplate, LLMChain
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
template = """Question: {question}
@spencerkittleson
spencerkittleson / main.py
Created June 26, 2023 16:37
gpt4all with knowledge
from langchain.llms import GPT4All
from langchain.vectorstores import Chroma
from langchain.indexes import VectorstoreIndexCreator
from langchain.indexes.vectorstore import VectorStoreIndexWrapper
from langchain.document_loaders import DirectoryLoader, TextLoader, UnstructuredMarkdownLoader
from langchain.chains import RetrievalQA
import sys
import os
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain.embeddings import HuggingFaceEmbeddings, SentenceTransformerEmbeddings
@spencerkittleson
spencerkittleson / do.py
Created June 14, 2023 17:24
pytest with ducktyping
import requests
import xml.etree.ElementTree as ET
def get_current_weather(uri: str, client = requests) -> str:
result = client.get(uri)
weather = ET.ElementTree(ET.fromstring(result.text)).getroot().findall("./weather")[0].text
return weather
@spencerkittleson
spencerkittleson / userfavs.py
Created May 17, 2023 22:05
Python Spotify Playlist User Retrieval
from simple_http_server import route, server
from threading import Thread
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import os
from simple_http_server import route, server
@route("/")
@spencerkittleson
spencerkittleson / serverSideToken.cs
Created March 29, 2023 17:35
CXOneExpert Server Side Tokens
using System;
using System.IO;
using System.Security.Cryptography;
using System.Net.Http;
// Server API Token key and secret are available from API token management dashboard when Server API Token is generated
var key = "da28b6ec3ea350db524d80099f8c9f40f2fab2f4caf91a8d49d4cb4d659a9785";
var secret = "60a63916a77ef70c0ecf42b134f44fbb9732b395ae33dc6d5165aad2b5668bb4";
// include username prefixed with '='
@spencerkittleson
spencerkittleson / index.js
Last active March 17, 2023 21:14
Bot to get titles
import puppeteer from "puppeteer";
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(
"https://sfbay.craigslist.org/search/sby/sof#search=1~thumb~0~0"
);
// Set screen size