Skip to content

Instantly share code, notes, and snippets.

View darklight9811's full-sized avatar
🏠
Working from home

Rafael Corrêa Chaves darklight9811

🏠
Working from home
View GitHub Profile
import { auth } from "auth/helpers/auth";
import { createMiddleware } from "hono/factory";
type Session = typeof auth.$Infer.Session;
export function authMiddleware<Type extends "optional" | "guest" | "admin" | "required">(
type: Type = "required" as Type,
) {
return createMiddleware<{
Variables: Type extends "optional"
@darklight9811
darklight9811 / api.ts
Last active June 11, 2023 16:41
Nextjs Action Utility
// Packages
import { cache } from "react"
// Types
import type { z } from "zod"
import type { ZodSchema } from "zod"
// -------------------------------------------------
// Type
// -------------------------------------------------
@darklight9811
darklight9811 / use-prop.ts
Last active July 21, 2023 11:43
A useProp hook for react that handles auto currying, reducing and types for you.
// Packages
import { useCallback, useReducer } from "react"
// Constants
const invalid = Symbol()
// types
type Method<State> = (prev: State, curr: Partial<State>) => State
type Updater<State> = {
@darklight9811
darklight9811 / snow.js
Created December 21, 2022 18:30
Snow falling
// -------------------------------------------------
// Properties
// -------------------------------------------------
// HTML related
var canvasElement = document.querySelector("canvas");
var canvas = canvasElement.getContext("2d");
var quantity = canvasElement.getAttribute("data-snow");
// Javascript related
@darklight9811
darklight9811 / presenter.ts
Created September 8, 2022 20:45
Response Presenter
// -------------------------------------------------
// Types
// -------------------------------------------------
type Pagination<Data = any> = {
data: Data;
perPage: number;
totalNumber: number;
currentPage: number;
lastPage: number;
@darklight9811
darklight9811 / extractor.js
Last active August 27, 2021 19:33
Every alphabet from array extractor
export const getRawWord = (type) =>
({
undefined: "`${[![]][!![] + ![]]}`",
true: "([] + !![])",
false: "([] + ![])",
object: "`${{}}`",
}[type]);
export const getCharacter = (char) =>
({
// -------------------------------------------------
// Variables
// -------------------------------------------------
let debug: boolean = false;
let context: string[] = [];
// -------------------------------------------------
// Debug methods
// -------------------------------------------------
@darklight9811
darklight9811 / Resource.php
Last active May 7, 2020 23:35
Laravel default model resource test
<?php
namespace Tests;
//General
use Laravel\Sanctum\Sanctum;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Model\User;
@darklight9811
darklight9811 / idiocrat_generator
Created March 15, 2020 17:11
Idiocrat name generator
const prefix = [
"Bolso",
"Bolbo",
"Boldo",
"Bozo",
"Bolo"
];
const suffix = [
"naro",