Skip to content

Instantly share code, notes, and snippets.

View ngot's full-sized avatar
🎯
Focusing

Henry Zhuang ngot

🎯
Focusing
View GitHub Profile
@ngot
ngot / koa_ts.ts
Created May 24, 2020 13:56
A simple demo of Koa in TypeScript
import Session from "koa-session";
import Router from "koa-router";
import Koa from "koa";
interface IContext {
dummy: string;
}
interface JContext {
dummy: number;
@ngot
ngot / polymorphism.ts
Created May 24, 2020 13:19
A simple polymorphism demo in TypeScript
// Package A
interface JContext {
j: string;
}
function fake1 (ctx: JContext) {
// type 2
console.log(ctx);
}
@ngot
ngot / v8-custom-global-error.cc
Last active November 14, 2017 09:04
v8 custom Error & Global Error
inline void ThrowError(const char* msg)
{
Isolate* isolate = Isolate::current();
// create custom error class/function
auto code =
"class MyError extends TypeError {"
"constructor(){"
"super();"
"this.name = 'MyError';"
"this.message = 'This is custom Error Object!"
@ngot
ngot / multi-thread.js
Last active October 25, 2023 15:27
V8 Thread Demo
start(() => {
while(true)
{
print("a");
sleep(1000);
}
})
while(true)
{
@ngot
ngot / booom.js
Created July 24, 2017 10:17
雪崩 Booom!
const compose = require('koa-compose');
const mids = [];
for (var i = 0; i < 20; i++) {
mids.push(async (context, next) => {
await next();
});
}
'use strict'
const thunk = require('thunks')()
const co = require('co')
function * testPromise (i) {
return yield Promise.resolve(i)
}
async function testAsync (i) {

Summary

Members Descriptions
namespace assert Assertion test module, if testing result is false, you will get an error. The way of handling error can be set as continue or throw exception.
namespace base32 base32 module with encode and decode operations. to use:
namespace base64 base64 module with encode and decode operations. to use:
namespace base64vlq base64vlq module with encode and decode operations. to use:
namespace bson bson module with encode and decode operations. to use:
namespace console console module
function check(n, fn, tm) {
var tm1 = tm || -1;
function _check() {
try {
if (fn()) return;
} catch (e) {
throw e;
return;
}
var structure = {
"root":{
"name":"Main Level",
"god": "is a girl",
nodes:{
"node1":{
"name":"Node 1"
},
"node2":{
"name":"Node 2"
@ngot
ngot / dbUtils.js
Created October 21, 2013 04:43
dbUtils.js
var mysql = require('mysql')
var env = process.env.NODE_ENV || 'development'
var config = require('../../config/config')[env]
var async = require('async');
var kit = require("./kit");
var logger = kit.getLogger();
//create mysql connection
var connection = mysql.createConnection(config.mysql);