Skip to content

Instantly share code, notes, and snippets.

Michael Behan mbehan

Block or report user

Report or block mbehan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View SwiftyButton.swift
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
}
}
@0xced
0xced / pin256.sh
Created Aug 30, 2017
Extract certificate + public key + pin from a TLS server
View pin256.sh
#!/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"
@mbehan
mbehan / ForcePanGestureRecognizer.swift
Created Nov 11, 2016
A UIPanGestureRecognizer subclass to get the force of the gesture's touch (assumes a single touch)
View ForcePanGestureRecognizer.swift
import UIKit.UIGestureRecognizerSubclass
class ForcePanGestureRecognizer : UIPanGestureRecognizer {
private(set) var force = CGFloat(0) {
didSet {
if force > maxForce {
maxForce = force
}
}
@mbehan
mbehan / increment-build-number.sh
Created Apr 23, 2014
Add as a pre compile build phase in Xcode to auto increment your build number (bundle version). Format is revHash.user.number
View increment-build-number.sh
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
Uploads builds produced by Xcode bots
View build-uploader.sh
#!/bin/bash
files=/ci_scripts/*.plist
for f in $files
do
echo Processing $f "..."
productName="$(/usr/libexec/plistbuddy -c Print:ProductName: "$f")"
echo $productName
@hatfinch
hatfinch / CGAffineTransformFromRectToRect.m
Created Aug 17, 2011
CGAffineTransformFromRectToRect (not working)
View CGAffineTransformFromRectToRect.m
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);
}
@zoul
zoul / AVAssetExportSession+Testing.m
Created Nov 8, 2010
Export assets synchronously. Good for testing.
View AVAssetExportSession+Testing.m
@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);
@zoul
zoul / UIImage+ForceLoad.m
Created Sep 14, 2010
Forces UIImage to load and decode its data
View UIImage+ForceLoad.m
@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);
You can’t perform that action at this time.