Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Get busy living or get busy dying

艾斯特洛 axetroy

💭
Get busy living or get busy dying
View GitHub Profile
@axetroy
axetroy / glob2regexp.js
Last active Apr 9, 2021
Glob string transform to javascript RegExp
View glob2regexp.js
function glob2regexp(glob) {
const prefix = "^/?(.*/)*";
const suffix = "$";
const content = glob
.replace(/\./g, ".")
.replace(/\*{2,}/, "**")
.replace(/\*{1,}\/?/g, function (match, b, c, d) {
const matchSlash = match[match.length - 1] === "/";
match = !matchSlash ? match : match.substr(0, match.length - 1);
@axetroy
axetroy / grid.scss
Created Feb 13, 2021
通用的 web app 原子类样式
View grid.scss
.flex {
display: flex;
}
.row {
position: relative;
height: auto;
margin-right: 0;
margin-left: 0;
zoom: 1;
View BigFloat.ts
type Numeric = number | string | BigInt
function getType(o: unknown): string {
const matcher = Object.prototype.toString.call(o).match(/\s(\w+)/)
if (!matcher) {
return ''
}
return matcher[1]
View reactive.js
function reactive(val) {
const isPrimitive =
val instanceof Number || val instanceof String || val instanceof Boolean;
return new Proxy(
{
[Symbol.toPrimitive]: () => val,
valueOf: () => val.valueOf(),
toString: () => val.toString(),
},
{
View index.ts
type HTTPHeaders = { [key: string]: string | string[] };
interface HTTPResponse {
status: number;
headers: HTTPHeaders;
body: unknown;
}
class Printer {
#url!: string;
View README.md

xcode 太庞大,而我又用不到 xcode,只能卸载

在卸载 xcode 之后 Git 命令不起作用了

$ git
xcrun: error: active developer path 
("/Applications/Xcode.app/Contents/Developer") 
does not exist, use `xcode-select --switch path/to/Xcode.app` 
to specify the Xcode that you wish to use for command line 
@axetroy
axetroy / README.md
Created Oct 2, 2019 — forked from biezhi/README.md
Go 的信号处理和优雅退出
View README.md

每个平台的信号定义或许有些不同。下面列出了POSIX中定义的信号。 Linux 使用34-64信号用作实时系统中。 命令man 7 signal提供了官方的信号介绍。

在POSIX.1-1990标准中定义的信号列表

@axetroy
axetroy / README.md
Created Dec 17, 2018
Mac上的优化,提升文件打开数/连接数
View README.md
$ echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
$ echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -w kern.maxfiles=65536
$ sudo sysctl -w kern.maxfilesperproc=65536
$ ulimit -n 65536
@axetroy
axetroy / index.ts
Last active May 25, 2018
基于角色的访问控制
View index.ts
interface User {
username: string;
roles: string[];
}
interface Role {
name: string;
desc: string;
permission: Permission[];
}
@axetroy
axetroy / index.js
Last active May 16, 2019
基本版的 JS 解析器
View index.js
const babylon = require("babylon");
const types = require("babel-types");
const visitors = {
File(node, scope) {
evaluate(node.program, scope);
},
Program(program, scope) {
for (const node of program.body) {
evaluate(node, scope);