Skip to content

Instantly share code, notes, and snippets.

@mko4444
mko4444 / getNftSpamStatus.ts
Last active December 5, 2024 01:06
Function that tests NFTs for spamminess using GPT-4o via the OpenAI API.
/**
* Function that tests NFTs for spamminess using GPT-4o via the OpenAI API.
*
* @param address - The contract address of any NFT collection
* @param network - The network the NFT is on (e.g. "ethereum") — refer to SimpleHash Docs for supported networks
* @returns - A boolean indicating whether the NFT is spammy or not
*
* @example getNftSpamStatus({ address: "0x03c4738Ee98aE44591e1A4A4F3CaB6641d95DD9a", network: "base" }); -> false
* @example getNftSpamStatus({ address: "0xDEB4f256312fa000B8564E0154e2d21b777e8f20", network: "base" }); -> false
@mko4444
mko4444 / itunes.ts
Last active October 30, 2024 06:34
iTunes Podcast API - Typescript SDK
// iTunes API TypeScript Module
type MediaType =
| "movie"
| "podcast"
| "music"
| "musicVideo"
| "audiobook"
| "shortFilm"
| "tvShow"
@mko4444
mko4444 / abbreviateDate.ts
Last active June 10, 2024 03:47
Returns a relative time string for UI (e.g. "2h", "3m", "10d")
import relativeTime from "dayjs/plugin/relativeTime";
import dayjs from "dayjs";
dayjs.extend(relativeTime);
function abbreviateDate(ms: number | string) {
const t = dayjs(ms);
const minutesAgo = dayjs().diff(t, "minute");
const hoursAgo = dayjs().diff(t, "hour");
@mko4444
mko4444 / abbreviateNumber.ts
Last active June 10, 2024 03:47
Abbreviates any number past 999 (e.g. "1.2k", "4.5m")
function abbreviateNumber(value: number) {
let suffix = "";
let divisor = 1;
// Determine the suffix and divisor based on the value
if (value >= 1e9) {
suffix = "b";
divisor = 1e9;
} else if (value >= 1e6) {
suffix = "m";
@mko4444
mko4444 / flex_shortcuts.scss
Last active October 30, 2024 06:41
Tailwind shortcuts to make writing flex classes easier
// place in main styles file or import
// examples:
// - ".row-fs-c" is a row with flex-start on main axis and center on secondary axis
// - ".col-sb-sb" is a column with space-between on main axis and secondary axis
// - ".row-sa-fe" is a row with space-around on main axis and flex-end on secondary axis
// - ".col": is a column with flex-start on main axis and secondary axis
@mixin flex-layout-generator() {
$directions: (
@mko4444
mko4444 / abbreviateTimeDiff.ts
Last active October 30, 2024 06:47
abbreviates the time until / since a specified datetime
/**
* Returns a relative time string for UI like in the Warpcast client.
* Works for both past and future dates.
* @param {number|string} ms - timestamp in milliseconds
* @returns {string} - relative time string
*/
export function abbreviateTimeDiff(ms: number | string) {
const t = new Date(ms).getTime();
const now = new Date().getTime();