Skip to content

Instantly share code, notes, and snippets.

import Foundation
let date = NSDate()
var dateArrayCalendar = [String]()
let components = NSCalendar.currentCalendar().components([.Day , .Month , .Year], fromDate: date)
let year = components.year
let month = components.month
let dateFormatatter = NSDateFormatter()
let day = 1 // Output is [2,3,4]
// let day = 0 than o/p [1,2,3,4,5]
//
// ViewController.swift
// carouselTest
//
// Created by Paul Wilkinson on 28/09/2016.
// Copyright © 2016 Paul Wilkinson. All rights reserved.
//
import UIKit
import iCarousel
@paulw11
paulw11 / getReceipt.swift
Last active June 29, 2022 06:16
iOS Receipt validator
if let receiptURL = NSBundle.mainBundle().appStoreReceiptURL {
print("Fetching local receipt")
if let receipt = NSData(contentsOfURL: receiptURL) {
print("fetched")
let b64 = receipt.base64EncodedStringWithOptions([]).stringByReplacingOccurrencesOfString("+", withString: "%2B")
self.validateReceipt(b64)
} else {
print("Could not retrieve app store receipt")
}
} else {
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if let url = URL(string: "http://seemeclothing.xyz/service.php") {
@paulw11
paulw11 / bt.swift
Last active December 24, 2018 01:21
//
// BTConnectionHandler.swift
// AdTableTest
//
// Created by Paul Wilkinson on 24/06/2016.
// Copyright © 2016 Paul Wilkinson. All rights reserved.
//
import Foundation
import CoreBluetooth
//
// AppDelegate.m
// DefaultsTest
//
// Created by Paul Wilkinson on 24/06/2016.
// Copyright © 2016 Paul Wilkinson. All rights reserved.
//
#import "AppDelegate.h"
if ([self canFlash]) {
self.flashLabel.text = self.sentences[self.sentenceCounter][self.wordCounter];
self.wordCounter++;
if (self.wordCounter == [self.sentences[self.sentenceCounter] count]) {
self.sentenceCounter++;
self.wordCounter = 0;
}
}
//
// ViewController.swift
// AdTableTest
//
// Created by Paul Wilkinson on 15/06/2016.
// Copyright © 2016 Paul Wilkinson. All rights reserved.
//
import UIKit
let vowels=["a","e","i","o","u"]
let vowelSet = NSCharacterSet(charactersInString: "aeiou")
func findVowelAndReplace(start: NSString, end: NSString) -> [String] {
let vowelPosition = end.rangeOfCharacterFromSet(vowelSet)
var outputArray = [String]()
if vowelPosition.location != NSNotFound {
let newEnd = end.substringFromIndex(vowelPosition.location+1)
let newStart = end.substringToIndex(vowelPosition.location)
for vowel in vowels {
NSString *url = @"https://www.google.com";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
// [request setValue:@"api.example.com" forHTTPHeaderField:@"Host"];
[request setValue:@"http://www.examplegood.com/" forHTTPHeaderField:@"Referer"];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod: @"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"%@",response);
NSLog(@"%@",error);
NSString* resultStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];