Skip to content

Instantly share code, notes, and snippets.

View dmathewwws's full-sized avatar
🤠

Daniel Mathews dmathewwws

🤠
View GitHub Profile
import Vapor
let drop = Droplet()
drop.get("welcome") { request in
return "Hello"
}
drop.get("uppercase") { request in
guard let word = request.data["word"]?.string else { return "Could not grab the name" }
public extension UIDevice {
var deviceType: String {
var systemInfo = utsname()
uname(&systemInfo)
let machine = systemInfo.machine
let mirror = Mirror(reflecting: machine)
var identifier = ""
@dmathewwws
dmathewwws / URLSession POST.swift
Created November 5, 2016 01:35
URLSession POST request example
private static func createUserEventData(user:SKUser, eventType:SKEventType, sticker:Sticker?) {
// server endpoint
let endpoint = "https://app.stickerkit.io/userEvent/v1/\(user.projectID)"
guard let endpointUrl = URL(string: endpoint) else {
return nil
}
//Make JSON to send to send to server
@dmathewwws
dmathewwws / gist:6d5bc1ad8f380f0c72b593808ed9d576
Created July 25, 2016 18:08
W5D1 - Swift Mini Assignment
Write a function that pluralizes words.
• By default, it just adds "s" to the end.
• But there are some exceptions ("goose" -> "geese")
• Create a dictionary of exceptions, so I can look up "hoof" and get back "hooves".
• The function should first check the dictionary, to see if it has an exception, then fall back to appending "s"
# HTTP - redirect all requests to HTTPS
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}
# HTTPS - proxy requests to /parse-server/
# through to Parse Server
server {
apt-get update -y
apt-get upgrade -y
apt-get install git -y
curl -fsSL https://get.docker.com/ | sh
apt-get install python-pip -y
pip install docker-compose
@dmathewwws
dmathewwws / gist:37a18558426cea5edc84
Created July 11, 2015 21:20
How to limit UITableView row reordering to a section
override func tableView(tableView: UITableView, targetIndexPathForMoveFromRowAtIndexPath sourceIndexPath: NSIndexPath, toProposedIndexPath proposedDestinationIndexPath: NSIndexPath) -> NSIndexPath {
if sourceIndexPath.section != proposedDestinationIndexPath.section {
var row = 0
if sourceIndexPath.section < proposedDestinationIndexPath.section {
row = tableView.numberOfRowsInSection(sourceIndexPath.section) - 1
}
return NSIndexPath(forItem: row, inSection: sourceIndexPath.section)
}
return proposedDestinationIndexPath;
}
@dmathewwws
dmathewwws / gist:d430e8817de54f138e81
Last active August 29, 2015 14:19
Completion blocks
// How to create your own completion blocks
+ (void)responseFrom4sq:(CLLocation*)currentLocation limit:(NSString*)limit block:(void (^)(NSArray *locationDictionary, NSError *error))completionBlock{
NSString *apiString4aq= @"https://api.foursquare.com/v2/venues/search?ll=";
NSString *clientID = @"&client_id=x&client_secret=y";
NSString *version = @"&v=20121219";
NSMutableURLRequest *foursqRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%1.6f,%1.6f%@%@&limit=%@",apiString4aq,currentLocation.coordinate.latitude,currentLocation.coordinate.longitude,clientID,version,limit]]];
dispatch_queue_t foursqQueue;
range binaryRangedSearch(int array[], int searchValue, int minimumSearchBounds,int maximumSearchBounds)
{
// We would perform the search much like above
// where we go to find the value. But once we've found it,
// we need to find out where it occurs first and where it occurs last.
if (minimumSearchBounds > maximumSearchBounds) {
range notFound = {-1, 0};
return notFound;
}

WWDC Sessions by Topics

Language and Runtime

  • WWDC 2012 Session 405 — Modern Objective-C
  • WWDC 2012 Session 413 — Migration to Modern Objective-C
  • WWDC 2013 Session 228 — Hidden Gems in Cocoa and Cocoa Touch
  • WWDC 2014 Session 402 — Introduction to Swift
  • WWDC 2014 Session 403 — Intermediate Swift
  • WWDC 2014 Session 404 — Advanced Swift