Skip to content

Instantly share code, notes, and snippets.

View CatsMiaow's full-sized avatar
🌱
'~'/

Meow CatsMiaow

🌱
'~'/
  • Your Heart
  • 14:10 (UTC +09:00)
View GitHub Profile
@CatsMiaow
CatsMiaow / main.ts
Created June 12, 2020 05:26
Comlink example for Node.js with TypeScript
/**
* https://github.com/GoogleChromeLabs/comlink/blob/master/docs/examples/06-node-example/main.mjs
* https://github.com/GoogleChromeLabs/comlink/issues/476#issuecomment-642765445
* esModuleInterop to true in tsconfig.json compilerOptions.
*/
import { Worker } from 'worker_threads';
import * as comlink from 'comlink';
import nodeEndpoint from 'comlink/dist/umd/node-adapter';
import { cpus } from 'os';
@CatsMiaow
CatsMiaow / base62-bigint.ts
Last active April 17, 2022 14:28
BigInt Base62 Encoding
import * as assert from 'assert';
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
*/
export class Base62 {
private readonly base: bigint = BigInt(62);
private readonly charset: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
public encode(integer: string): string {
@CatsMiaow
CatsMiaow / base62-bignumber.ts
Last active August 30, 2019 06:44
BigNumber Base62 Encoding
import * as assert from 'assert';
import BigNumber from 'bignumber.js';
class Base62 {
private readonly base: BigNumber = new BigNumber(62);
private readonly charset: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
public encode(integer: string): string {
if (Number(integer) === 0) {
return '0';
@CatsMiaow
CatsMiaow / node-httpd-virtualhost.js
Created March 14, 2017 01:26
Node.js VirtualHost
const http = require('http');
const httpProxy = require('http-proxy');
const _ = require('lodash');
const virtualHost = {
// Proxy Web
'tested.co.kr': { target: { host: 'localhost', port: 8000 } },
// Proxy WebSocket
'ws.tested.co.kr': { target: { host: 'localhost', port: 8010 }, ws: true },
// Proxy Path
@CatsMiaow
CatsMiaow / node-mysql-bluebird-controller.js
Last active August 3, 2017 10:00
Node.js - MySQL에서 Bluebird 사용하기
'use strict';
var db = require('./db');
var testModel = require('./model');
var testControllers = {
// 모델에서 db.single() 함수를 사용한 예제입니다.
// 쿼리를 실행하고 커넥션을 반환합니다.
test1: function (req, res) {
testModel.getTest('test1').then(function (rows) {