Skip to content

Instantly share code, notes, and snippets.

function FindProxyForURL(url, host) {
// Bypass localhost and local network addresses
if (
shExpMatch(host, "localhost") ||
shExpMatch(host, "*.local") ||
isInNet(host, "127.0.0.0", "255.0.0.0") ||
isInNet(host, "10.0.0.0", "255.0.0.0") ||
isInNet(host, "172.16.0.0", "255.240.0.0") ||
isInNet(host, "192.168.0.0", "255.255.0.0")
) {
async function generateKeysAndId() {
const keyPair = await crypto.subtle.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: "SHA-256",
},
true,
["sign", "verify"]
function getLogger(prefix: string, time = false): Console {
return new Proxy(console, {
get(target, prop) {
if (typeof target[prop] === 'function') {
return function(...args) {
return target[prop](`[${prefix} ${time ? new Date().toISOString() : ''}]`, ...args);
};
}
return target[prop];
}
import { readonly, ref } from 'vue'
import type { Ref } from 'vue'
type StoreItem<N extends string, T> = {
readonly [K in N]: Readonly<Ref<T>>
} & {
readonly [K in `set${Capitalize<N>}`]: (value: T) => void
}
@victor141516
victor141516 / generate_image.sh
Created May 9, 2025 09:01
Generate image using gpt-image-1
function generate_image() {
output_filename="image-$(date +%s).png"
image_prompt=$(echo $1 | jq -R)
gpt_response=$(curl -s https://api.openai.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-image-1",
"prompt": '$image_prompt',
@victor141516
victor141516 / uuidv4.js
Created May 2, 2025 19:20
Generate UUIDv4
export default () => {
const u = [...crypto.getRandomValues(new Uint8Array(16))]
u[6] = (u[6] & 0x0f) | 0x40
u[8] = (u[8] & 0x0f) | 0x80
return u
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
.replace(/^(.{8})(.{4})(.{4})(.{4})/, '$1-$2-$3-$4-')
}
/**
* Asserts that a value is of a specific type.
* If the assertion fails, an error is thrown.
*
* @param value The value to type check (used only in type signature)
* @param checker A function that returns true if the value is of the expected type
* @param message Optional custom error message
* @throws Error if the checker returns false
*/
export function assert<T>(
rclone mount ^
--vfs-cache-mode full ^
--vfs-cache-max-age 24h ^
--vfs-cache-max-size 10G ^
--buffer-size 256M ^
--vfs-read-ahead 512M ^
--vfs-read-chunk-size 32M ^
--vfs-read-chunk-size-limit 256M ^
--allow-other ^
--dir-cache-time 24h ^
@victor141516
victor141516 / useUrl.ts
Created December 16, 2024 08:45
Vue composable for URL editing
import { onMounted, onUnmounted, Ref, ref, watch } from 'vue'
class ReactiveURL {
hash: string
host: string
hostname: string
href: string
pathname: string
port: string
protocol: string
@victor141516
victor141516 / zzz-change-display.ps1
Created November 6, 2024 20:10
sunshine display screen
param (
[Parameter(Mandatory=$true)][string]$status
)
$isOnStart=$true
if ($status -eq "start") {
$isOnStart=$true
} elseif ($status -eq "end") {
$isOnStart=$false