Skip to content

Instantly share code, notes, and snippets.

View mmyoji's full-sized avatar
🙃

mmyoji mmyoji

🙃
View GitHub Profile
@mmyoji
mmyoji / compose.yaml
Created February 27, 2025 01:03
Minimum example of Sequelize (MySQL) on Deno
services:
db:
image: mysql:8.0
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_bin
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=app_development
ports:
- "3306:3306"
@mmyoji
mmyoji / main.tsx
Last active February 7, 2025 05:14
minimal example of `use()` API w/ react@19
import { Suspense, use } from 'react';
function Messages({ fetchMessages }: { fetchMessages: Promise<string[]> }) {
// Promise must be initialized outside the component currently.
// see: https://react.dev/blog/2024/12/05/react-19#new-feature-use
//
// This doesn't work;
// ```
// const messages = use(new Promise<string[]>((resolve) => {
// setTimeout(() => {
@mmyoji
mmyoji / create-state-machine.ts
Last active October 9, 2024 02:40
State machine in TypeScript
/**
* @example
* ```ts
* const POST_STATE = {
* DRAFT: 0,
* PUBLISHED: 1,
* // ...
* } as const;
* type PostState = (typeof POST_STATE)[keyof typeof POST_STATE];
*
@mmyoji
mmyoji / express-5-upgrade-guide.md
Last active October 16, 2024 01:03
[WIP] express v5 upgrade guide

express.js official migration guide is not sufficient yet.

Regexp in route path cannot be used

  • Check manually in your RequestHandler
  • Be careful declaration order
// users.router.ts
import { Router } from "express";
@mmyoji
mmyoji / pagination.test.ts
Created May 10, 2024 08:32
Get page objects to implement pagination
import { assertEquals } from "jsr:@std/assert";
import { paginate } from "./pagination.ts";
Deno.test(function paginateTest() {
assertEquals(paginate(1, 1), [1]);
assertEquals(paginate(1, 2), [1, 2]);
assertEquals(paginate(2, 2), [1, 2]);
@mmyoji
mmyoji / multiline-vars-in-bash.sh
Created January 31, 2024 02:29
Multiline variables in bash
#!/bin/bash
function print_multiline() {
local text=$(cat <<'EOF'
```
# Markdown Text
- one
- two
```
@mmyoji
mmyoji / 00_timestamps-on-sequelize-v5.md
Last active December 15, 2023 01:06
timestamps behaviour on Sequelize v5

timestamps: boolean behaviours on Sequelize (v5)

const { Sequelize, DataTypes, literal } = require("sequelize");

const sequelize = new Sequelize({/* ... */});
@mmyoji
mmyoji / range.ts
Created December 11, 2023 09:46
`range()` function for TypeScript
/**
* ref: https://www.freecodecamp.org/news/javascript-range-create-an-array-of-numbers-with-the-from-method/
*
* # Example
*
* ```ts
* import { range } from "./main.ts";
*
* range(1, 5);
* // [1, 2, 3, 4, 5]
@mmyoji
mmyoji / lcm-and-gcd.ts
Last active December 8, 2023 09:16
LCM & GCD in TypeScript
/**
* LCM ... Least Common Multiple (最小公倍数)
* GCD ... Greatest Common Divisor (最大公約数)
*
* LCM = (A * B) / GCD
*/
function _findGCD(a: number, b: number): number {
if (a === 0) return b;
if (b === 0) return a;
@mmyoji
mmyoji / deno-queues-examples.ts
Last active September 28, 2023 00:29
Code examples of Deno Queues
// https://deno.com/blog/queues
function listenQueue<T>(fn: (msg: T) => Promise<void>) {
//
}
// lib/kv/queue/_core.ts
const messageTypes = {
foo: "foo",