This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* | |
* export const config = { | |
* runtime: "edge", | |
* }; | |
* | |
* const stream = await streamFromResponse(await openai.complete({ | |
* model: 'gpt-3.5-turbo', | |
* prompt: 'this is a test', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##################################################### | |
# Name: Bash CheatSheet for Mac OSX | |
# | |
# A little overlook of the Bash basics | |
# | |
# Usage: | |
# | |
# Author: J. Le Coupanec | |
# Date: 2014/11/04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const elemsIn = (tag, parent) => Array.from(parent.getElementsByTagName(tag)); | |
const speedUp = (v) => v.playbackRate = 2; | |
const videos = elemsIn('video', document); | |
const iframes = elemsIn('iframe', document); | |
videos.forEach(speedUp); | |
iframes.forEach((f) => elemsIn('video', f.contentWindow.document).forEach(speedUp)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# 1. Copy the raw text from https://www.corequran.com/ | |
# 2. Run "ruby parse.rb" | |
# 3. Paste the copied text | |
# 4. Press "Ctrl + D" to see the output | |
def parse(str) | |
str | |
.split("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
hexStringToIntArray: function(str) { | |
var res = [] | |
for(var i = 0; i < str.length; i += 2) { | |
res.push(parseInt(str.substring(i, i+2), 16)) | |
} | |
return res | |
}, | |
byteArrayToHexString: function(array) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Converts: | |
# people.csv | |
Name, Age, Height | |
Ahmed, 12, 103 | |
Mohamed, 19, 176 | |
.. into: | |
# people.json |
NewerOlder