Skip to content

Instantly share code, notes, and snippets.

View mteece's full-sized avatar

Matthew Teece mteece

View GitHub Profile
@mteece
mteece / compareversions.js
Created May 23, 2014 19:28
Compare the installed to required version. Assumes Semantic Versioning.
/*
* Compare the installed to required version.
*
* @param {String} installed The currently installed version string.
* @param {String} required The required version string.
*
* compareVersions('1.0.1', '1.0.0') returns true
* compareVersions('1.0.0', '1.0.0') returns true
* compareVersions('0.0.9', '1.0.0') returns false
* compareVersions('1.0.0', '1.0.1') returns false
@mteece
mteece / basic-auth-afnetworking-2-0.m
Created July 28, 2014 18:25
Post JSON Body to API with Basic HTTP Authentication using Objective-C and AFNetworking 2.0
NSString *URLString = @"http://example.com/path";
NSDictionary *parameters = @{ };
NSURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:URLString parameters:parameters error:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
@mteece
mteece / ExampleClass-new.h
Created July 28, 2014 19:38
The past way and the the new and improved way of writing Objective-C classes, and properties with the modern Objective-C compiler.
@interface ExampleClass : UIViewController
@property (nonatomic, assign) BOOL someBool;
// a few method declarations
@end

Keybase proof

I hereby claim:

  • I am mteece on github.
  • I am mteece (https://keybase.io/mteece) on keybase.
  • I have a public key whose fingerprint is A11C 93B2 294C B115 A311 4302 6BB8 8693 3E75 10B6

To claim this, I am signing this object:

@mteece
mteece / moveto.js
Last active August 29, 2015 14:07
Move an item in array to a position.
moveTo = function (arr, value, position) {
var index = arr.indexOf(value), newPos = position - 1, temp = arr[newPos];
if (index === -1) return;
if (newPos >= arr.length || newPos < 0) return;
if (index === newPos) return;
arr.splice(newPos, 1, value); // Remove 1 item at newPos insert value
arr.splice(index, 1, temp); // Remove 1 item at index, insert temp
}
//var a = ['Matt', 'Ralph', 'Jason'];
  • To add Settings.bundle in Xcode. Command N and in Resource, choose Settings Bundle .
  • Open Root.plist in source code, paste the code below to replace it,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>PreferenceSpecifiers</key>
	
@mteece
mteece / .gitignore
Created June 10, 2015 14:43
Merged Liftoff and Objective-C.gitignore
# OS X Finder
.DS_Store
# Xcode per-user config
*.pbxuser
!default.pbxuser
*.mode1
*.mode1v3
!default.mode1v3
*.mode2v3
@mteece
mteece / data.json
Created August 31, 2015 19:07
Deserialize JSON to Objective-C
{
"completed_in": 0.012,
"max_id": 136536013832069120,
"max_id_str": "136536013832069120",
"next_page": "?page=2&max_id=136536013832069120&q=twitterapi&rpp=1",
"page": 1,
"query": "twitterapi",
"refresh_url": "?since_id=136536013832069120&q=twitterapi",
"results": [
{
@mteece
mteece / ListResponseObject.cs
Created November 15, 2011 20:05
C# wrapper for responses, returning a list of objects in WCF. Useful for Ajax and JSON, uses generics.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
/*
using My.Domain.Namespace;
(function(){
// FizzBuzz
for(var i=1; i<=100; i++) {
var fizz = (i % 3 == 0 ? "fizz" : "") + (i % 5 == 0 ? "buzz" : "");
console.log(fizz == "" ? i : fizz);
}
})();