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
@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
@samsm
samsm / scale.rake
Created November 29, 2011 15:51
"Auto" Scale Heroku Cedar instances with rake tasks
I think this is a nice option for apps that are mostly used during particular hours and aren't really ready
for a more intense auto-scaling thing. Hirefire (https://github.com/meskyanichi/hirefire) likely does a
lot more, but I didn't really understand how it worked and don't really need something that fancy right now.
I suspect it requires at least one worker itself, but I don't really know.
Add an API key to your app's Heroku config
heroku config:add HEROKU_API_KEY=your_key (from https://api.heroku.com/account )
Add the above rake task. Change 'YOUR-APPS-NAME' to indigo-butterfly-77 or whatever your app's name is.
@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"
@mbinna
mbinna / RunUnitTests.sh
Last active October 25, 2017 12:59
Run Xcode Application Tests from the command line
#!/bin/sh
# Launch application using ios-sim and set up environment to inject test bundle into application
# Source: http://stackoverflow.com/a/12682617/504494
if [ "$RUN_APPLICATION_TESTS_WITH_IOS_SIM" = "YES" ]; then
test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"
environment_args="--setenv DYLD_INSERT_LIBRARIES=/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection --setenv XCInjectBundle=$test_bundle_path --setenv XCInjectBundleInto=$TEST_HOST"
ios-sim launch $(dirname $TEST_HOST) $environment_args --args -SenTest All $test_bundle_path
echo "Finished running tests with ios-sim"
@bstahlhood
bstahlhood / UIImage+Retina4.h
Created September 13, 2012 00:51
Swizzled UIImage imageNamed for iPhone 5
//
// UIImage+Retina4.h
// StunOMatic
//
// Created by Benjamin Stahlhood on 9/12/12.
// Copyright (c) 2012 DS Media Labs. All rights reserved.
//
#import <UIKit/UIKit.h>
@alloy
alloy / Instructions.md
Created June 28, 2012 12:56
Run iOS unit tests (in a Xcode workspace) when a file changes and *only* those tests related to the changed file. Also trims otest output and colors test results.
@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)
@malclocke
malclocke / gist:943565
Created April 27, 2011 01:31 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' |
xargs git push origin --delete