Skip to content

Instantly share code, notes, and snippets.

View HsiangHo's full-sized avatar
🐒
黑神话: 悟空

Xiang He HsiangHo

🐒
黑神话: 悟空
View GitHub Profile
@nealfennimore
nealfennimore / wireguard.conf
Last active January 4, 2026 02:36
Wireguard VPN - Forward all traffic to server
# ------------------------------------------------
# Config files are located in /etc/wireguard/wg0
# ------------------------------------------------
# ---------- Server Config ----------
[Interface]
Address = 10.10.0.1/24 # IPV4 CIDR
Address = fd86:ea04:1111::1/64 # IPV6 CIDR
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # Add forwarding when VPN is started
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE # Remove forwarding when VPN is shutdown
@iccir
iccir / openScreenRecordingPreferences.m
Created October 13, 2019 09:21
Open "Screen Recording" preferences on macOS Catalina
static void sOpenScreenRecordingPreferences()
{
CFDataRef passThruData = CFBridgingRetain([@"Privacy_ScreenCapture" dataUsingEncoding:NSUTF8StringEncoding]);
CFArrayRef itemURLs = CFBridgingRetain(@[ [NSURL fileURLWithPath:@"/System/Library/PreferencePanes/Security.prefPane"] ]);
OSStatus err = noErr;
AEDesc passThruDesc = {0};
BOOL needsDispose = NO;
// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
class Model: ObservableObject {
@Published var minimumContainer = true
@Published var extendedTouchBar = false
@Published var twoPhases = true
@vorce
vorce / jerry.swift
Last active May 11, 2025 06:07
Mouse move and click test thing for macos in swift
import Cocoa
import Foundation
// Move around and click automatically at random places in macos, kinda human like in a cheap way.
// Moves the mouse pointer to `moves` random locations on the screen and runs the `action` function at
// each point with the point as argument.
func mouseMoveWithAction(moves: Int, action: (CGPoint) -> Void = defaultAction) {
let screenSize = NSScreen.main?.visibleFrame.size
@dnedrow
dnedrow / version_comparator.sh
Last active November 18, 2020 12:21
bash function for comparing version numbers
#!/usr/bin/env bash
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" > "$1"; }
function version_eq() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; }
function version_lt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" < "$1"; }
RUBY_VERSION=$(/usr/bin/ruby -v | awk '{print $2}' | cut -d'p' -f1)
echo "ruby version is ${RUBY_VERSION}"
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@insidegui
insidegui / WebCacheCleaner.swift
Created September 14, 2016 23:12
Clear WKWebView's cookies and website data storage, very useful during development.
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
@subharanjanm
subharanjanm / clamav-mac.md
Created August 30, 2016 14:16 — forked from dkobia/clamav-mac.md
Get ClamAV running on Mac OS X (using Homebrew)

Get ClamAV running on Mac OS X (using Homebrew)

The easiest way to get the ClamAV package is using Homebrew

$ brew install clamav

Before trying to start the clamd process, you'll need a copy of the ClamAV databases.

Create a freshclam.conf file and configure as so

static func make(withKeychainItem keychainItem: SecKeychainItem) -> Credentials? {
var attributeTags = [SecItemAttr.accountItemAttr.rawValue]
var formatConstants = [UInt32(CSSM_DB_ATTRIBUTE_FORMAT_STRING)]
var attributeInfo = SecKeychainAttributeInfo(count: 1, tag: &attributeTags, format: &formatConstants)
var attributeList: UnsafeMutablePointer<SecKeychainAttributeList>? = nil
var passwordLength: UInt32 = 0
var passwordPointer: UnsafeMutablePointer<Void>? = nil
let status = SecKeychainItemCopyAttributesAndData(keychainItem,
@takuoka
takuoka / AutoGrowingTextField.swift
Last active January 18, 2022 13:02
Example of an NSTextField that expands its height automatically. https://github.com/DouglasHeriot/AutoGrowingNSTextField
import Cocoa
// https://github.com/DouglasHeriot/AutoGrowingNSTextField
// for AutoLayout
class AutoGrowingTextField: NSTextField {
var minHeight: CGFloat? = 100