Skip to content

Instantly share code, notes, and snippets.

View ekaone's full-sized avatar
🎯
Focusing

Eka Prasetia ekaone

🎯
Focusing
View GitHub Profile
@ekaone
ekaone / node_redis_cache.js
Created August 21, 2019 07:53 — forked from bradtraversy/node_redis_cache.js
Node.js & Redis Caching
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();
@ekaone
ekaone / memoizedHandlers.js
Created February 2, 2021 06:28 — forked from kyleshevlin/memoizedHandlers.js
Using React.useMemo to create a `handlers` object
// 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.
@ekaone
ekaone / App.js
Created March 9, 2021 05:32 — forked from skolhustick/App.js
ChakraUI - Login Form with ColorMode
import React from 'react'
import {
ThemeProvider,
theme,
ColorModeProvider,
CSSReset,
Box,
Flex,
IconButton,
useColorMode,
@ekaone
ekaone / hyper.js
Created June 25, 2021 02:55 — forked from coco-napky/hyper.js
Hyper config for git bash in Windows
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)',
@ekaone
ekaone / README.md
Created July 28, 2021 03:23 — forked from JonasWanke/README.md
GitHub Actions Cheat Sheet
@ekaone
ekaone / 00-README-NEXT-SPA.md
Created March 18, 2023 04:46 — forked from gaearon/00-README-NEXT-SPA.md
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

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.)

Building

@ekaone
ekaone / title-from-url.ts
Created March 28, 2023 07:15 — forked from steven-tey/title-from-url.ts
Get Title from URL
// 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();
})
@ekaone
ekaone / route.ts
Created May 31, 2023 04:58 — forked from m1guelpf/route.ts
Next.js App Route for getting the current playing song on Spotify (or a cached version)
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: {
@ekaone
ekaone / options.oak
Created July 7, 2023 04:57 — forked from thesephist/options.oak
Collection of useful Stable Diffusion prompt modifiers
{ 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'
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.