Skip to content

Instantly share code, notes, and snippets.

@PutziSan
PutziSan / Stream ChatGPT API.md
Last active January 25, 2024 20:21
Streaming ChatGPT API Responses in Node.js using async generators

Streaming ChatGPT API Responses in Node.js

This repository contains a reusable function leveraging async generators to stream real-time responses from OpenAI's ChatGPT API, word by word, in a Node.js environment. Instead of waiting for the entire response to be generated, this function allows for an interactive experience where the AI's thoughts are streamed as they are produced.

Prerequisites

  1. Node.js 18.14 or higher (since we're using nodejs native fetch)
  2. A valid API key for OpenAI's ChatGPT

Usage

@PutziSan
PutziSan / machine.js
Created June 13, 2022 13:37
Generated by XState Viz: https://xstate.js.org/viz
const orderMachine = Machine({
id: "createOrder",
initial: "cart",
states: {
cart: {
on: {
NEXT: "customer"
}
},
customer: {
@PutziSan
PutziSan / create-tailwind-sort-list-pure-tailwind.js
Last active December 17, 2020 08:27
prettier-plugin-sort-class-names-order-tailwind-default
const resolveConfig = require("tailwindcss/lib/util/resolveConfig").default;
const defaultConfig = require("tailwindcss/defaultConfig");
const _ = require("lodash");
// const customPlugins = require("./tailwind-custom-plugins");
const path = require("path");
const appDir = path.dirname(require.main.filename);
const userConfigPath = path.join(appDir, "tailwind.config.js");
const config = resolveConfig([
// if you want to use your custom config then uncomment following line:
@PutziSan
PutziSan / tailwind.config.js
Last active August 18, 2019 15:05
TailwindCSS-config with generated classnames for justify-items, justify-self, justify-content, align-items, align-self and align-content
function alignContent({ addUtilities, variants }) {
addUtilities(
{
".align-content-start": {
"align-content": "flex-start"
},
".align-content-end": {
"align-content": "flex-end"
},
".align-content-center": {
@PutziSan
PutziSan / README.md
Last active February 11, 2020 12:13
create-react-story

Create React Story

A npx-utility for creating a storybook-story for your existing react-component.

usage

$ npx https://gist.github.com/PutziSan/7621bb69364fcf95409264261b77887c src/MyComponent.tsx
npx: installed 1 in 6.294s
write new story into src/MyComponent.stories.tsx
@PutziSan
PutziSan / purgecss-webpack-plugin.js
Created August 8, 2019 15:09
PurgeCSS via Webpack without glob
const esprima = require("esprima");
const Purgecss = require("purgecss");
const LastCallWebpackPlugin = require("last-call-webpack-plugin");
class Emitter extends require("events") {}
// by https://github.com/FullHuman/purgecss-from-js/blob/master/index.js
class PurgeFromJS {
static extract(content) {
const tokens = esprima.tokenize(content);
@PutziSan
PutziSan / Ideen.md
Last active September 18, 2018 09:11
Ideen zu react
  • React callback-hell => das wird zu nested funktonsaufrufen durch react (siehe wenn man reacttree mit babel umrechneb lässt) *das könnte man mit compose machen
  • Provider sollten read-onky sein, ctx also nicht bearbeitbar,
  • Fotms (fotmik-field) => setter nicgt in komponenten reingeben, sondern in der eltern-komponenete das onchange reingeben, ansonsten verändert das.kund sein Elternteil was zu sehr und sinnlos die app verschränkt und verwirrend macht
  • Insgesamt sollte optimalerweise ausschließlich mit generellen Events(onchangs, onload) gearbeitet werden und due eltern-komponenten sollten das für sich entsprechend implementieren => *ein setter sokltr niemals an eun.kind weitergegeben werden sindern immer nur mut inconchange subscriben sodass das kind keine ahnujg haben mhss was ltztendlicg implementiert wird

zb dropdown:

inout => load Vorschläge von db => dropdown miz values znd.onchangr,

@PutziSan
PutziSan / haskell-notes.md
Last active July 24, 2018 08:51
Haskell notes