Skip to content

Instantly share code, notes, and snippets.

@appyaaron
appyaaron / send_apns.php
Created August 13, 2014 08:02
Send a push
function sendAPNSSandbox($vDeviceToken, $message) {
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'Createanet');
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) return false;
@appyaaron
appyaaron / CustomTextField.swift
Last active August 31, 2015 06:06
A custom UITextField that allows you to easily set the placeholder color from your storyboard!
import UIKit
@IBDesignable class CustomTextField: UITextField {
@IBInspectable var placeholderColor: UIColor = UIColor.lightGrayColor() {
didSet {
let canEditPlaceholderColor = self.respondsToSelector(Selector("setAttributedPlaceholder:"))
if (canEditPlaceholderColor) {
self.attributedPlaceholder = NSAttributedString(string: placeholder, attributes:[NSForegroundColorAttributeName: placeholderColor]);
}
@appyaaron
appyaaron / Check for white-spaces in iOS
Last active December 27, 2015 15:59
Check a string for a whitespace by creating an NSArray from an NSString separated by a whitespace. If this count is greater than one, then there is at least 1 whitespace.
NSArray *checkPasswordForWhitespace = [password.text componentsSeparatedByString:@" "];
NSLog(@"%@", checkPasswordForWhitespace);
if ([checkPasswordForWhitespace count] > 1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whitespace" message:@"Please remove the whitespace from your password." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
return;
@appyaaron
appyaaron / Validate an email (iOS)
Created October 26, 2013 22:45
Here is a quick and simple way to validate an email address in iOS.
//Place outside any other methods
- (BOOL)validateEmail:(NSString *)emailStr {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
//Place where you wish to validate the email
if(![self validateEmail:[emailAddress text]]) {
//Didn't enter correct email value
@appyaaron
appyaaron / Setting parameters on an NSString (iOS)
Last active December 26, 2015 15:49
A nice and simple way to get the characters in-between a start character and an end character using NSRange. Replace cell.text with your string.
NSString *param3 = nil;
NSRange start3 = [cell.text rangeOfString:@"thestartcharacterhere"];
if (start3.location != NSNotFound)
{
param3 = [cell.text substringFromIndex:start3.location + start3.length];
NSRange end3 = [param3 rangeOfString:@"theendcharacterhere"];
if (end3.location != NSNotFound)
{
param3 = [param3 substringToIndex:end3.location];
}
@appyaaron
appyaaron / Hide the UIStatusBar in iOS 7
Last active December 26, 2015 15:49
Here is a nice and simple way to hide the status bar in iOS 7
//Place in viewDidLoad
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}