Skip to content

Instantly share code, notes, and snippets.

View ioslh's full-sized avatar
😀

Lianghua ioslh

😀
View GitHub Profile
@ioslh
ioslh / mount-connect-or-express-to-koa.js
Created March 29, 2021 07:48
mount connect/express to koa
import koa from 'koa'
import middlewareForExpressOrConnect from './path/some-middleware'
const app = new koa()
app.use(async (ctx, next) => {
const { req, res } = ctx
return new Promise((resolve, reject) => {
middlewareForExpressOrConnect(req, res, (err) => {
if (err) {
@ioslh
ioslh / es6-template-string.js
Last active August 17, 2021 09:47
tricky way to parse es6 template string
const parseEs6String = (str: string, ctx: Record<string, string>) => {
return new Function(`
const proxy = new Proxy(${JSON.stringify(ctx)}, {
has() { return true },
get(obj, prop) {
if (prop === Symbol.unscopables) return false
if (prop in obj) return obj[prop]
if (prop in window) return window[prop]
return ''
}
#include <iostream>
using namespace std;
char get_first_char(string *str) {
return (*str)[1] + 2;
}
void string_memory(){
long bottom = -1;
@ioslh
ioslh / microgpt.py
Created February 12, 2026 05:50 — forked from karpathy/microgpt.py
microgpt
"""
The most atomic way to train and inference a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp