Skip to content

Instantly share code, notes, and snippets.

View jmaicaaan's full-sized avatar

JM Santos jmaicaaan

  • Philippines
View GitHub Profile
@jmaicaaan
jmaicaaan / try-catch-snippet-01.js
Last active March 31, 2021 13:10
[Tutorial] Functional Try Catch
const getData = (id) => {
if (!id) {
throw new Error('No id found');
}
return [1, 2, 3, 4, 5].filter(i => i % id);
};
try {
const data = getData(2); // [1, 3, 5]
@jmaicaaan
jmaicaaan / package.json
Last active January 31, 2021 14:50
[Tutorial] NPM start script update
{
"name": "nextjs-with-google-cloud-run",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT"
},
"dependencies": {
@jmaicaaan
jmaicaaan / cloud-run.yml
Last active February 21, 2022 16:28
[Tutorial] Setting up cloud-run.yml for Github Actions
name: nextjs-cloud-run
on:
push:
branches:
- master
- main
env:
CLOUD_RUN_PROJECT_ID: ${{ secrets.CLOUD_RUN_PROJECT_NAME }}
@jmaicaaan
jmaicaaan / DockerIgnore
Created January 31, 2021 12:37
[Tutorial] Dockerizing Next.js - dockerignore
Dockerfile
.dockerignore
node_modules
npm-debug.log
@jmaicaaan
jmaicaaan / Dockerfile
Created January 31, 2021 12:35
[Tutorial] Dockerizing Next.js - Dockerfile
# base image
FROM node:14.15.4-alpine
# Create and change to the app directory.
WORKDIR /usr/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY . .
"Image placeholder": {
"prefix": "img#placeholder",
"body": [
"${2:https://via.placeholder.com/${1:150}}"
],
"description": "Image placeholder"
}
"Jest It": {
"prefix": "jest#it",
"body": [
"it('should $1', () => {",
" const actual = $2;",
" const expected = $3;",
" ",
" expect(actual).toBe(expected);",
"});"
],
"Jest Describe": {
"prefix": "jest#describe",
"body": [
"describe('$1', () => {",
" $2",
"});",
],
"description": "Jest Describe block"
}
"Jest Describe Full": {
"prefix": "jest#describe-full",
"body": [
"describe('$1', () => {",
" describe('happy paths', () => {",
" it('should return the value', () => {",
" expect(1).toBeTruthy();",
" });",
" });",
" describe('exception paths', () => {",
"React Component using filename": {
"prefix": "react#component-using-filename",
"body": [
"export type ${TM_FILENAME_BASE/(.*)/${1:/capitalize}Props/} = {};",
"export const ${TM_FILENAME_BASE/(.*)/${1:/capitalize}/} = (props: ${TM_FILENAME_BASE/(.*)/${1:/capitalize}Props/}) => {",
" return (",
" $2",
" );",
"};"
],