Skip to content

Instantly share code, notes, and snippets.

View tiptopcoder's full-sized avatar
⚕️

Tien Nhan tiptopcoder

⚕️
View GitHub Profile
@tiptopcoder
tiptopcoder / _error.tsx
Last active April 17, 2023 10:26
Next.js Typescript error page
import { NextPageContext } from "next";
const Error = ({ statusCode }) => {
return (
<p>
{statusCode
? `An error ${statusCode} occurred on server`
: "An error occurred on client"}
</p>
);
@tiptopcoder
tiptopcoder / tsconfig.server.json
Last active February 16, 2020 02:46
Override Next.js tsconfig for express local development
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"noEmit": false
},
"include": ["server"]
}
@tiptopcoder
tiptopcoder / index.ts
Last active January 30, 2022 18:29
Next - Express Custom Server in Typescript
import express, { Request, Response } from "express";
import next from "next";
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const port = process.env.PORT || 3000;
(async () => {
try {
@tiptopcoder
tiptopcoder / settings.json
Created January 31, 2020 21:13
VSCode eslint autofix
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
import moduleAlias from "module-alias";
import path from "path";
const rootPath = path.resolve(__dirname, "..", "dist");
moduleAlias.addAliases({
"~": rootPath
});
export const formatName = (firstName: string, lastName: string) => {
return `${firstName} ${lastName}`;
};
import { formatName } from "~/utils/helpers/format-name";
export class User {
get fullName() {
return formatName("John", "Doe");
}
}
@tiptopcoder
tiptopcoder / test.js
Created January 14, 2020 07:14
How good your JS?
function addLinks () {
for (var i=0, link; i<5; i++) {
link = document.createElement("a");
link.innerHTML = "Link " + i;
link.onclick = function () {
alert(i);
};
document.body.appendChild(link);
}
}
@tiptopcoder
tiptopcoder / .block
Last active June 26, 2018 06:20
Tree of Life
license: gpl-3.0
height: 960
@tiptopcoder
tiptopcoder / .block
Last active May 23, 2018 15:57
fresh block
license: mit