Skip to content

Instantly share code, notes, and snippets.

@Andrew-Chen-Wang
Andrew-Chen-Wang / openai.py
Last active December 3, 2024 15:30
Parallel calling OpenAI with rate limit handling
"""
Created by: @Andrew-Chen-Wang
Parallel calling OpenAI with rate limit handling.
Required packages:
- openai
- tenacity (optional if you remove the decorators. Useful for 500 errors)
Usage:
You must call with with_raw_response to get rate limit headers like:
@kirsteins
kirsteins / Array -> UnsafeMutablePointer -> Array
Last active June 16, 2024 09:42
Array -> UnsafeMutablePointer -> Array
var initalArray = [1, 2, 3]
let pointer: UnsafeMutablePointer<Int> = UnsafeMutablePointer(initalArray)
let arrary = Array(UnsafeBufferPointer(start: pointer, count: initalArray.count))
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//