Skip to content

Instantly share code, notes, and snippets.

View e7h4n's full-sized avatar
🎯
Focusing

Ethan Zhang e7h4n

🎯
Focusing
View GitHub Profile
@e7h4n
e7h4n / mobx.test.ts
Created September 20, 2024 08:05
mobx + abortSignal 的一点点例子
// 这个测试里我们用 mobx 来建立一个应用程序
// 这个程序中,当 dialog 的 show 状态变为 true 时,我们开启一个定时器
// 这个定时器每秒给一个全局自增 counter+1
// 当 dialog 的状态变为 false 时,我们重置这个全局定时器
// 在这个例子中,所有的清理工作都应该用 transaction / abortSignal 来完成,而不是调用方主动重置
import { afterEach, beforeEach, expect, test, vi } from "vitest";
import { makeAutoObservable, reaction } from "mobx"
import { interval } from "signal-timers";
import { transaction } from "signal-transaction";
@e7h4n
e7h4n / README.md
Created November 3, 2023 02:49
管理 Beancount 的 Receivables 账户

基本规则

  • Receivable 账户意味着别人应该给你钱,比如购物退货之后等待退款、借给别人钱等等。例如
2023-10-31 * "淘宝" “[退货] 表带"
    Liabilities:CreditCard:CMB                                 -83.00 CNY
    Assets:Receivables
// 业务方法定义
const getA = function(cb) {
cb(a);
}
const getB = function(a, cb) {
cb(b);
}
const getC = function(a, b, cb) {
@e7h4n
e7h4n / loading.pipe.ts
Created March 24, 2017 13:22
Get a loading state of a Observable or Promise
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform, ɵisObservable, ɵisPromise } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
interface SubscriptionStrategy {
createSubscription(async: any, updateLatestValue: any): any;
dispose(subscription: any): void;

title: Node Web 服务平滑升级 date: 2014-06-22 11:33:12 tags: node

用 Node 搭建一个 Web 服务是一件很轻松的事情,例如经典的 Hello World 例子,三行代码实现一个 Web 服务:

require('http').createServer(function (req, res) {
 res.end('Hello World');
var ignoreRegexp = ['/^\\/?(?=/|$)/i', '/^(.*)\\/?$/i', '/^\\/ss\\/?(?=/|$)/i'];
var routerProto = express.Router().__proto__;
var regexpList = app._router.stack.reduce(function findProto(memo, curr) {
if (ignoreRegexp.indexOf(curr.regexp.toString()) === -1) {
memo.push(curr.regexp);
}
if (curr.handle.__proto__ === routerProto && curr.handle.stack) {
memo = curr.handle.stack.reduce(findProto, memo);
}
function qs(arr) {
if (!arr || !arr.length) {
return [];
}
var split = arr.pop();
return qs(arr.filter(function (item) { return item <= split; }))
.concat([split])
.concat(qs(arr.filter(function (item) { return item > split; })));
}
(function (window) {
// prng4.js - uses Arcfour as a PRNG
function Arcfour() {
this.i = 0;
this.j = 0;
this.S = new Array();
}
// Initialize arcfour context from key, an array of ints, each from [0..255]
# Web App 实践经验
var files = fileEl.files;
var formData = new FormData();
_.toArray(files).forEach(function (file) {
formData.append('images[]', file);
});
var xhr = new XMLHttpRequest();
xhr.open('post', '/uni/api/' + $routeParams.course + '/images', true);