Skip to content

Instantly share code, notes, and snippets.

View axetroy's full-sized avatar
💭
Get busy living or get busy dying

Axetroy axetroy

💭
Get busy living or get busy dying
View GitHub Profile
@axetroy
axetroy / str2color.js
Last active March 20, 2021 14:02
根据一个字符串,生成一个动态的hex颜色
var stringToColor = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var color = '#';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
color += ('00' + value.toString(16)).substr(-2);
}
@axetroy
axetroy / grid.scss
Created February 13, 2021 14:47
通用的 web app 原子类样式
.flex {
display: flex;
}
.row {
position: relative;
height: auto;
margin-right: 0;
margin-left: 0;
zoom: 1;
@axetroy
axetroy / BigFloat.ts
Created January 27, 2021 01:51
Big Float
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]
@axetroy
axetroy / reactive.js
Created December 4, 2020 16:51
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(),
},
{
@axetroy
axetroy / maximum-difference.js
Last active August 18, 2020 08:45
美团2016校招算法题-最大差值
/*
描述:
有一个长度为n的A,满足0<=a<=b<=n的A[b] - A[a]的最大值
给定数组A以及它的大小n,请返回最大差值
example:
[10, 5], 2
@axetroy
axetroy / index.ts
Created August 6, 2020 04:32
HTTP printer
type HTTPHeaders = { [key: string]: string | string[] };
interface HTTPResponse {
status: number;
headers: HTTPHeaders;
body: unknown;
}
class Printer {
#url!: string;
@axetroy
axetroy / README.md
Created December 1, 2019 10:27
卸载 xcode

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 October 2, 2019 08:17 — forked from hellokaton/README.md
Go 的信号处理和优雅退出

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

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

@axetroy
axetroy / pool.go
Created November 27, 2017 15:12
Golang资源池
package pool
type CreatorFunc func() (interface{}, error)
type DestroyerFunc func(resource interface{}) (interface{}, error)
type Pool struct {
config Config
options Options
pool []interface{}
}
@axetroy
axetroy / index.js
Last active May 16, 2019 02:41
基本版的 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);