Skip to content

Instantly share code, notes, and snippets.

View rsaunders100's full-sized avatar

Rob Saunders rsaunders100

View GitHub Profile
@rsaunders100
rsaunders100 / XMLPullParserExample.java
Created September 7, 2011 16:08
(Android) An simple example use of a XML pull parser.
public String parseInputStream(InputStream inputStream) throws Exception
{
XmlPullParser parser = Xml.newPullParser();
parser.setInput(inputStream, null);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType){
case XmlPullParser.START_DOCUMENT:
@rsaunders100
rsaunders100 / UIView+Snapshots.m
Created January 31, 2012 14:11
(iOS) Take image snapshots of the current state of a view.
@interface UIView (UIView_Snapshots)
// Take image snapshots of the current state of a view.
// Use the background color of the superview if you have rounded corners
// If background color is nil the background will be treated as transparent
- (UIImage*) imageOfViewUsingBackgroundColor:(UIColor*)backgroundColorOrNil;
// Will save to the documents directory as XXXX.png
- (void) saveImageOfViewToPNGNamed:(NSString*)fileNameMinusExtension usingBackgroundColor:(UIColor*)backgroundColorOrNil;
@rsaunders100
rsaunders100 / AppReSigner.scpt
Created March 22, 2012 17:29
Re-sign .ipa files and replace the embedded.mobileprovision
-- Erica Sadun, http://ericasadun.com
-- iPhone Developer's Cookbook, 3.0 Edition
-- BSD License, Use at your own risk
-- Adapted by Rob Saunders to also replace embeded profiles
--
--
-- save in Script Editor as Application
-- drag files to its icon in Finder
@rsaunders100
rsaunders100 / SimpleTimerThreshold.java
Created September 7, 2011 17:13
(Android) Use to check check if a threshold has expired since a last event. e.g. 5 mins has expired since the lat time some data has been downloaded. Optional persistant storage.
package uk.co.digitaljigsaw.utils;
import java.util.Calendar;
import java.util.Date;
import android.R.string;
import android.content.Context;
import android.content.SharedPreferences;
@rsaunders100
rsaunders100 / UIImage+ImageSplitting.h
Created February 3, 2012 15:02
(iOS) Split an image into an array of evenly sized CALayers
//
// UIImage+ImageSplitting.h
// Test
//
// Created by Robert Saunders on 03/02/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@rsaunders100
rsaunders100 / gist:6094708
Created July 27, 2013 12:14
Core image rendering on a EAGLContext
// View controller is a subclass of GLKViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.ciContext = [CIContext
contextWithEAGLContext:self.eaglContext
@rsaunders100
rsaunders100 / UIView+ViewArranging.h
Created May 15, 2012 17:39
(iOS) Make a view with given subviews arranged linearly (either horizontally or vertically)
//
// UIView+ViewArranging.h
// Created by on 15/05/2012.
//
#import <UIKit/UIKit.h>
typedef enum {
ViewArrangingDirectionHorizontal,
ViewArrangingDirectionVertical
@rsaunders100
rsaunders100 / gist:8711151
Created January 30, 2014 15:35
Wrap HTML with a given UIColor and UIFont
+ (NSString *)htmlFromBodyString:(NSString *)htmlBodyString
textFont:(UIFont *)font
textColor:(UIColor *)textColor
{
int numComponents = CGColorGetNumberOfComponents([textColor CGColor]);
NSAssert(numComponents == 4 || numComponents == 2, @"Unsupported color format");
// E.g. FF00A5
NSString *colorHexString = nil;
@rsaunders100
rsaunders100 / gist:8972207
Created February 13, 2014 09:24
NSDateFormatter reuse
// For NSString to NSDate to parse server dates in the full ISO 8601 format
// E.g. 2014-02-11T10:22:46+00:00
+ (NSDateFormatter *) iso8601FullDateFromatter
{
static NSDateFormatter * dateFormatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dateFormatter = [[NSDateFormatter alloc] init];
@rsaunders100
rsaunders100 / alert.m
Created September 19, 2011 09:35
(iOS) UIAlert View Example - Has a delegate for Yes/No Taps Will only display popup once
- (void) showConfirmationAlert
{
// A quick and dirty popup, displayed only once
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"HasSeenPopup"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Question"
message:@"Do you like cats?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes",nil];