This file contains hidden or 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 express = require('express'); | |
| const fetch = require('node-fetch'); | |
| const redis = require('redis'); | |
| const PORT = process.env.PORT || 5000; | |
| const REDIS_PORT = process.env.PORT || 6379; | |
| const client = redis.createClient(REDIS_PORT); | |
| const app = express(); |
This file contains hidden or 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
| // One of my new favorite React Hook patternms is to create handler | |
| // functions for a custom hook using `React.useMemo` instead of | |
| // `React.useCallback`, like so: | |
| function useBool(initialState = false) { | |
| const [state, setState] = React.useState(initialState) | |
| // Instead of individual React.useCallbacks gathered into an object | |
| // Let's memoize the whole object. Then, we can destructure the | |
| // methods we need in our consuming component. |
This file contains hidden or 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 React from 'react' | |
| import { | |
| ThemeProvider, | |
| theme, | |
| ColorModeProvider, | |
| CSSReset, | |
| Box, | |
| Flex, | |
| IconButton, | |
| useColorMode, |
This file contains hidden or 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 = { | |
| config: { | |
| // default font size in pixels for all tabs | |
| fontSize: 12, | |
| // font family with optional fallbacks | |
| fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace', | |
| // terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk) | |
| cursorColor: 'rgba(248,28,229,0.8)', |
Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.
You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.
You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)
This file contains hidden or 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
| // Note: this gist is a part of this OSS project that I'm currently working on: https://github.com/steven-tey/dub | |
| export default async function getTitleFromUrl (url: string) { | |
| const controller = new AbortController(); | |
| const timeoutId = setTimeout(() => controller.abort(), 2000); // timeout if it takes longer than 2 seconds | |
| const title = await fetch(url, { signal: controller.signal }) | |
| .then((res) => { | |
| clearTimeout(timeoutId); | |
| return res.text(); | |
| }) |
This file contains hidden or 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 redis from '@/lib/redis' | |
| import { tap } from '@/lib/utils' | |
| import { NextResponse } from 'next/server' | |
| import { NowPlaying } from '@/types/activities' | |
| import { base64_encode, use } from '@/lib/utils' | |
| type SpotifyResponse = { | |
| is_playing: boolean | |
| progress_ms: number | |
| item: { |
This file contains hidden or 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
| { name: 'Lighting', options: [ | |
| 'golden hour, warm glow' | |
| 'blue hour, twilight, ISO12000' | |
| 'midday, direct lighting, overhead sunlight' | |
| 'overcast, whitebox, flat lighting, diffuse' | |
| 'dreamlike diffuse ethereal lighting' | |
| 'dramatic lighting, dramatic shadows, illumination' | |
| 'studio lighting, professional lighting, well-lit' | |
| 'flash photography' | |
| 'low-key lighting, dimly lit' |
This file contains hidden or 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 ollama | |
| import time | |
| def read_file(file_path): | |
| """ | |
| Reads the content of a file and decodes it using the 'latin-1' encoding. | |
| Args: | |
| file_path (str): The path to the file to be read. | |
OlderNewer