Skip to content

Instantly share code, notes, and snippets.

View hungtcs's full-sized avatar

鸿则 hungtcs

View GitHub Profile
@hungtcs
hungtcs / 00.md
Created August 17, 2022 02:49
SSH 使用 HTTP 代理的配置方式
  1. 安装 corkscrew 软件,mac 系统可以直接使用 brew 安装

    brew search corkscrew
    brew install corkscrew
  2. 配置 ssh,编辑 ~/.ssh/config 文件,添加 ProxyCommand 配置

@hungtcs
hungtcs / 00.md
Created August 19, 2022 07:34
广度优先 和 深度优先
  • BFS:广度优先搜索
  • DFS:深度优先搜索

BFS 的重点在于队列,而 DFS 的重点在于递归。

namespace A {
  export interface Node {
    value: number,
@hungtcs
hungtcs / 01.md
Last active September 5, 2022 10:11
Mac OS 通过 CLI 对系统进行控制

深色模式

切换深色模式

tell application "System Events"
    tell appearance preferences
        set dark mode to not dark mode
    end tell
end tell
@hungtcs
hungtcs / context-menu-trigger.directive.ts
Created September 30, 2022 07:45
Angular material menu as context-menu
import { MatMenuPanel, _MatMenuTriggerBase } from '@angular/material/menu';
import { Directive, ElementRef, HostListener, Input, OnInit } from '@angular/core';
@Directive({
selector: '[contextMenuTriggerFor]',
})
export class ContextMenuTriggerDirective extends _MatMenuTriggerBase implements OnInit {
private readonly anchorElement = document.createElement('div');
@Input('contextMenuTriggerFor')
@hungtcs
hungtcs / bubble-sort.ts
Last active June 8, 2023 02:26
一些常用算法的实现
export function bubbleSort<T>(list: Array<T>, compare: (a: T, b: T) => number) {
for(let i = 0, len = list.length; i < len - 1; i++) {
for (let j = 0; j < len - 1 - i; j ++) {
const a = list[j];
const b = list[j + 1];
if (compare(a, b) > 0) {
list[j] = b;
list[j + 1] = a;
}
}
@hungtcs
hungtcs / bit-reader.ts
Last active October 25, 2023 09:34
这个工具类从 ArrayBuffer 中读取指定长度的 bits,并在增加内部偏移。受限于 JS 的数据类型,length 的值不能超过30,如果需要支持更大的数据类型,可以将数值类型改为 BigInt。
export class BitReader {
private offset: number = 0;
private bitOffset: number = 0;
private uint8Array: Uint8Array;
constructor(buffer: ArrayBuffer) {
this.uint8Array = new Uint8Array(buffer);
}
public read(length: number): number {
@hungtcs
hungtcs / 00.sql
Created October 24, 2023 03:36
Postgres 数据库、schema、table 大小获取方式
-- 数据库大小
select pg_size_pretty(pg_database_size(current_database()));
-- 只计算table size
select schemaname, pg_size_pretty(sum(pg_relation_size(schemaname || '.' || tablename))) from pg_tables group by schemaname;
@hungtcs
hungtcs / emojis.json
Created October 25, 2023 03:11
Unicode Emojis Collection
[
{
"name": "smileys_and_people",
"emojis": [
{
"emoji": "😀",
"unicode": "U+1F600",
"shortcode": ":grinning_face:"
},
{
@hungtcs
hungtcs / 00.html
Last active October 26, 2023 09:36
Show fallback image when image loading fails
<object data="path/to/image-00.png" type="image/png">
<img src="path/to/fallback.png" />
</object>
<!-- why not this -->
<img src="path/to/image-00.png" onerror="this.src = 'path/to/fallback.png'" />
<!-- 1. object is a pure html solution and does not require js. -->
<!-- 2. if the backup image fails to load, there is a risk of an infinite loop -->
<!-- 3. however, the object tag has a larger overhead -->
@hungtcs
hungtcs / Expr.g4
Last active December 13, 2023 06:06
搜索过滤表达式匹配
grammar Expr;
fragment ESC: '\\' .;
fragment DIGIT: [0-9];
WS: [ \t\r\n]+ -> skip;
COMMA: ',';
EXCLUDE: '-';
KEYWORLD: ~[ \t\r\n:,-]+;