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
/* | |
* clearIntArray | |
* This function deletes all items in array (sets it to 0) and resizes array according to size (default = 1). | |
* @param int& theArray - passing the array by reference | |
* @param int size - size of the array (default = 1) | |
* @return int blank array of size | |
*/ | |
int clearIntArray( int& theArray[], int size = 0 ) { | |
ArrayResize( theArray, size ); | |
if ( size > 0 ) { ArrayInitialize( theArray, 0 ); } |
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
/******************************************************************************************************************** | |
Countdown.js is a simple script to add a countdown timer | |
for your website. Currently it can only do full minutes | |
and partial minutes aren't supported. This script is a fork of http://jsfiddle.net/HRrYG/ with some | |
added extensions. Since the original code that I forked was released under Creative Commons by SA license, | |
I have to release this code under the same license. You can view a live demo of this code at http://jsfiddle.net/JmrQE/2/. | |
********************************************************************************************************************/ | |
function countdown(minutes) { | |
var seconds = 60; | |
var mins = minutes |
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
// swift-tools-version:4.0 | |
import PackageDescription | |
let package = Package( | |
name: "blog", | |
dependencies: [ | |
// 💧 A server-side Swift web framework. | |
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"), | |
// 🔵 Swift ORM (queries, models, relations, etc) built on MySQL. |
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 FluentMySQL | |
import Vapor | |
final class User: MySQLModel { // 1 | |
/// The unique identifier for `User` // 2 | |
var id: Int? | |
// Additional properties of `User` // 3 | |
var email: String | |
var password: String |
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 Vapor | |
public func routes(_ router: Router) throws { | |
try router.register(collection: UserController()) | |
} |
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 Vapor | |
public func routes(_ router: Router) throws { | |
let userController = UserController() | |
router.post("users", use: UserController.create) | |
router.get("users", use: UserController.index) | |
router.get("users", User.parameter, use: UserController.show) | |
router.patch("users", use: UserController.update) | |
router.delete("users", User.parameter, use: UserController.delete) |
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 Vapor | |
import Crypto // 1 | |
/// Controls basic CRUD operations on `User`s. | |
final class UserController: RouteCollection { | |
func boot(router: Router) throws { | |
let users = router.grouped("users") // 2 | |
users.get(use: index) |
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
func validate(input: String) -> Bool { | |
let digits = input.map { Int(String($0)) } | |
guard digits.count == 10 && digits.count == input.count else { | |
return false | |
} | |
let check = digits[9]! | |
let remainder = digits.prefix(upTo: 9).enumerated().reduce(0) { |
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 Vapor | |
import FluentMySQL // 1 | |
final class Post: MySQLModel { // 2 | |
var id: Int? | |
var title: String | |
var body: String // 3 | |
init(id: Int? = nil, title: String, body: String) { // 4 | |
self.id = id |
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
let futurePosts = getPostsFromDatabase().map { posts in | |
// posts: [Post] | |
for post in posts { | |
print(post.title) | |
} | |
} |
OlderNewer