Skip to content

Instantly share code, notes, and snippets.

View iamssen's full-sized avatar
🏄‍♂️

Seo Yeon, Lee iamssen

🏄‍♂️
  • Seoul, Korea
View GitHub Profile
@iamssen
iamssen / loader.mjs
Created June 5, 2024 05:39
Handling Import Aliases in Node.js ESM without NODE_PATH: A Practical Example
import generateAliasesResolver from 'esm-module-alias';
import { glob } from 'glob';
// TODO Create an aliases map { '@dir/a': 'dist/@dir/a/index.js', '@dir/b': 'dist/@dir/b/index.js', ... }
const aliases = glob
.sync('dist/@*/*/index.js', { cwd: import.meta.dirname })
.reduce((a, jsfile) => {
a[jsfile.substring(13, jsfile.length - 9)] = jsfile;
return a;
}, {});
@iamssen
iamssen / etag-cache-server-example.mts
Created June 5, 2024 04:55
Using HTTP ETag to Control Cache in a Koa Server Example
import cors from '@koa/cors';
import Router from '@koa/router';
import fs from 'fs';
import https from 'https';
import Koa from 'koa';
import { DateTime } from 'luxon';
const app = new Koa();
const router = new Router();
@iamssen
iamssen / media-query-template.css
Created February 28, 2023 02:51 — forked from mavieth/media-query-template.css
Media Query Template for Basic CSS
/**
* Basic CSS Media Query Template
* TODO: I should probably use Sass...
* Author: Michael Vieth
* ------------------------------------------
* Responsive Grid Media Queries - 1280, 1024, 768, 480
* 1280-1024 - desktop (default grid)
* 1024-768 - tablet landscape
* 768-480 - tablet
* 480-less - phone landscape & smaller
@iamssen
iamssen / test.ts
Created September 19, 2022 05:33
node-cron time matcher test
import { describe, test, expect } from 'vitest';
import TimeMatcher from 'node-cron/src/time-matcher';
describe('node-cron TimeMatcher test', () => {
test('should match times', async () => {
const seoul = new TimeMatcher('* 9-16 * * 1-5', 'Asia/Seoul');
expect(seoul.match(new Date('2022-09-18T12:38+09:00'))).toBeFalsy(); // is sunday
expect(seoul.match(new Date('2022-09-19T12:38+09:00'))).toBeTruthy(); // is monday
expect(seoul.match(new Date('2022-09-19T08:59+09:00'))).toBeFalsy();
@iamssen
iamssen / stream-pipe.ts
Last active May 6, 2021 00:09
typescript stream-pipe
import { ObservableInput, isObservable, Observable } from 'rxjs';
export type OperatorReturn<R> = ObservableInput<R> | R extends ObservableInput<
infer U
>
? U
: R;
export type Operator<T, R> = (params: T) => OperatorReturn<R>;
@iamssen
iamssen / sample.js
Last active August 29, 2020 16:22
Sample Snippet
module.exports = function() {
return 'hello world?';
}
@iamssen
iamssen / 6-json-request.ts
Created December 15, 2019 08:19
Understanding HTTP using Node.js "net" 6. Json Request
import Koa from 'koa';
import koaBody from 'koa-body';
import Router from 'koa-router';
import { Socket } from 'net';
const port: number = 9903;
// ---------------------------------------------
// server
// ---------------------------------------------
@iamssen
iamssen / 5-multipart-form-data-request.ts
Last active December 15, 2019 08:13
Understanding HTTP using Node.js "net" 5. Multi-Part Form Data Request
import fs, { ReadStream, WriteStream } from 'fs-extra';
import Koa from 'koa';
import Body from 'koa-body';
import Router from 'koa-router';
import { Socket } from 'net';
import os from 'os';
import path from 'path';
const port: number = 9903;
@iamssen
iamssen / 4-multipart-form-data.ts
Created December 13, 2019 14:13
Understanding HTTP using Node.js "net" 4. Multi-Part Form Data
import { createServer, Server } from 'net';
const port: number = 9903;
// ---------------------------------------------
// server
// ---------------------------------------------
const form: string = `
<html>
<body>
@iamssen
iamssen / 3-http-request.ts
Last active January 26, 2024 10:07
Understanding HTTP using Node.js "net" 3. HTTP Request
import { createServer, Server, Socket } from 'net';
const port: number = 9903;
// ---------------------------------------------
// server
// ---------------------------------------------
const server: Server = createServer((clientSocket: Socket) => { // 2. this is the client below
console.log(`[server] connected client: ${JSON.stringify(clientSocket.address())}`);