Skip to content

Instantly share code, notes, and snippets.

View subdigital's full-sized avatar

Ben Scheirman subdigital

View GitHub Profile
@interface UIView (LayoutConvenience)
- (NSLayoutConstraint *)constraintAligningAttribute:(NSLayoutAttribute)attr withView:(UIView *)otherView;
@end
@implementation UIView (LayoutConvenience)
- (NSLayoutConstraint *)constraintAligningAttribute:(NSLayoutAttribute)attr withView:(UIView *)otherView {
return [NSLayoutConstraint constraintWithItem:self attribute:attr relatedBy:NSLayoutRelationEqual toItem:otherView attribute:attr multiplier:1.0 constant:0.0];
}
@end
@liscio
liscio / retinaify.sh
Created March 12, 2015 18:33
Make Preview open your @2x .png files as if they are retina images
#!/bin/sh
# First, set the width/height DPI on the file
sips -s dpiWidth 144 -s dpiHeight 144 "$1"
# Fake that it is a screen capture (wat?)
xattr -wx com.apple.metadata:kMDItemIsScreenCapture "62 70 6C 69 73 74 30 30 09 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09" "$1"
xattr -wx com.apple.metadata:kMDItemScreenCaptureType "62 70 6C 69 73 74 30 30 59 73 65 6C 65 63 74 69 6F 6E 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12" "$1"
xattr -wx com.apple.FinderInfo "00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" "$1"
@Vestride
Vestride / encoding-video.md
Last active June 5, 2024 14:38
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@norio-nomura
norio-nomura / add_path_to_swift-build.sh
Last active March 24, 2016 16:31
Fix "dyld: Library not loaded: @rpath/libswiftCore.dylib" on swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a
sudo install_name_tool -add_rpath @executable_path/../lib/swift/macosx /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a.xctoolchain/usr/bin/swift-build
sudo install_name_tool -add_rpath @executable_path/../lib/swift/macosx /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-16-a.xctoolchain/usr/bin/swift-test
// 1. Implement URLSession:task:didReceiveChallenge:completionHandler:. (Be sure to call the completion handler with NSURLSessionAuthChallengeDisposition.PerformDefaultHandling and a nil NSURLCredential.)
// 2. Set a breakpoint in the callback + trigger an authentication challenge at runtime
// 3. In the debugger, inspect the callback's `challenge.protectionSpace` argument for the values to put in the following lines of code...
// 4. Put the following lines of code somewhere before your network requests (i.e. AppDelegate area, or other)
let basicAuthCredentials = NSURLCredential(user: "username", password: "password", persistence: .Permanent)
let foobarHttpsProtectionSpace = NSURLProtectionSpace(host: "foo.bar.com", port: 443, protocol: "https", realm: "This Probably Has A Value, Get It From The Delegate Callback", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
NSURLCredentialStorage.sharedCredentialStorage().setDefaultCredential(basicAuthCredentials, forProtectionSpace: apidevHttpsProtectionSpace
@vzsg
vzsg / 1_Fetch.swift
Last active June 25, 2021 10:37
A solution for the N+1 problem when fetching children for parents (Fluent 3)
import Fluent
func fetchChildren<Parent, ParentID, Child: Model, Result>(
of parents: [Parent],
idKey: KeyPath<Parent, ParentID?>,
via reference: KeyPath<Child, ParentID>,
on conn: DatabaseConnectable,
combining: @escaping (Parent, [Child]) -> Result) -> Future<[Result]> where ParentID: Hashable & Encodable {
let parentIDs = parents.compactMap { $0[keyPath: idKey] }
let children = Child.query(on: conn)
@4np
4np / HowTo use xcconfig or plist with SPM.md
Last active January 25, 2024 22:20
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig