Skip to content

Instantly share code, notes, and snippets.

@tbxark
tbxark / difficulty.js
Last active February 25, 2025 13:05
ChatGPT IP 风险解析
function parseDifficulty(difficulty) {
const cleanDifficulty = difficulty.replace('0x', '').replace(/^0+/, '');
const hexLength = cleanDifficulty.length;
const hex2num = parseInt(cleanDifficulty, 16); // 将十六进制字符串转换为数字
if (hexLength <= 2) {
level = '(困难)';
qualityText = '高风险';
} else if (hexLength === 3) {
level = '(中等)';
@tbxark
tbxark / api.ts
Last active February 15, 2025 04:39
Sphere Dash Adapter
import { Api } from "@/api/dash/Api";
import { http } from "@/utils/http";
import type { AxiosInstance, AxiosResponse } from "axios";
import type { HttpClient } from "@/api/dash/http-client";
interface PureHTTP {
axiosInstance: AxiosInstance;
}
type UnwrapResponse<T> =
@tbxark
tbxark / tryCatch.js
Created January 24, 2025 01:07
Safe Assignment
function tryCatch(fn, ...args) {
try {
const result = fn.apply(null, args);
if (result.then) {
return new Promise(resolve => {
result
.then(v => resolve([undefined, v]))
.catch(e => resolve([e, undefined]))
});
@tbxark
tbxark / CustomButton.tsx
Created January 4, 2025 15:38
Define the properties of a custom button
import type { ComponentProps } from 'react';
interface CustomButtonProps {
onPress: ComponentProps<typeof TouchableOpacity>["onPress"];
title: string;
}
const CustomButton = ({ onPress, title }: CustomButtonProps) => (
<TouchableOpacity
onPress={onPress}
@tbxark
tbxark / update-go-bins.sh
Created November 22, 2024 04:16
Update go bin to the latest version
#!/bin/bash
if [[ -z "$GOPATH" ]]; then
export GOPATH=~/go
fi
for bin in $GOPATH/bin/*; do
if [[ -x "$bin" ]]; then
path=$(go version -m "$bin" | grep "^[[:space:]]*path" | awk '{print $2}')
if [[ "$path" == */* ]]; then
@tbxark
tbxark / a-clash-tproxy-gateway.md
Created September 19, 2024 02:17 — forked from phlinhng/a-clash-tproxy-gateway.md
Clash as transparent proxy gateway via TPROXY

Notes

  1. If your local network use public IP ranges instead of private ones, make sure to add respecive RETURN rules to iptables to prevent looping issue
  2. Set clash as DHCP's only DNS server to allow domain-based filter (shunting) rules work
  3. Use lsof -i udp:53 to check if clash's DNS module work fine, otherwise you may have to kill systemd-resolved and any other processes occupying the UDP 53 port
  4. The given scripts will NOT hangle the traffic of gateway itself since it is not recommend to do so. If you want to redirect the egress traffic of the gateway, the following material may be useful

Reference

@tbxark
tbxark / 伪元素.md
Created November 28, 2023 06:32
CSS笔记
伪元素 作用 使用场景 示例
::after 在元素内容之后插入内容 添加装饰性内容,如图标、边框 p::after { content: "★"; }
::before 在元素内容之前插入内容 添加装饰性内容,如图标、边框 p::before { content: "★"; }
::first-letter 选择第一个字母 首字下沉,字体样式变化 p::first-letter { font-size: 200%; }
::first-line 选择第一行文本 改变段落的第一行文本样式 p::first-line { color: blue; }
::selection 定制用户选中文本的样式 更改选中文本的颜色和背景 p::selection { color: white; background: black; }
::placeholder 定制输入字段的占位符文本样式 改变输入框占位符的样式 input::placeholder { color: grey; }
::marker 定制列表项标记的样式 改变列表项目符号的样式 li::marker { color: red; }
/// https://developers.cloudflare.com/workers/
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// https://example.com/author/repo/name.podspec?xxx=xxx
const url = new URL(request.url)
const [, author, repo, name] = url.pathname.split(/[\./]/g)
@tbxark
tbxark / CenterAlignmentFlowLayout.swift
Created August 21, 2017 04:29
CenterAlignmentFlowLayout
//
// CenterAlignmentFlowLayout.swift
// Play
//
// Created by Tbxark on 15/12/28.
// Copyright © 2015年 TBXark. All rights reserved.
//
import UIKit
@tbxark
tbxark / Find all locations of substring in NSString
Last active November 20, 2016 16:14
Find all locations of substring in NSString
extension NSString {
func rangesOfSubString(_ string: String) -> [NSRange] {
var searchRange = NSMakeRange(0, length)
var searchResult = [NSRange]()
while searchRange.location < length {
searchRange.length = length - searchRange.location
let foundRange = range(of: string, options: [], range: searchRange)
if foundRange.location != NSNotFound {
searchResult.append(foundRange)
searchRange.location = foundRange.location+foundRange.length