Skip to content

Instantly share code, notes, and snippets.

View bryanjclark's full-sized avatar

Bryan Clark bryanjclark

View GitHub Profile
@kylefritz
kylefritz / publishAmazonSnsMsg.py
Created October 18, 2010 22:06
publish a message to Amazon SNS using python or ruby
from time import strftime,gmtime,time
import urllib2
import hmac
import hashlib
import base64
import string
def publishAmazonSnsMsg(Subject,TopicArn,Message,AWSAccessKeyId,privatekey):
#http://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/
amzsnshost = 'sns.us-east-1.amazonaws.com'
@zwaldowski
zwaldowski / NSObject+Blocks.h
Created May 4, 2011 12:08
Perform blocks with delays and cancellation
//
// NSObject+Blocks.h
// Filemator
//
// Created by Zachary Waldowski on 4/12/11.
// Copyright 2011 Dizzy Technology. All rights reserved.
//
@interface NSObject (Blocks)
@erkie
erkie / UIFont+DahDit
Last active November 27, 2021 22:45
UILabel get CGRect for substring of text
//
// UIFont+DahDit.m
// DahDit
//
// Created by Erik Andersson on 2011-07-28.
// Copyright 2011 Åva gymnasium. All rights reserved.
//
#import "UIFont+DahDit.h"
@prabirshrestha
prabirshrestha / TextFieldChanges.m
Created August 2, 2012 13:53
Reactive Cocoa examples
@synthesize firstName = _firstName;
@synthesize txtFirstName = _txtFirstName;
[RACAbleSelf(self.firstName) subscribeNext:^(id x) { [self firstNameChanged:x]; }];
[self rac_bind:RAC_KEYPATH_SELF(self.firstName) to:self.txtFirstName.rac_textSubscribable];
- (void) firstNameChanged:(id)firstName {
NSLog(@"changed: %@", firstName);
}
@mattt
mattt / uiappearance-selector.md
Last active June 4, 2024 13:28
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@bryanjclark
bryanjclark / Given an NSRange and a UILabel with attributed text, find the CGRect of a substring
Last active July 15, 2021 10:42
My three current contenders for solving a tricky UILabel question: given an NSRange and a UILabel that displays attributed text, can you find the rect of the text in that range? Link to my related Stack Overflow question: http://stackoverflow.com/questions/19417776/how-do-i-locate-the-cgrect-for-a-substring-of-text-in-a-uilabel
- (CGRect)rectForSubstringWithRange:(NSRange)range
{
/* Core Text methods that seem somewhere in the neighborhood of useful:
CTRunGetPositionsPtr
CTRunGetPositions
CTRunGetImageBounds
CTLineGetStringRange
CTLineGetOffsetForStringIndex
CTLineGetImageBounds
@jlawton
jlawton / blur-and-darken.m
Last active July 17, 2018 19:23
CIFilter Blur
// Fix for https://github.com/bryanjclark/ios-darken-image-with-cifilter
-(instancetype)darkened:(CGFloat)alpha andBlurredImage:(CGFloat)radius blendModeFilterName:(NSString *)blendModeFilterName {
CIImage *inputImage = [[CIImage alloc] initWithImage:self];
CIContext *context = [CIContext contextWithOptions:nil];
//First, create some darkness
CIFilter* blackGenerator = [CIFilter filterWithName:@"CIConstantColorGenerator"];
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
void CRWaitMinimumDurationAndExecute(NSTimeInterval start, NSTimeInterval minimumDuration, void(^block)(void)) {
double diff = [NSDate date].timeIntervalSince1970-start;
double delayInSeconds = MAX(0.0, minimumDuration-diff);
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (block) block();
});
}
//Usage
@chriseidhof
chriseidhof / TypedNotifications.swift
Created January 26, 2015 14:41
Typed Notifications
import Foundation
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
struct Notification<A> {
let name: String
}