Skip to content

Instantly share code, notes, and snippets.

Pierre Houston jpmhouston

Block or report user

Report or block jpmhouston

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
@jpmhouston
jpmhouston / gist:db1fa96997cef811bc3251b6d50e99d6
Created Jan 30, 2019
Data extension method hexEncodedString
View gist:db1fa96997cef811bc3251b6d50e99d6
extension Data {
struct HexEncodingOptions: OptionSet {
let rawValue: Int
static let uppercase = HexEncodingOptions(rawValue: 0)
static let lowercase = HexEncodingOptions(rawValue: 1 << 0)
}
func hexEncodedString(options: HexEncodingOptions = []) -> String {
let hexDigits = Array((options.contains(.lowercase) ? "0123456789abcdef" : "0123456789ABCDEF").utf16)
var dump: [unichar] = []
var ascii: [unichar] = []
@jpmhouston
jpmhouston / gist:de82ffa91a9fdb026b39bc6ad65c7c0c
Created May 11, 2017
convert TimeInterval to DispatchTimeInterval
View gist:de82ffa91a9fdb026b39bc6ad65c7c0c
public extension TimeInterval {
public var dispatchInterval: DispatchTimeInterval {
let microseconds = Int64(self * TimeInterval(USEC_PER_SECS)) // perhaps use nanoseconds, though would more often be > Int.max
return microseconds < Int.max ? DispatchTimeInterval.microseconds(Int(microseconds)) : DispatchTimeInterval.seconds(Int(self))
}
}
@jpmhouston
jpmhouston / ColorPHTextField.swift
Last active Sep 15, 2016
UITextField subclass adding placeholderColor property
View ColorPHTextField.swift
// TODO: link here to SO post that inspired this
// ^ that source worked fine when setting placeholderColor sometime after
// placeholder or attributedPlaceholder, but not the other way around.
// this is an attempt to fix this, it might work.
class ColorPHTextField : UITextField {
@IBInspectable var placeholderColor: UIColor? {
didSet {
applyPlaceholderColor()
@jpmhouston
jpmhouston / gist:f25d560cbd771d0f74f3d7b2d0ce6fbd
Last active Aug 8, 2016
Swift Array element(at:), why is this missing from the standard library?
View gist:f25d560cbd771d0f74f3d7b2d0ce6fbd
extension Array {
func element(at index: Int) -> Element? {
return index >= 0 && index < count ? self[index] : nil
}
}
@jpmhouston
jpmhouston / NSManagedObject+JPHClone.h
Last active May 19, 2017
NSManagedObject+JPHClone
View NSManagedObject+JPHClone.h
//
// NSManagedObject+Clone.h
// TResActivityLog
//
// Created by Pierre Houston on 2016-05-30.
// Copyright © 2016 Resilience software. All rights reserved.
//
// When no context provided, uses [NSManagedObjectContext MR_defaultContext].
// Note, I was going to add unique prefix "jph_" to these category method names,
// but currently I've left those out.
@jpmhouston
jpmhouston / gist:35686fc811b1c62effe5
Last active Aug 29, 2015
Shrink UITextField placeholder to fit
View gist:35686fc811b1c62effe5
// call from a view controller's -viewDidLayoutSubviews or -viewWillAppear:
// pass it a text field, etc, assign result to that text field's attributedPlaceholder property
// note that the maxKerning parameter must be a negative value (a "maximally negative" kerning value)
// pro tip: i've sometimes found that a text field still has incorrect bounds in -viewDidLayoutSubviews
// and needs to forcibly have its layout done:
//- (void)viewDidLayoutSubviews {
// [self.field layoutIfNeeded];
// self.field.attributedPlaceholder = [self resizedPlaceholderForField:self.field withPadding:4.0 maxKerningReduction:0.3];
//}
@jpmhouston
jpmhouston / gist:daa75345f6a017ce1681
Created Jun 19, 2015
POST with both URL parameters & JSON body in AFNetworking
View gist:daa75345f6a017ce1681
@interface MixedPOSTHTTPSessionManager : AFHTTPSessionManager
- (NSURLSessionDataTask *)POST:(NSString *)URLString
parameters:(id)parameters
JSONParameters:(NSDictionary *)jsonParameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
@end
@implementation MixedPOSTHTTPSessionManager
View gist:131b96d02830d4a540ce
Verifying I am +jpmhouston on my passcard. https://onename.com/jpmhouston
@jpmhouston
jpmhouston / keybase.md
Last active Aug 29, 2015
Identity proof for keybase.io
View keybase.md

Keybase proof

I hereby claim:

  • I am jpmhouston on github.
  • I am jpmhouston (https://keybase.io/jpmhouston) on keybase.
  • I have a public key whose fingerprint is E183 744F B4CE E864 AE7B 9B1D 2449 C433 3C48 45D9

To claim this, I am signing this object:

@jpmhouston
jpmhouston / gist:680ba3a3c09039c66230
Last active Aug 29, 2015
successful yahoo oauth1 access, unsuccessful request
View gist:680ba3a3c09039c66230
** Generating signature for https://api.login.yahoo.com/oauth/v2/get_request_token
** Parameters for base signature string:
oauth_callback=http%3A%2F%2Flocalhost&
oauth_consumer_key=dj0yJmk9Q1BTWWoxZVd0QlBGJmQ9WVdrOWVGcEVWbWxTTldrbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hMQ--&
oauth_nonce=48FD2DE7-0380-40AA-BF8C-3C61341ACCCE&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1425329590&
oauth_version=1.0
** Base signature string:
You can’t perform that action at this time.