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
import { OperationType } from "@safe-global/types-kit"; | |
import Safe from "@safe-global/protocol-kit"; | |
import SafeApiKit from "@safe-global/api-kit"; | |
import { encodeFunctionData, Hash } from "viem"; | |
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; | |
import { sepolia } from "viem/chains"; | |
import { waitForTransactionReceipt } from "viem/actions"; | |
const ERC20_TOKEN_ADDRESS = "0x..."; | |
const AMOUNT = 100n ** 18n; |
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
import { OpenAI } from "openai"; | |
const openai = new OpenAI({ apiKey: "your-api-key" }); | |
async function getEmbedding(text: string): Promise<number[]> { | |
const response = await openai.embeddings.create({ | |
model: "text-embedding-ada-002", | |
input: text, | |
}); | |
return response.data[0].embedding; // Вектор (1536 чисел) |
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 uniqueBy = <T extends Record<string, any> = Record<string, any>>( | |
array: T[], | |
by: string | string[], | |
): T[] => { | |
const uniqueArray: T[] = []; | |
array.forEach(item => { | |
const found = uniqueArray.find(it => { | |
if (Array.isArray(by)) { | |
return by.every(b => it[b] === item[b]); |
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 { ScrapingBeeClient } = require('scrapingbee') | |
async function get(url) { | |
const client = new ScrapingBeeClient("API_KEY") | |
return client.get({ | |
url, | |
params: { | |
json_response: true, | |
screenshot_full_page: true, | |
block_ads: true, |
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 { createWriteStream } = require("node:fs"); | |
const { Readable } = require("node:stream"); | |
;(async () => { | |
const XI_API_KEY = "sk_..."; | |
const VOICE_ID = "9BWtsMINqrJLrRacOk9x"; // Aria | |
const TEXT_TO_SPEAK = "hello world!"; | |
const OUTPUT_PATH = "output.mp3"; | |
const url = `https://api.elevenlabs.io/v1/text-to-speech/${VOICE_ID}/stream`; |
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
;(async () => { | |
const XI_API_KEY = 'sk_...' | |
const url = 'https://api.elevenlabs.io/v1/voices' | |
const headers = { | |
Accept: 'application/json', | |
'xi-api-key': XI_API_KEY, | |
'Content-Type': 'application/json', | |
} |
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
import { Writable } from "stream"; | |
export const streamAsPromise = (readable: Readable): Promise<Buffer> => { | |
const result: Array<Buffer> = []; | |
const w = new Writable({ | |
write(chunk, encoding, callback) { | |
result.push(chunk); | |
callback(); | |
}, |
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
import { Readable } from "stream"; | |
export const getReadableStream = (buffer: Buffer): Readable => { | |
const stream = new Readable(); | |
stream.push(buffer); | |
stream.push(null); | |
return stream; | |
}; |
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 mapSeries = <T>(tasks: Array<() => Promise<T>>): Promise<Array<T>> => { | |
return tasks.reduce((promiseChain, currentTask) => { | |
return promiseChain.then(chainResults => currentTask().then(currentResult => [...chainResults, currentResult])); | |
}, Promise.resolve([] as Array<T>)); | |
}; |
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 fisherYates = <T>(array: Array<T>): Array<T> => { | |
for (let i = array.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[array[i], array[j]] = [array[j], array[i]]; | |
} | |
return array; | |
}; |
NewerOlder