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
@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
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);
}
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(() => {
jobs:
install:
working_directory: ~/enki-project
docker:
- image: circleci/node:8.10.0
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
lint:
steps:
- checkout
- attach_workspace:
at: ~/my-workspace-path
- run:
name: Lint
# this will work because above we attach to the same workspace
# into which we previously persisted `node_modules`
command: ~/my-workspace-path/node_modules/.bin/eslint
install:
steps:
- checkout
- run:
name: NPM Install
command: npm install
- persist_to_workspace:
root: ~/my-workspace-path
paths: ./node_modules
async function workflow() {
const workspace = await install();
await Promise.all([build(workspace), lint(workspace)]);
if (isDeployBranch) {
await deploy(workspace);
}
}