Skip to content

Instantly share code, notes, and snippets.

View pronebird's full-sized avatar

Andrej Mihajlov pronebird

View GitHub Profile
@pronebird
pronebird / print-struct-byte-by-byte.rs
Created March 4, 2024 12:45
Print rust struct byte by byte
unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
::core::slice::from_raw_parts(
(p as *const T) as *const u8,
::core::mem::size_of::<T>(),
)
}
let bytes: &[u8] = unsafe { any_as_u8_slice(&req) };
for byte in bytes {
print!("{:02x} ", byte);
@pronebird
pronebird / NSAttributedString+BasicMarkdown.swift
Last active May 26, 2023 12:36
Basic markdown support for attributed string
import UIKit
import PlaygroundSupport
extension NSAttributedString {
enum MarkdownElement {
case paragraph, bold
}
struct MarkdownStylingOptions {
var font: UIFont
@pronebird
pronebird / NENWPath+Private.swift
Created March 2, 2023 10:56
NetworkExtension NWPath private extension to obtain interface name
import NetworkExtension
extension NetworkExtension.NWPath {
var interfaceName: String? {
let interface = self.value(forKeyPath: "_internalPath.direct") as? nw_interface_t
return interface.map { String(cString: nw_interface_get_name($0)) }
}
}
@pronebird
pronebird / UIPresentationController+Private.swift
Created January 19, 2023 11:29
Private notifications posted by UIPresentationController
extension UIPresentationController {
static let presentationTransitionWillBegin = Notification.Name(
"UIPresentationControllerPresentationTransitionWillBeginNotification"
)
static let presentationTransitionDidEndNotification = Notification.Name(
"UIPresentationControllerPresentationTransitionDidEndNotification"
)
static let dismissalTransitionWillBeginNotification = Notification.Name(
@pronebird
pronebird / FormsheetPresentationController.swift
Last active August 30, 2022 07:37
Custom formsheet presentation
class FormsheetPresentationController: UIPresentationController {
private static let dimmingViewOpacityWhenPresented = 0.5
private var isPresented = false
private let dimmingView: UIView = {
let dimmingView = UIView()
dimmingView.backgroundColor = .black
return dimmingView
}()
@pronebird
pronebird / bulk-convert-video.sh
Last active January 12, 2024 18:50
Convert videos in bulk to H264 baseline/YUV420p, preserve metadata and sanitize filenames
caffeinate &
CAFFEINATE_PID=$!
for FILE in *.mkv; do
OUTPUT=$(echo $FILE | sed -r "s/[ ]*[\.-\(]?(480p|720p|1080p|WEB|576p|HDTV|Xvid).*(\.[a-z4]+)$/\2/I")
if [ "$OUTPUT" = "$FILE" ]; then
OUTPUT=$(echo $OUTPUT | sed -r "s/(\.[a-z4]+)$/.converted\1/I")
fi
@pronebird
pronebird / UnfairLock.swift
Created March 2, 2022 12:56
Wrapper type for os_unfair_lock
class UnfairLock: NSLocking {
private var _lock = os_unfair_lock()
func lock() {
os_unfair_lock_lock(&_lock)
}
func unlock() {
os_unfair_lock_unlock(&_lock)
}
@pronebird
pronebird / apple-fomat-regex.txt
Last active October 1, 2021 12:53
Regex for parsing sprintf style format with Apple privacy extensions
# Ignore escape sequences %%
(?<!%)
# Match %
%
# Match extended attributes supported by OSLog, ie: {public, uuid_t}
# See https://developer.apple.com/documentation/os/logging for built-in value decoders
(?:\{([\w-,\s]+)\}){0,1}
@pronebird
pronebird / redux_v3.x.x.js
Last active July 25, 2017 18:17
Patch that adds Dispatch parameter to redux interface
// flow-typed signature: 7f1a115f75043c44385071ea3f33c586
// flow-typed version: 358375125e/redux_v3.x.x/flow_>=v0.33.x
declare module 'redux' {
/*
S = State
A = Action
D = Dispatch
@pronebird
pronebird / CLLocationCoordinate2D+Encodable.swift
Created July 4, 2017 09:46
Encode CLLocationCoordinate2D with Codable in Swift 4
import CoreLocation
extension CLLocationCoordinate2D: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(longitude)
try container.encode(latitude)
}