Skip to content

Instantly share code, notes, and snippets.

View ejknapp's full-sized avatar

Eric Knapp ejknapp

View GitHub Profile
//Set cookie policy to accept cookies always
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
// How to poll the server periodically
- (BOOL)testForFlakServer:(NSString *)hostURL {
NSString *urlString = [NSString stringWithFormat:@"%@/flak", hostURL];
NSLog(@"urlString: %@", urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// How to create a POST request to the Flak server
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSData *data = [jsonStringForSession dataUsingEncoding:NSISOLatin2StringEncoding];
[request setHTTPBody:data];
// Handling Flak dates
NSDateFormatter* dateFormatter;
...
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
//In the init method of something
self.dateFormatter = [[NSDateFormatter alloc] init];
self.dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
Searching An Array
1. A for loop that loops through the array
for (index = 0; index < numbers.length; index++) {
2. An "if" statement that compare the current element in the array with the value I'm searching for.
/*
This is the JavaScript code for
"Lab 11: Searching an Array"
File: /unit5/labs/lab11searchAnArray.html
*/
function lab11Demo() {
// Your code goes in here.
var words;
var search = "not";
var index;
//Datasource array for table view
- (void)createDataSourceArray {
NSDictionary *credentials = [self.flakManager.settingsManager loginCredentials];
NSDictionary *loginDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Logged in as:", @"sectionTitle",
[NSArray arrayWithObjects:
[credentials objectForKey:@"currentLoggedInUserByName"],
UNIX Commands
pwd - Where am I?
cd - Just type "cd" to go home
ls - basic directory list
ls -l - list view of directory
ls -a - show all files including hidden
ls -al - show all in list
// Exception demo
package java112.labs1;
import java.io.*;
import java.util.*;
/**
* @author Eric Knapp
* class ExceptionDemo
// Demo of IBOutlet
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.myFirstLabel.text = @"Fred";
}