Skip to content

Instantly share code, notes, and snippets.

View avaidyam's full-sized avatar

Aditya Vaidyam avaidyam

View GitHub Profile
#!/bin/bash
mkdir -p "$1_8mb"
cd $1
for x in *.mp4; do
newname=${x/mp4/8mb.mp4}
# if [[ "../$1_8mb/$newname" exists then skip ]]
/opt/homebrew/bin/ffmpeg -i "$x" -c:a copy -c:v libx264 -crf 35 -vf scale=1280:720 "../$1_8mb/$newname"
/opt/homebrew/bin/exiftool "-AllDates<Filename" "-FileCreateDate<Filename" "-FileModifyDate<Filename" -overwrite_original_in_place "../$1_8mb/$newname"
done
@avaidyam
avaidyam / BackdropView.swift
Created July 2, 2020 17:23
DIY NSVisualEffectView using Private API for macOS
// TODO: setting window transforms (or mission control) flattens layers...
// TODO: Mask image vs path (layer)?
/// `NSVisualEffectView`:
///
/// A view that adds translucency and vibrancy effects to the views in your interface.
/// When you want views to be more prominent in your interface, place them in a
/// backdrop view. The backdrop view is partially transparent, allowing some of
/// the underlying content to show through. Typically, you use a backdrop view
/// to blur background content, instead of obscuring it completely. It can also
@avaidyam
avaidyam / animate_dark.swift
Last active February 11, 2022 14:20
Animated dark mode transition
// swiftc this file & mv to /usr/local/bin
import Cocoa
typealias NSGlobalPreferenceTransitionBlock = @convention(block) () -> Void
@objc protocol NSGlobalPreferenceTransitionProtocol: NSObjectProtocol {
static func transition() -> AnyObject
func waitForTransitionWithCompletionHandler(_ arg1: @escaping NSGlobalPreferenceTransitionBlock)
func postChangeNotification(_ arg1: UInt64, completionHandler arg2: @escaping NSGlobalPreferenceTransitionBlock)
}
let NSGlobalPreferenceTransition: AnyClass = NSClassFromString("NSGlobalPreferenceTransition")!
@avaidyam
avaidyam / runtime-class.m
Created March 11, 2018 19:53
An attempt at creating a subclass of an unknown/hidden NSProxy type.
func test() {
// Allocate a new class-pair from an unknown superclass type.
let selector = Selector(("doStuff"))
let oldClass_: AnyClass = Something.self
let newClass_: AnyClass = objc_allocateClassPair(NSClassFromString("_NSObjectAnimator"), "MyNewClass", 0)!
// Copy instance and class methods over.
let m = class_getInstanceMethod(oldClass_, selector)!
class_addMethod(newClass_, selector, method_getImplementation(m), method_getTypeEncoding(m))
@avaidyam
avaidyam / RegisterEventHotKey.c
Created March 10, 2018 02:08
The decompiled and cleaned source for RegisterEventHotKey and SCRKeyboardRegisterForHotKeysWithConnection.
class HotInputDataUnknown1 {
0x4
0x8
0x10
}
class HotInputData {
UInt32 unknown; // + 0x0
UInt32 modifiers; // + 0x4
UInt32 keyCode; // + 0x8
@avaidyam
avaidyam / Example.m
Last active February 26, 2018 00:56
Automatically map between an NSObject and a dictionary representation, including custom properties and excluding cyclic ones.
@implementation ExampleClass
+ (void)load {
NSArray *ignoreList = [NSArray arrayWithObjects:
[[NSIgnoredClassKey alloc] initWithClassName:@"GPBOneofDescriptor" key:@"containingOneof"],
nil];
NSArray *includeList = [NSArray arrayWithObjects:
[[NSIncludedClassKey alloc] initWithClassName:@"GPBEnumDescriptor" key:@"namedValues" block:^(id obj)
{
#pragma clang diagnostic push
@avaidyam
avaidyam / async.swift
Created January 29, 2018 04:10
Swift (naive) partial application for async functions
import Dispatch
/// Manages async state for a function from its exterior.
fileprivate final class AsyncSlot<T> {
private let semaphore = DispatchSemaphore(value: 0)
private var value: T! = nil
fileprivate func fill(_ value: T) {
self.value = value
self.semaphore.signal()
@avaidyam
avaidyam / people_pa.js
Created January 15, 2018 04:04
Google People API v2 (Internal) Reference
{
kind: "discovery#restDescription",
name: "people_pa",
version: "v2",
rootUrl: "https://people-pa.googleapis.com/",
servicePath: "",
batchPath: "batch",
id: "people_pa:v2",
parameters: {
"$.xgafv": {
@avaidyam
avaidyam / Animatable.swift
Created August 22, 2017 00:09
A quick test of a declarative? animation interface.
import Cocoa
import QuartzCore
// CAMediaTiming stuff?
// custom interps?
// isAdditive, isCumulative, timingFunction
// auto-fill-forward without keeping anim
// auto-fill-backward before start of anim
// delegate + removedOnCompletion ignored in groups...
// - use CACurrentMediaTime() and beginTime offset for everything
@avaidyam
avaidyam / KeyValueCoderTests.swift
Last active May 29, 2021 13:46
Key-Value Encoding in Swift 4
import Foundation
import XCTest
class TestKeyValueEncoder : XCTestCase {
func testEncodingTopLevelEmptyStruct() {
let empty = EmptyStruct()
_testRoundTrip(of: empty)
}