Skip to content

Instantly share code, notes, and snippets.

View whoisryosuke's full-sized avatar
👾
Going deep with game development

Ryosuke whoisryosuke

👾
Going deep with game development
View GitHub Profile
@whoisryosuke
whoisryosuke / docgen.js
Created March 24, 2021 07:03
React / NodeJS - Generate React documentation inside MDX files using react-docgen-typescript. Setup for Docusaurus. Run using `node docgen.js`.
const docgen = require('react-docgen-typescript');
const fs = require('fs');
const path = require('path');
const DOCGEN_OPTIONS = {
savePropValueAsString: true,
};
const IGNORE_PATHS = [
'docs',
@whoisryosuke
whoisryosuke / find-by-query-param.js
Created March 11, 2021 18:54
MongoDB - How to filter a nested object by query params (e.g. metadata object that has different parameters like page)
export default async function(req: NextApiRequest, res: NextApiResponse) {
const {
query
} = req
const { db } = await connect()
// Finds all posts where the `metadata` property is an object
// and contains properties like `category`.
const posts: Posts[] = await db
@whoisryosuke
whoisryosuke / package.json
Created March 11, 2021 16:30
Babel/Typescript/NPM - How to build CJS, ESM, and Types using Babel and Typescript
"scripts": {
"build": "concurrently yarn:build:*",
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
"dev": "tsc --watch"
},
@whoisryosuke
whoisryosuke / clean-node-modules.js
Created March 11, 2021 16:26 — forked from bcinarli/clean-node-modules.js
Cleaning node modules, dist and build files in monorepo
const fs = require('fs');
const { rm } = require('./utils/file-actions');
const cwd = process.cwd();
const rm = (path) => {
if (fs.existsSync(path)){
exec(`rm -r ${ path }`, (err) => {
if (err) {
console.log(err);
tsc -p tsconfig.json && tsc -p tsconfig-cjs.json
@whoisryosuke
whoisryosuke / Dockerfile
Created March 10, 2021 22:32
Docker - Deploy static projects - This deploys the contents of the public folder (in same directory as Dockerfile) into the root of the nginx container. This is served at localhost:80
FROM nginx:alpine
COPY ./public /usr/share/nginx/html
@whoisryosuke
whoisryosuke / npm-permission-change.sh
Created March 9, 2021 01:39
NPM - Permission denied for installing global node_modules (e.g. `npm install -g npm`) @see: https://letscodepare.com/blog/npm-resolving-eacces-permissions-denied
sudo chown -R $(whoami) /usr/local/lib/node_modules/
@whoisryosuke
whoisryosuke / delete-node-modules.sh
Last active March 14, 2022 22:51
NPM - Delete all node_modules in a project -- `yarn clean:npm` @see: https://stackoverflow.com/a/43561012
# Mac only version
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
# Platform agnostic
npx rimraf ./**/node_modules
@whoisryosuke
whoisryosuke / docker-compose.yml
Created March 5, 2021 21:30
Docker - Quick MongoDB for app. Run `docker-compose up` to spin up DB alonside app. Connect to DB inside your app at `mongodb://localhost:27017/test`. @see: https://github.com/nestjs/nest/tree/master/sample/06-mongoose
version: "3"
services:
mongodb:
image: mongo:latest
environment:
- MONGODB_DATABASE="test"
ports:
- 27017:27017
@whoisryosuke
whoisryosuke / date-yyyy-mm-dd.js
Last active March 1, 2021 23:10
JS - Get YYYY-MM-DD formatted date -- see: https://stackoverflow.com/a/29774197
const dateString = new Date().toISOString().split('T')[0]