A Pen by Alex Persian on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
func dispatchOnce(_ predicate: inout Bool, _ block: @noescape () throws -> Void) rethrows { | |
objc_sync_enter(predicate) | |
if !predicate { | |
do { | |
predicate = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Dispatch { | |
private func once(var predicate: Bool, block: () -> Void) { | |
if !predicate { | |
block() | |
predicate = true | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HandleUserDefaults.swift | |
// Student | |
// | |
// Created by Alex Persian on 6/9/15. | |
// Copyright (c) 2015 Geo-Comm Inc. All rights reserved. | |
// | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//TODO: Write a test for the hex string -> UIColor conversion | |
func checkHexStringForDateString(dateString: String) { | |
// given | |
let changes: [String: String] = [ | |
"1" : "A", | |
"2" : "B", | |
"3" : "C", | |
"4" : "D", | |
"5" : "E", | |
"6" : "F" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CameraViewController.swift | |
// SpotWalk | |
// | |
// Created by Alex Persian on 10/25/15. | |
// Copyright © 2015 alexpersian. All rights reserved. | |
// | |
import UIKit | |
import AVFoundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/api/posts', function(req, res) { | |
Post.find(function(err, posts) { | |
// if there is an error retrieving, send the error | |
// nothing after res.send(err) will execute if there is one | |
if (err) { | |
res.send(err); | |
} | |
res.json(posts); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/api/posts', function(req, res) { | |
var post = new Post(); | |
post.name = req.body.name; | |
post.desc = req.body.desc; | |
post.quantity = req.body.quantity; | |
post.time = new Date(); | |
post.save(function(err) { | |
if (err) { | |
res.send(err); |
NewerOlder