Skip to content

Instantly share code, notes, and snippets.

View ioslh's full-sized avatar
😀

Lianghua ioslh

😀
View GitHub Profile
#include <iostream>
using namespace std;
char get_first_char(string *str) {
return (*str)[1] + 2;
}
void string_memory(){
long bottom = -1;
@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 ''
}
@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) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,viewport-fit=cover">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
@ioslh
ioslh / fake-database.js
Created February 18, 2019 08:37
Fake Database
const fs = require('fs')
class FakeDatabase {
constructor(dbPath) {
this._filePath = dbPath || './data.json'
this._data = JSON.parse(fs.readFileSync(this._filePath))
this._idBase = Math.max.apply(null, this._data.map(i => i.id))
}
_idGen() {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="//shadow.elemecdn.com/zcache/gl/god-dev/[email protected]/dist/perf.min.js"></script>
window.Lib = function(){
var h1 = document.createElement('h1')
h1.textContent = 'Hello World'
document.body.appendChild(h1)
}
window.Lib()
@ioslh
ioslh / test.c
Last active August 2, 2016 03:00
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Bugtags startWithAppKey:@"APP_KEY" invocationEvent:BTGInvocationEventBubble];
return YES;
}
define([
'jquery'
], function (
$
) {
var STARTED = false;
window.onload=function(){
var table=document.createElement("table");
for(var i=1;i<10;i++){
var tr=document.createElement("tr");
if(i%2==0){
tr.className="dark";
}else{
}
for(var j=1;j<i+1;j++){
var td=document.createElement("td");