Skip to content

Instantly share code, notes, and snippets.

View scottsappen's full-sized avatar

Scott Sappenfield scottsappen

View GitHub Profile
@scottsappen
scottsappen / gist:5901899
Last active December 19, 2015 05:09
Activity indicator made easy in iOS
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *AboutActivityIndicator;
@synthesize AboutActivityIndicator = _aboutActivityIndicator;
[_aboutActivityIndicator startAnimating];
[_aboutActivityIndicator stopAnimating];
@scottsappen
scottsappen / gist:5901896
Created July 1, 2013 15:33
SQLLite integration with iOS app
1. Here’s your data controller class
#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "UserObject.h"
@interface DataController : NSObject
{
sqlite3 *databaseHandle;
}
-(void)initDatabase;
@scottsappen
scottsappen / gist:5901890
Created July 1, 2013 15:32
iOS 5.0+ made it a whole lot easier working with them as Dictionary objects
NSData *jsonData = [fixJSONString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&parseError];
if (jsonArray)
{
NSMutableArray *userObjects = [[NSMutableArray alloc]init];
for(NSDictionary *item in jsonArray) {
@scottsappen
scottsappen / gist:5901883
Last active December 19, 2015 05:09
Using the camera gallery picker or taking a photo on the iPhone in iOS
//in your header
@property (weak, nonatomic) IBOutlet UIButton *ProfilePictureButton;
UIViewController <UIImagePickerControllerDelegate, UIActionSheetDelegate>
//in your implementation
@synthesize ProfilePictureButton = _profilePictureButton;
//implementation details
[self setProfilePictureButton:nil];
@scottsappen
scottsappen / gist:5901860
Created July 1, 2013 15:29
launch the Safari mobile browser from inside your iOS App
- (IBAction)LaunchSafariButtonClick:(UIButton *) sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.yoururl.com"]];
}
@scottsappen
scottsappen / gist:5901839
Created July 1, 2013 15:27
Google Memcache is super simple - example with a jinja template
from google.appengine.api import memcache
if memcache.get('yourindexpage'):
self.response.out.write(memcache.get('yourindexpage'))
else:
template = jinja_environment.get_template('/index.html')
@scottsappen
scottsappen / gist:5901832
Created July 1, 2013 15:27
Super Simple Web Server from Python. Netcat and various other utilities make it so easy to run a simple web server on your machine, but so does Python.
Here’s how you can run it on a Windows machine, but works quite well on Linux too (or Cygwin).
C:\>python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
@scottsappen
scottsappen / gist:5901820
Created July 1, 2013 15:26
ASP.Net XMLDocument to incorporate a blog roll
Let’s say you have a WordPress blog at another domain and you want to show it on another domain.
Well, you’re better off using a more standard way of incorporating a WordPress blog into your website (just google around), but if you need to do something more custom, here’s a possibility.
Here’s some pseudo code for a .Net application – you get the idea. One thing to keep in mind is that XMLDocument is not serializable, so if you want to save it in a session state or do something else, you will need to work around it.
Dim xmlReader As XmlReader = xmlReader.Create("your website blog url goes here/feed/rss")
Dim xmlDocument As XmlDocument = New XmlDocument
xmlDocument.Load(xmlReader)
Dim xmlNameSpaceManager As XmlNamespaceManager = New XmlNamespaceManager(xmlDocument.NameTable)
@scottsappen
scottsappen / gist:5901810
Created July 1, 2013 15:24
ASP.Net SQL Server sql injection safety
Dim connString As String = ConfigurationManager.ConnectionStrings("your_database").ConnectionString
Dim sqlString As String = ""
Dim sqlConnection As New SqlConnection(connString)
sqlString = "insert into [ss].[dbo].[MyGuestBook] (firstName) values (@firstName);"
Dim sqlCommand As New SqlCommand(sqlString, sqlConnection)
Dim paramFirstName = New SqlParameter("firstName", SqlDbType.VarChar)
paramFirstName.Value = inputFromUserCleanedFirstName
sqlCommand.Parameters.Add(paramFirstName)
@scottsappen
scottsappen / gist:5901807
Created July 1, 2013 15:24
PHP MySQL PDO sql injection safety
$pdo = new PDO('mysql:dbname=your_database;host=localhost', $username, $password);
//don't use whatever the user typed in, use a variable
$stmt = $pdo->prepare('SELECT * FROM MyGuestBook WHERE firstName = :firstName');
//that variable is then assigned to whatever the user typed in, but it's escaped and treated safely
$stmt->execute(array(':firstName' => $firstName));