Skip to content

Instantly share code, notes, and snippets.

const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState, formState } = useFormContext() // comes from from react-hook-form
const fieldState = getFieldState(fieldContext.name, formState)
if (!fieldContext) {
throw new Error('useFormField should be used within <FormField>')
}
@nikolovlazar
nikolovlazar / auth.ts
Created August 14, 2024 11:34
React Hook Form + Zod validation. The form components are from the shadcn/ui library.
import { z } from 'zod'
export const signUpFormSchema = z.object({
email: z.string().email('Invalid email'),
password: z
.string()
.min(6, { message: 'Password must be at least 6 characters' }),
confirmPassword: z
.string()
.min(6, { message: 'Password must be at least 6 characters' }),
@nikolovlazar
nikolovlazar / tokyo-night.tmux
Created August 6, 2024 15:37
My modified tokyo-night tmux theme
#!/usr/bin/env bash
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# title Tokyo Night +
# version 1.0.0 +
# repository https://github.com/logico-dev/tokyo-night-tmux +
# author Lógico +
# email hi@logico.com.ar +
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
RESET="#[fg=brightwhite,bg=#15161e,nobold,noitalics,nounderscore,nodim]"
@nikolovlazar
nikolovlazar / tsconfig.json
Created July 17, 2024 21:06
Next.js tsconfig that works with inversify
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
@nikolovlazar
nikolovlazar / serviceLocator.ts
Last active July 2, 2024 22:55
An updated ServiceLocator that matches types in the `getService` method
import { CollectionsRepository } from '../repositories/collectionsRepository'
import { AuthenticationService } from './authenticationService'
import { CollectionsService } from './collectionsService'
interface ServiceMap {
AuthenticationService: AuthenticationService
CollectionsService: CollectionsService
}
@nikolovlazar
nikolovlazar / serviceLocator.ts
Created June 28, 2024 16:30
Service Locator pattern in TypeScript
import { CollectionsRepository } from '../repositories/collectionsRepository'
import { AuthenticationService } from './authenticationService'
import { CollectionsService } from './collectionsService'
export class ServiceLocator {
private static _cache: Record<string, any>
static {
console.log('Setting up cache')
@nikolovlazar
nikolovlazar / keybindings.json
Last active October 3, 2024 04:04
VSCode key bindings to navigate like Neovim
[
// Navigation
{
"key": "ctrl-h",
"command": "workbench.action.navigateLeft"
},
{
"key": "ctrl-l",
"command": "workbench.action.navigateRight"
},
@nikolovlazar
nikolovlazar / slugify.js
Created January 13, 2024 18:42
An Obsidian QuickAdd script that renames the file/parent folder to its slugified version
// https://byby.dev/js-slugify-string
const slugify = function (str) {
return String(str)
.normalize("NFKD") // split accented characters into their base characters and diacritical marks
.replace(/[\u0300-\u036f]/g, "") // remove all the accents, which happen to be all in the \u03xx UNICODE block.
.trim() // trim leading or trailing whitespace
.toLowerCase() // convert to lowercase
.replace(/[^a-z0-9 -]/g, "") // remove non-alphanumeric characters
.replace(/\s+/g, "-") // replace spaces with hyphens
.replace(/-+/g, "-"); // remove consecutive hyphens
// Name: tmux sesh
// Description: Atach to a tmux session
// Author: Lazar Nikolov
// Twitter: @NikolovLazar
import '@johnlindquist/kit';
const sessionsCmd = await $`tmux list-sessions`;
let sessions = sessionsCmd.stdout
// Name: tmux sesh
// Description: Opens a tmux session
import '@johnlindquist/kit';
const sessionsCmd = await $`tmux list-sessions`;
let sessions = sessionsCmd.stdout;
sessions = sessions
.split('\n')