Skip to content

Instantly share code, notes, and snippets.

View vikdenic's full-sized avatar

vik vikdenic

  • Chicago, IL
View GitHub Profile
@vikdenic
vikdenic / gist:bceea2d9ab9e2fa9cf2b
Created June 2, 2015 17:43
populateWithRetiredHeroesIfEmpty
-(void)populateWithRetiredHeroesIfEmpty
{
if (self.heroes.count < 2) {
for (RetiredSuperhero *retiredSuperhero in self.retiredSuperheroes) {
NSManagedObject *superhero = [NSEntityDescription insertNewObjectForEntityForName:@"Superhero" inManagedObjectContext:self.moc];
[superhero setValue:retiredSuperhero.name forKey:@"name"];
[superhero setValue:retiredSuperhero.textDescription forKey:@"textDescription"];
[superhero setValue:retiredSuperhero.urlString forKey:@"imageURL"];
[self.moc save:nil];
[self load];
@vikdenic
vikdenic / gist:75cfe0b3091a787b7e11
Created April 2, 2015 19:04
XCTAssertEqualObjects
- (void)testFirstSuperHero {
XCTestExpectation *expectation = [self expectationWithDescription:@"Retrieving Superheroes"];
[SuperHero retrieveSuperHerosWithCompletion:^(NSArray *superHeros) {
SuperHero *firstHero = superHeros.firstObject;
NSLog(@"%@", firstHero.name);
XCTAssertEqualObjects(firstHero.name, @"Namor");
[expectation fulfill];
}];
@vikdenic
vikdenic / gist:c3bcfda0e61628b9f8b9
Created April 2, 2015 18:38
Locate Core Data sqlite
- (NSURL *)applicationDocumentsDirectory {
NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
// The directory the application uses to store the Core Data store file. This code uses a directory named "yourname.BookClub" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
if error == nil
{
let mostRecentMessage = self.messages.first
var indexPathArray = [NSIndexPath]()
var index = 0
for tweet in tweetMessages
{
//If any new tweets are found, add them to the array
if tweet.bornOn!.compare(mostRecentMessage!.bornOn!) == NSComparisonResult.OrderedDescending
{
@vikdenic
vikdenic / gist:fc4c30e10d57ac14167a
Created March 2, 2015 20:55
animate collectionView addition
var indexPathArray = [NSIndexPath]()
var index = 0
for message in messages {
self.messages.insert(message, atIndex: index)
indexPathArray.insert(NSIndexPath(forItem: index, inSection: 0), atIndex: index)
index++
}
self.collectionView.insertItemsAtIndexPaths(indexPathArray)
@vikdenic
vikdenic / gist:6cb0e079b0adc07fa1fd
Created February 24, 2015 03:27
UpdateCardViewController
//
// ViewController.m
// PTKPayment Example
//
// Created by Alex MacCaw on 1/21/13.
// Copyright (c) 2013 Stripe. All rights reserved.
//
#import "UpdateCardViewController.h"
#import "Stripe.h"
@vikdenic
vikdenic / gist:8fd1ced79a5558f6866b
Created February 23, 2015 16:46
PayPal Access Token and Payment Verification
//
// PPDataManager.swift
// HealthBuddy
//
// Created by Vik Denic on 2/15/15.
// Copyright (c) 2015 Nektar Labs. All rights reserved.
//
import Foundation
@vikdenic
vikdenic / gist:8b9652352650c1399324
Created February 10, 2015 15:55
Retrieve PayPal Access Token via HTTP Request
func httpRequestAccessToken()
{
//Concatenate a String composed of the client and secret id's
let authString = "\(kClientIdSandbox):\(kSecretId)"
let authData = authString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
let credentials = "Basic \(authData!.base64EncodedStringWithOptions(nil))"
//Create and set configuration object with necessary Header and value parameters
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPAdditionalHeaders = ["Accept": "application/json", "Accept-Language": "en_US", "Content-Type": "application/x-www-form-urlencoded", "Authorization": credentials]
@vikdenic
vikdenic / gist:1f9c4089d710ae7a2c6e
Created February 1, 2015 21:01
may cloud call from code stripe
NSDictionary *chargeParams = @{
@"token": token.tokenId,
@"currency": @"usd",
@"amount": result, // this is in cents (i.e. 1000 = $10)
@"lineItems": self.lineItems,
@"name": self.shippingName,
@"email": self.email,
@"address": self.shippingAddress,
@"cityState": self.cityState,
@"zipcode": self.zipcode,
@vikdenic
vikdenic / gist:837d7bf5e8516f1d18df
Created February 1, 2015 19:45
May Stripe Before mailfun order stuff
Parse.Cloud.define("charge", function(request, response) {
console.log("test");
Stripe.Charges.create({
amount: request.params.amount, // in cents
currency: request.params.currency,
card: request.params.token
},{
success: function(httpResponse) {
response.success("Purchase made!");
},