Skip to content

Instantly share code, notes, and snippets.

View hungtcs's full-sized avatar

鸿则 hungtcs

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 00.md
Created August 19, 2022 07:34
广度优先 和 深度优先
  • BFS:广度优先搜索
  • DFS:深度优先搜索

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

namespace A {
  export interface Node {
    value: number,
@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 / examples.ts
Last active October 25, 2023 03:13
Simple JavaScript Sandbox
const parser = Sandbox.compile('a + b');
const result = parser({ a: 1, b: 2 });
// ---
const parser = Sandbox.compile('a + b + alert', { throwOnUndefined: true });
const result = parser({ a: 1, b: 2 });
@hungtcs
hungtcs / 重要步骤.md
Last active February 20, 2022 10:23
Raspberry Pi 3B install Lakka

重要步骤

中文UI

  1. 上传字体到 /storage/assets/xmb/retroactive/font.ttf
  2. systemctl stop retroarch
  3. vim ~/.config/retroarch/retroarch.cfg
  4. change video_font_path = /storage/assets/xmb/retroactive/font.ttf
  5. systemctl start retroarch
@hungtcs
hungtcs / sample.sh
Last active December 22, 2023 06:26
ffmpeg 录制屏幕
# Linux:录制当前显示器
# - show_region: 显示录制区域
# - framerate: 录制的帧率
# - video_size: 录制区域的大小
# - $DISPLAY+0,0: `$DISPLAY`:环境变量,当前显示器
# `+0,0` 录制区域偏移量
# x11grab: http://underpop.online.fr/f/ffmpeg/help/x11grab.htm.gz
ffmpeg -f x11grab -show_region 1 -framerate 8 -video_size 1024x768 -i $DISPLAY+0,0 -y output.mp4
# MacOS 录制屏幕