Skip to content

Instantly share code, notes, and snippets.

View KevinCotoCarrera's full-sized avatar
🌐
Open to work; send me an email

Kevin Coto KevinCotoCarrera

🌐
Open to work; send me an email
View GitHub Profile
@KevinCotoCarrera
KevinCotoCarrera / countryList.ts
Created April 1, 2025 15:24
Country List with Emoji Flag, country code, and dial code. Perfect for Custom Contact Number Input Components
export const COUNTRIES = [
{ code: 'AF', name: 'Afghanistan', dialCode: '+93', flag: '🇦🇫' },
{ code: 'AL', name: 'Albania', dialCode: '+355', flag: '🇦🇱' },
{ code: 'DZ', name: 'Algeria', dialCode: '+213', flag: '🇩🇿' },
{ code: 'AD', name: 'Andorra', dialCode: '+376', flag: '🇦🇩' },
{ code: 'AO', name: 'Angola', dialCode: '+244', flag: '🇦🇴' },
{ code: 'AG', name: 'Antigua and Barbuda', dialCode: '+1-268', flag: '🇦🇬' },
{ code: 'AR', name: 'Argentina', dialCode: '+54', flag: '🇦🇷' },
{ code: 'AM', name: 'Armenia', dialCode: '+374', flag: '🇦🇲' },
{ code: 'AU', name: 'Australia', dialCode: '+61', flag: '🇦🇺' },
@KevinCotoCarrera
KevinCotoCarrera / +page.server.ts
Created March 30, 2025 16:16
Resend in Svelte Kit using form actions
// +page.server.ts
import { env } from '$env/dynamic/private';
import type { ValidationErrors } from '$lib/types/form-validation';
//git clone https://gist.github.com/1661f024493c3de8e014cd9498d6c978.git (to get validateForm utility)
import { validateForm } from '$lib/utils/form-validation.js';
import { Resend } from 'resend';
const resend = new Resend(env.PRIVATE_RESEND_KEY);
function extractAndValidate(formData: FormData) {
const values = {
message: formData.get('message')?.toString() || '',
@KevinCotoCarrera
KevinCotoCarrera / form-validation.ts
Last active March 30, 2025 16:15
Minimalist Form Validation Utility
import type { ValidationErrors, ValidationValues } from '../../ambient';
export function validateForm(values: Partial<ValidationValues>): ValidationErrors {
const errors: ValidationErrors = {};
// Message Validation
if ('message' in values) {
if (!values.message) {
errors.message = 'Please provide a message';
} else if (values.message.trim().length < 50 || values.message.trim().length > 5000) {
errors.message = 'Message must be between 50 and 5000 characters.';
@KevinCotoCarrera
KevinCotoCarrera / FileInput.svelte
Created March 22, 2025 13:16
File Input that also allows textarea implemented in Svelte 5
<script lang="ts">
import type { FormInputProps } from '../../../ambient';
let {
id,
label,
type = 'text',
value = $bindable(''),
error = '',
placeholder = ''
@KevinCotoCarrera
KevinCotoCarrera / +server.ts
Created March 19, 2025 07:37
A server file(used and tested in Svelte KIT) for getting a presigned url for S3 uploads
// src/routes/api/presigned-url/+server.ts
import type { RequestHandler } from '@sveltejs/kit';
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { s3Client, S3_BUCKET_NAME } from '$lib/config/s3';
export const POST: RequestHandler = async ({ request }) => {
try {
const { fileName, fileType } = await request.json();
@KevinCotoCarrera
KevinCotoCarrera / Field.tsx
Last active May 15, 2024 22:09
Revisar buenas practicas
import {Root} from '@radix-ui/react-label';
import { cva, type VariantProps } from "class-variance-authority"
import { useState } from 'react';
import { PhoneInput } from 'react-international-phone';
import 'react-international-phone/style.css';
import { twMerge } from "tailwind-merge"
const field = cva(
[
"flex",
"flex-wrap",
@KevinCotoCarrera
KevinCotoCarrera / prettier
Created January 3, 2023 20:23
Prettier config for Nestjs Project
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine":"auto"
}
@KevinCotoCarrera
KevinCotoCarrera / .eslintrc.js
Created January 3, 2023 20:22
Eslint config for Nestjs Project
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',