Skip to content

Instantly share code, notes, and snippets.

View eralston's full-sized avatar
🏠
Working from home

Erik Ralston eralston

🏠
Working from home
View GitHub Profile
@eralston
eralston / ResignOnReturnDelegate.m
Created December 31, 2013 18:49
A delegate for resigning a UITextField when the return key is pressed. It's a corrected version of the code here: http://stackoverflow.com/questions/3186065/uitextfield-resign-first-responder-ios4
@interface ResignOnReturnDelegate : NSObject <UITextFieldDelegate>
@end
@implementation ResignOnReturnDelegate
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([string isEqualToString:@"\n"]) {
@eralston
eralston / RoundedTableView.m
Created December 17, 2013 22:38
A code snippet for adding rounded cells to a UITableView in Objective-C (Originally from http://stackoverflow.com/questions/18822619/ios-7-tableview-like-in-settings-app-on-ipad)
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(tintColor)]) {
if (tableView == self.tableView) {
CGFloat cornerRadius = 5.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
CGRect bounds = CGRectInset(cell.bounds, 10, 0);
BOOL addLine = NO;
@eralston
eralston / NSArray+WeakArray.h
Last active July 5, 2023 09:11
An pair of Objective-C categories on NSArray and NSMutableArray that provides a mechanism for weak referencing any type of Objective-C object. This was created when I found a case, referencing protocols, where NSPointerArray did not work for my needs.
//
// NSMutableArray+WeakArray.h
//
#import <Foundation/Foundation.h>
///
/// Category on NSArray that provides read methods for weak pointers
/// NOTE: These methods may scan the whole array
///
@eralston
eralston / gist:7865300
Created December 8, 2013 23:52
A basic example of checking for available sharing mechanisms with SimpleSocial.
BOOL isFacebookLoggedInAndiOS6 = [SimpleSocial isFacebookAvailable];
BOOL isTwitterLoggedInAndiOS6 = [SimpleSocial isTwitterAvailable];
BOOL isSmsAvailable = [SimpleSocial isSmsAvailable];
BOOL isEmailAvailable = [SimpleSocial isEmailAvailable];
@eralston
eralston / gist:7865288
Created December 8, 2013 23:49
A basic demonstration of using SimpleSocial.
@implementation ViewControllerChild
{
// For holding the simple social instance
SimpleSocial *_simpleSocial;
// An outlet to the button, so we can show/hide only when Facebook is available
__weak IBOutlet UIButton *_shareBtn;
}
- (void)viewDidLoad
@eralston
eralston / MailExtensions.cs
Last active December 23, 2015 07:59
A static class in C# that simplifies setting properties of the System.Net.Mail.MailMessage class, concealing all of those extraneous new instances of objects you have to create.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net.Mime;
/// <summary>
@eralston
eralston / Code First Entity Framework Examples.cs
Last active December 21, 2015 05:48
Example C# class showing the basic and recurring patterns of fields used in Code First Entity Framework
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Web.Security;
class Example
@eralston
eralston / Common Package Manager Console Commands
Last active December 21, 2015 05:39
The commands for common package manager console tasks for ASP.Net MVC web app projects, such as migration of Code-First Entity Framework
///
/// UPDATE NuGET PACKAGES
///
Once a project is created, be sure to run "update-packages" to get the latest version of each package
///
/// To ensure NuGet packages are working on teammate machines:
/// Go tools -> Options -> Package Manager -> General
/// Check "Allow NuGet to download missing packages during build
/// Right click on the project solution
@eralston
eralston / SimpleSocial.h
Last active December 20, 2015 19:18
An Objective-C class that simplifies using the iOS 6 Native social posting dialogs for Facebook and Twitter, plus SMS messaging and E-mail
//
// SimpleSocial.h
//
// Copyright (c) 2013 Erik Ralston
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@eralston
eralston / SimpleCaptureSession.h
Last active December 19, 2015 13:38
A sub-class of AVCaptureSession that adds a few helper properties for simplifying access to device hardware and add capabilities like flipping between the front and back camera.
//
// SimpleCaptureSession.h
//
// Copyright (c) 2013 Erik Ralston
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights