Skip to content

Instantly share code, notes, and snippets.

View chrisvasqm's full-sized avatar

Christian Vasquez chrisvasqm

View GitHub Profile
@chrisvasqm
chrisvasqm / EXERCISE-1.md
Last active April 21, 2024 01:22
Object-Oriented Programming Exercises

Stopwatch Exercise

Design a class that represents a Stopwatch. We want to be able to start and stop it. There's no need to track the time that has passed between a start and stop action.

But we should be able to tell the consumer of this class whenever the Stopwatch has started, is already running, stopped and is already stopped on the console.

You should be able to generate this output on the console:

@chrisvasqm
chrisvasqm / APIClient.java
Created March 26, 2024 03:29
API Testing with Java + RestAssured + TestNG + Truth
package org.example.services;
import io.restassured.RestAssured;
import java.util.List;
public class APIClient<T> {
private final Class<T> type;
private final String baseUrl;
private final String endpoint;
@chrisvasqm
chrisvasqm / Shapes.java
Last active April 23, 2024 00:14
Shapes exercise
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
var shapes = Arrays.asList(
new Circle(3),
new Rectangle(5, 10),
new Square(5)
);
@chrisvasqm
chrisvasqm / Dockerfile
Last active June 6, 2024 20:11
Sample Dockerfile for a Node backend using Prisma and pnpm
FROM node:20.14.0-alpine3.20
WORKDIR /app
COPY . .
RUN npm install -g pnpm
RUN pnpm install
RUN pnpm generate
RUN pnpm migrate
RUN pnpm build
EXPOSE 3000
USER node
services:
postgres:
image: postgres:16.3-alpine3.20
container_name: appname
ports:
- '5432:5432'
environment:
POSTGRES_DB: appname
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
@chrisvasqm
chrisvasqm / tsconfig.json
Last active May 25, 2024 16:28
Sample tsconfig.json file to convert a JavaScript project to TypeScript (Tip: Remove the "module" property from your package.json if you have it)
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2020",
"sourceMap": true,
"outDir": "dist"
},
"include": [
"*"
@chrisvasqm
chrisvasqm / frontend-backend-database-compose.yml
Created May 27, 2024 11:56
Demostration docker-compose.yml file for a project with a Frontend + Backend+ Database setup to make local development easier
services:
db:
image: mongo:4.0-xenial
ports:
- 27017:27017
volumes:
- vidly:/data/db
api:
build: ./backend
@chrisvasqm
chrisvasqm / s3-delete-script.js
Created May 31, 2024 20:40
Delete objects from S3 while excluding some
const aws = require('aws-sdk');
// Configure the AWS SDK with your credentials
aws.config.update({
accessKeyId: 'ACCESS_KEY',
secretAccessKey: 'SECRET_ACCESS_KEY',
region: 'REGION'
});
// Create an S3 service object
@chrisvasqm
chrisvasqm / deploy.sh
Created June 1, 2024 04:35
Sample deployment script to use with a Virtual Machine setup (Linode, Digital Ocean Droplets, etc)
echo "Switching to master branch"
git checkout master
echo "Building app..."
pnpm build
echo "Deploying files to server..."
scp -r dist/* app@<DOMAIN_OR_IP>:/var/www/<DOMAIN_OR_IP>/
echo "Deployment done!"
@chrisvasqm
chrisvasqm / .dockerignore
Created June 6, 2024 22:30
Sample .dockerignore for a Node project
dist
node_modules
.git
.env
*.log
Dockerfile
docker-compose.yaml
.vscode
.idea
test