Skip to content

Instantly share code, notes, and snippets.

@yazinsai
yazinsai / convertkit.js
Created November 11, 2020 10:50
A simple script to register a user to ConvertKit using only Javascript
/* Submit an email address to ConvertKit using only Javascript */
function submitForm(email) {
fetch('https://app.convertkit.com/forms/XXXXXX/subscriptions', {
// replace XXXXXX above with your form ID (e.g. 1231234)
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `email_address=${email}`
}).then((response) => {
@yazinsai
yazinsai / bash-cheatsheet.sh
Created April 6, 2021 07:35 — forked from kannaiah/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
export const flattenObjectToMongoDbFormat = (obj: any, parent: String = ''): any => {
/**
* When you want to update a MongoDB document, without overriding
* nested fields that are not specified, you need to specify the
* nested fields in the format:
* `$set: { "parent.nested.key": "value" }`
*
* This method takes a nested object (usually from an incoming API
* request) and converts it to the nested format.
*/
const flattenObjectToMongoDbFormat = (obj, ancestors = []) => {
/**
* When you want to update a MongoDB document, without overriding
* nested fields that are not specified, you need to specify the
* nested fields in the format:
* `$set: { "parent.nested.key": "value" }`
*
* This method takes a nested object (usually from an incoming API
* request) and converts it to the nested format.
*/
@yazinsai
yazinsai / stream.ts
Last active May 16, 2023 07:40
Streams an OpenAI response, compatible with Next.js
/**
* Usage:
*
* export const config = {
* runtime: "edge",
* };
*
* const stream = await streamFromResponse(await openai.complete({
* model: 'gpt-3.5-turbo',
* prompt: 'this is a test',
function StreamedText() {
const [text, setText] = React.useState("");
React.useEffect(() => { getStream() }, []);
function getStream() {
// Fetch the stream
const stream = await fetch('/api/answer', { method: 'POST', body: JSON.stringify({ query } }) })
const data = stream.body;
if (!data) return;