Skip to content

Instantly share code, notes, and snippets.

View nem035's full-sized avatar
🐢
always learning

Nemanja Stojanovic nem035

🐢
always learning
View GitHub Profile
@nem035
nem035 / safe-rate-limit-chatgpt.js
Created May 17, 2023 19:06
Example how to handle OpenAI rate limiting
import openai from '/path/to/openai';
const MAX_RETRIES_IN_CASE_UNKNOWN_ERROR = 5;
export default async function promptChatGPT(
data,
retriesLeft = MAX_RETRIES_IN_CASE_UNKNOWN_ERROR
) {
const completionRequest = buildCompletionRequest(data); // <-- insert your own logic
function all(arrayOfPromises) {
return new Promise(function (resolve, reject) {
// initialize an array of results with length of the given array of promises
const results = Array.from(Array(arrayOfPromises.length));
// since all promises are started in parallel (quickly one after the other)
// we are using a counter to keep track of when they all resolve because
// each promise can take a different amount of time to resolve
let resultsLeft = arrayOfPromises.length;
@nem035
nem035 / machine.js
Last active May 2, 2020 05:34
Generated by XState Viz: https://xstate.js.org/viz
// ----------------------------------------------
// fake DB stuff
// ----------------------------------------------
const logger = console;
let COUNTER_UNTIL_DB_IS_A_GOOD_BOY = 3;
const fakeDb = {
isConnected: false,
package main
import (
"fmt"
"math/rand"
)
type Tree struct {
Left *Tree
Value int
{
"type": "PLAYGROUND",
"text": "`PLAYGROUND`: Run a query to generate the titles of each movie.",
"setup_sql": "CREATE TABLE movies (Id INTEGER, Title TEXT(19), Director TEXT(14), Year INTEGER, Length_minutes INTEGER);;INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (1, 'Toy Story', 'John Lasseter', 1995, 81);INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (2, 'A Bug''s Life', 'John Lasseter', 1998, 95);INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (3, 'Toy Story 2', 'John Lasseter', 1999, 93);INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (4, 'Monsters, Inc.', 'Pete Docter', 2001, 92);INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (5, 'Finding Nemo', 'Andrew Stanton', 2003, 107);INSERT INTO movies (Id, Title, Director, Year, Length_minutes)VALUES (6, 'The Incredibles', 'Brad Bird', 2004, 116);INSERT INTO movies (Id, Title, Director, Year, Length_minutes
import React from "react";
import ReactDOM from "react-dom";
class Async extends React.Component {
state = { isLoading: false };
componentDidCatch(x) {
if (x instanceof Promise) {
this.setState({ isLoading: true });
x.then(() => {
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
jobs:
install:
working_directory: ~/enki-project
docker:
- image: circleci/node:8.10.0
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
version: 2
jobs:
build:
working_directory: ~/enki-project
machine: true
environment:
- ENKI: 'example'
steps:
- checkout
install:
steps:
- checkout
- run:
name: NPM Install
command: npm install
- persist_to_workspace:
root: ~/my-workspace-path
paths: ./node_modules