Skip to content

Instantly share code, notes, and snippets.

View codegino's full-sized avatar

Carlo Gino Catapang codegino

View GitHub Profile
@codegino
codegino / mapping.js
Created February 27, 2023 07:48
All Countries JavaScript
export const allCountries = {
AF: 'Afghanistan',
AX: 'Åland Islands',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
AD: 'AndorrA',
AO: 'Angola',
AI: 'Anguilla',
AQ: 'Antarctica',
@codegino
codegino / 01-example.spec.ts
Last active February 9, 2023 10:50
Playwright - Writing a test
import { test, expect, chromium } from "@playwright/test";
test("get started link long version", async () => {
// Open a browser
const browser = await chromium.launch();
// Open a new page
const context = await browser.newContext();
const page = await context.newPage();
@codegino
codegino / basic-get.js
Last active November 2, 2022 05:39
Vanilla Node.js Server
const http = require("http");
const PORT = 8088;
const HOST = "localhost";
const server = http.createServer(function handleRequest(req, res) {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "hello world" }));
});
@codegino
codegino / NextJS.Dockerfile
Created August 23, 2022 12:37
Basic NextJS Dockerfile
# Install dependencies only when needed
FROM node:lts-alpine AS deps
WORKDIR /opt/app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
# This is where because may be the case that you would try
# to build the app based on some `X_TAG` in my case (Git commit hash)
@codegino
codegino / scroll-snap.css
Last active June 21, 2022 09:00
Scroll Snap
.container {
overflow: auto;
display: flex;
scroll-snap-type: x mandatory;
}
.box {
height: 200px;
width: 200px;
background: red;
@codegino
codegino / throttle.js
Created January 13, 2022 05:12
Basic Throttle
function throttle (callback, limit) {
var wait = false; // Initially, we're not waiting
return function () { // We return a throttled function
if (!wait) { // If we're not waiting
callback.call(); // Execute users function
wait = true; // Prevent future invocations
setTimeout(function () { // After a period of time
wait = false; // And allow future invocations
}, limit);
}
@codegino
codegino / debounce.js
Created January 13, 2022 05:11
Debounce Plain JavaScript
const debounce = (callback, wait) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
}, wait);
};
}
@codegino
codegino / Button.test.tsx
Created November 30, 2021 09:22
Testing Improvement
import {render,fireEvent} from './custom-rtl'
describe('Outlined Button', (): void => {
test('Size of button should render correctly for variant outlined', (): void => {
const { container } = render(
<ButtonOutlined color="grey">
<SvgClose /> Text does not matter
</ButtonOutlined>
);
@codegino
codegino / root.tsx
Created November 24, 2021 12:18
Remix Document Boilerplate
import {Links,LiveReload,Meta,Outlet,Scripts,ScrollRestoration} from "remix";
export default function App() {
return (
<Document>
<Layout>
<Outlet />
</Layout>
</Document>
);
@codegino
codegino / CustomImage.jsx
Last active November 17, 2021 09:58
Next Image with placeholder and error handler
function CustomImage({...props}: ImageProps) {
const [src, setSrc] = React.useState(props.src);
return (
<Image
onError={() => setSrc('/assets/image-error.png')}
placeholder="blur"
blurDataURL="/assets/image-placeholder.png"
{...props}
src={src}