Skip to content

Instantly share code, notes, and snippets.

@mbehan
mbehan / increment-build-number.sh
Created April 23, 2014 13:37
Add as a pre compile build phase in Xcode to auto increment your build number (bundle version). Format is revHash.user.number
last_commit=$(git rev-parse --short HEAD)$([[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "*")
CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNum=${CFBundleVersion##*.}
buildNum=$((buildNum + 1))
CFBundleVersion=$last_commit"."$USER"."buildNum
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$INFOPLIST_FILE"
@mbehan
mbehan / build-uploader.sh
Last active May 19, 2016 07:56
Uploads builds produced by Xcode bots
#!/bin/bash
files=/ci_scripts/*.plist
for f in $files
do
echo Processing $f "..."
productName="$(/usr/libexec/plistbuddy -c Print:ProductName: "$f")"
echo $productName
@zoul
zoul / UIImage+ForceLoad.m
Created September 14, 2010 07:06
Forces UIImage to load and decode its data
@implementation UIImage (ForceLoading)
- (void) forceLoad
{
const CGImageRef cgImage = [self CGImage];
const int width = CGImageGetWidth(cgImage);
const int height = CGImageGetHeight(cgImage);
const CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
extension UIControl.Event: Hashable{
public var hashValue: Int{
return Int(self.rawValue)
}
static func == (lhs: UIControl.Event, rhs: UIControl.Event) -> Bool{
return lhs.rawValue == rhs.rawValue
}
}
@zoul
zoul / AVAssetExportSession+Testing.m
Created November 8, 2010 08:35
Export assets synchronously. Good for testing.
@implementation AVAssetExportSession (Testing)
- (void) exportSynchronously
{
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[self exportAsynchronouslyWithCompletionHandler:^{
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(semaphore);
@mbehan
mbehan / ForcePanGestureRecognizer.swift
Created November 11, 2016 23:11
A UIPanGestureRecognizer subclass to get the force of the gesture's touch (assumes a single touch)
import UIKit.UIGestureRecognizerSubclass
class ForcePanGestureRecognizer : UIPanGestureRecognizer {
private(set) var force = CGFloat(0) {
didSet {
if force > maxForce {
maxForce = force
}
}
@hatfinch
hatfinch / CGAffineTransformFromRectToRect.m
Created August 17, 2011 09:54
CGAffineTransformFromRectToRect (not working)
CGAffineTransform CGAffineTransformFromRectToRect(CGRect fromRect, CGRect toRect)
{
CGSize scale = CGSizeMake(toRect.size.width / fromRect.size.width, toRect.size.height / fromRect.size.height);
CGRect scaledFromRect = CGRectMake(fromRect.origin.x * scale.width, fromRect.origin.y * scale.height,
fromRect.size.width * scale.width, fromRect.size.height * scale.height);
CGSize translation = CGSizeMake(fromRect.origin.x - scaledFromRect.origin.x, fromRect.origin.y - scaledFromRect.origin.y);
return CGAffineTransformMake(scale.width, 0.0, 0.0, scale.height, translation.width, translation.height);
}
@ConorGarry
ConorGarry / GroupByPredicatesExtension.kt
Last active July 24, 2020 07:22
Kotlin extension function for paritioning >2 predicates.
/**
* Similar to [groupBy] or [partition], except an arbitrary amount of predicates can be returned.
* Think [partition] for > 2 predicates.
*
*
* @return [List] with size n for predicates where all items will satisfy one of the predicates,
* or size n + 1 for n predicates, where there will be remaining items after condition check.
*
* @throws [IndexOutOfBoundsException] If using declaration deconstruction where val count is > possible return size.
*
@0xced
0xced / pin256.sh
Created August 30, 2017 14:50
Extract certificate + public key + pin from a TLS server
#!/usr/bin/env bash -e
HOST=${1:-cloudflare.com}
FILENAME=${2:-${HOST%%.*}}
# For file naming, see https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them
# For HTTP Public Key Pinning (HPKP), see https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning
CERTIFICATE_PEM="${FILENAME}_certificate.ascii.crt"
CERTIFICATE_DER="${FILENAME}_certificate.crt"
PUBKEY_PEM="${FILENAME}_pubkey.ascii.key"