Skip to content

Instantly share code, notes, and snippets.

View cjfswd's full-sized avatar
🎯
Focusing

Castillo Junior cjfswd

🎯
Focusing
View GitHub Profile
@cjfswd
cjfswd / typescript_plain_object.ts
Last active April 14, 2023 20:31
typescript type to get an plain object attribute depth.
export type PlainObject<T> = { [K in keyof T]: T[K] extends object ? never : T[K] };
@cjfswd
cjfswd / typescript_path.ts
Last active April 14, 2023 12:01
type to path into object keys with typescript,
type PathInto<T extends Record<string, any>> = keyof {
[K in keyof T as T[K] extends string
? K
: T[K] extends Record<string, any>
? `${K & string}.${PathInto<T[K]> & string}`
: never]: any
}
type PathTrace<T, K extends keyof T = keyof T> =
K extends string
@cjfswd
cjfswd / typescript_singleton.js
Created June 8, 2022 21:19
typescript singleton
export namespace server {
export let database: { title: string, message: string }[] = []
}
@cjfswd
cjfswd / typescript_environment.js
Last active June 23, 2022 07:27
typing environment variables at typescript project
declare global {
namespace NodeJS {
interface ProcessEnv {
VARIABLE_NAME: string;
}
}
}
export { }
@cjfswd
cjfswd / actions_deploy.yml
Last active June 3, 2022 13:58
github action to deploy with github pages
name: deploy
on:
# Triggers the workflow on push
push:
branches:
- development
permissions: write-all
@cjfswd
cjfswd / actions_cache.yml
Created May 31, 2022 17:36
github action to generate schedule cache files
name: Generate cache file
on:
# Triggers the workflow everyday
schedule:
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
@cjfswd
cjfswd / api_discord_get_channel_messages.js
Last active June 7, 2024 10:33
discord rest api get all messages from channel
import fs from 'fs'
import fetch from 'cross-fetch';
import dotenv from 'dotenv';
dotenv.config();
const TOKEN = process.env.TOKEN || ''
const GUILD_URL = process.env.GUILD_URL || ''
class IGuild {
@cjfswd
cjfswd / next.js_dynamic_endpoint.js
Created May 31, 2022 03:05
next.js parse http endpoint dynamically
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { slug } = req.query;
type HTTP_METHOD =
| "GET"
@cjfswd
cjfswd / nuxt3_dynamic_endpoint.js
Created May 31, 2022 03:02
nuxt 3 parse http endpoint dynamically
export default defineEventHandler((event) => {
let { req, res } = event;
const params = String(event.context.params._).split('/').filter(item => item != '')
if (params.length == 0) {
switch (req.method) {
case "GET":
res.statusCode = 200
return 'All resources getted with success.';
case "POST":
@cjfswd
cjfswd / css_vanilla_darkmode.css
Last active June 23, 2022 07:30
change browser default theme by css
/* supported on Chrome 81, Firefox 96 and Safari 13 */
:root {
color-scheme: dark;
}