Skip to content

Instantly share code, notes, and snippets.

View bsenftner's full-sized avatar
🤨

Blake Senftner bsenftner

🤨
View GitHub Profile
@bsenftner
bsenftner / gist:1936e1ef8ae9b4f5d02a42d9a23d41a1
Last active March 23, 2024 11:52
working example of streaming responses from OpenAI and simultaniously saving them to the DB as they stream in
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key=get_settings().OPENAI_API_KEY,
)
# ----------------------------------------------------------------------------------------------
async def get_response_openai(aichat: AiChatDB):
if aichat.model=="gpt-3.5-turbo" or aichat.model=="gpt-4":
@bsenftner
bsenftner / gist:8ec474e7b142cb53e66d806ea9b40d85
Created February 8, 2018 15:40
simple jquery for dynamic collapsible web page elements
// an after-the-DOM is loaded wrapper,
// this makes designated elements slide up and disappear as soon as the page is visible,
// as well as holds conditional slide up/down logic for correctly configured content (see comments below):
$(function() {
// elements with a class of "content-hideable" have a "rel" attribute equal to the class of content
// that should be 'hidden' or 'revealed' upon a mouse click, accomplished via an animated toggle:
// for each element with class "content-hideable":
$('.content-hideable').each( function() {
@bsenftner
bsenftner / gist:ba3d493fa36b0b201ffd995e8c2c60a2
Created February 8, 2018 15:34
libav modification of libavformat/utils.c providing support for unexpected stream termination in live RTSP or similar video streams.
// Inside the file libavformat/utils.c is the routine "int av_read_frame(AVFormatContext *s, AVPacket *pkt)", one of the key routines
// used to play video streams through FFMPEG's libav. This routine does not handle the situation when a live stream terminates
// unexpectedly, such as the unplugging of a network connection, power loss to a camera, or other reasons an established connection
// would unexpectedly stop delivering packets.
// Below is the beginning of av_read_frame() up to and a bit past the three added lines necessary to support calling of the installed
// avformat interrupt callback. The conventional libav behavior is to call the avformat interrupt callback while establishing a new
// connection with a live stream. It is not called while the stream is playing, therefore no opportunity is provided to the client
// software to recognise unexpected stream termination.
// The three lines are added to the code pasted below. They should be easy to identify:
@bsenftner
bsenftner / gist:c7f983fda99ff463ba34e6e4bd69ebd1
Created February 8, 2018 15:09
A C++ class, an implementation of a general use AVFilterGraph for video playback within FFMPEG's libav libraries
//
// This file contains two code fragments:
// 1) A C++ class, an implementation of a general use AVFilterGraph for video playback. This class demonstrates a "best guess" of
// how an AVFilterGraph should be constructed, yet some WMV and AVI sourced video frames do not convert from the codec native format
// (yuv420p?) to the requested RGBA.
//
// 2) A C++ code fragment demonstrating how the above CE_LIBAV_FrameFilter class is used, and the error correcting logic catching
// when YUV to RGB conversion is incorrect, and a work-around for the pixel format conversion bug
//
// It appears a barebones AVFilterGraph is required to receive stable playback when working with a wide variety of formats & devices.