Skip to content

Instantly share code, notes, and snippets.

View GenoZhou's full-sized avatar

Hanxuan Zhou GenoZhou

View GitHub Profile
@GenoZhou
GenoZhou / UIView+AutoLayout.swift
Last active November 24, 2017 10:41
Swift 4 UIView Autolayout extensions.
extension UIView {
@discardableResult
public func constrainEdges(to view: UIView) -> [NSLayoutConstraint] {
let constraints = [
leadingAnchor.constraint(equalTo: view.leadingAnchor),
topAnchor.constraint(equalTo: view.topAnchor),
trailingAnchor.constraint(equalTo: view.trailingAnchor),
bottomAnchor.constraint(equalTo: view.bottomAnchor)
]
NSLayoutConstraint.activate(constraints)
@GenoZhou
GenoZhou / UIView.swift
Last active November 5, 2017 15:34
Swift 4 UIView extensions.
extension UIView {
public func addSubviews(_ subviews: [UIView], tAMIC: Bool = false) {
for subview in subviews {
addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
}
}
}
@GenoZhou
GenoZhou / UITableView.swift
Created November 5, 2017 15:34
Swift 4 UITableView extensions.
public protocol ReusableView: class { }
extension ReusableView where Self: UIView {
public static var reuseIdentifier: String {
return String(describing: self)
}
}
extension UITableViewCell: ReusableView { }
extension UITableViewHeaderFooterView: ReusableView { }
@GenoZhou
GenoZhou / obsidian-web-clipper.js
Last active December 12, 2023 14:17 — forked from kepano/obsidian-web-clipper.js
Obsidian Web Clipper Bookmarklet to save articles and pages from the web (for Safari, Chrome, Firefox, and mobile browsers)
javascript: Promise.all([import('https://unpkg.com/[email protected]?module'), import('https://unpkg.com/@tehshrike/[email protected]'), ]).then(async ([{
default: Turndown
}, {
default: Readability
}]) => {
/* Optional vault name */
const vault = "";
/* Optional folder name such as "Clippings/" */
@GenoZhou
GenoZhou / mac_power_monitor.py
Created December 26, 2025 06:48
Mac Power Monitor
#!/usr/bin/env python3
"""
Mac Power Monitor - Real-time power consumption dashboard for macOS
Features:
- Dynamic power detection (supports any charger wattage)
- Hardware telemetry: CPU/GPU/ANE (measured), Memory/Storage/Network/Screen (estimated)
- Application power analysis with proportional allocation
- Smart battery status detection (optimized charging, insufficient power warnings)
- Cross-validation using multiple data sources (ioreg, powermetrics, system_profiler)