Skip to content

Instantly share code, notes, and snippets.

View carlos-talavera's full-sized avatar
🏠
Working from home

Carlos Talavera carlos-talavera

🏠
Working from home
View GitHub Profile
@carlos-talavera
carlos-talavera / permit.controller.ts
Last active December 13, 2025 15:41
Example of implementing Permit.io in NestJS
// This is to retrieve all the available permissions so you can fetch them in the frontend
import { AuthGuard } from '@/shared/auth/auth.guard';
import { Session } from '@/shared/decorators/session.decorator';
import { CheckPermissionsDto } from '@/shared/permit/dto/check-permissions.dto';
import { PermitService } from '@/shared/permit/permit.service';
import { SessionWithMetadata } from '@/shared/types';
import { Body, Controller, Post, Res, UseGuards } from '@nestjs/common';
import type { Response } from 'express';
@carlos-talavera
carlos-talavera / easy_broker_client.rb
Created October 16, 2024 18:23
Example of a Ruby class for fetching properties from the EasyBroker staging API, including RSpec tests using Webmock to simulate HTTP requests.
require 'net/http'
require 'json'
class EasyBrokerClient
BASE_URL = 'https://api.stagingeb.com/v1'
API_KEY = 'l7u502p8v46ba3ppgvj5y2aad50lb9'
def initialize
@headers = { 'X-Authorization' => API_KEY }
end
@carlos-talavera
carlos-talavera / string-calculator.test.ts
Last active October 16, 2024 18:20
Example of a function which takes a string of numbers separated by a specific delimiter and sums the numbers. Includes tests
import {sumNumbers} from "../core/string-calculator";
describe('StringCalculator', () => {
it('can handle null and empty strings', () => {
expect(sumNumbers(null)).toBe(0);
expect(sumNumbers('')).toBe(0);
});
it('can handle one number', () => {
expect(sumNumbers('18')).toBe(18);
@carlos-talavera
carlos-talavera / Dockerfile
Created September 7, 2024 15:23
Example of Dockerfile for a Next.js standalone build using pnpm
# Don't forget to add output: "standalone" on next.config
FROM node:22.6.0-alpine3.19 AS base
# Install system dependencies and pnpm dependencies
FROM base AS build-deps
RUN apk add --no-cache libc6-compat
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"