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 CryptoKit | |
extension String { | |
func hmac(key: String) -> String { | |
let secret = key.data(using: .utf8)! | |
let message = self.data(using: .utf8)! | |
var hmac = HMAC<Insecure.SHA1>(key: SymmetricKey(data: secret)) | |
hmac.update(data: message) |
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 svg2img from 'svg2img'; | |
module.exports = (req, res) => { | |
const url = req.query.url; | |
const width = req.query.width; | |
const height = req.query.height; | |
const size = Math.min(width, height); | |
svg2img(url, {width: size, height: size, preserveAspectRatio: true}, | |
function(error, buffer) { | |
if (buffer) { |
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
const svg2img = require('svg2img'); | |
module.exports = (req, res) => { | |
svg2img(req.query.url, {width: req.query.width, height: req.query.height, preserveAspectRatio: true}, | |
function(error, buffer) { | |
if (buffer) { | |
res.send(buffer); | |
} | |
}); | |
}; |
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
enum Food: String { | |
case beef = "Beef" | |
case chicken = "Chicken" | |
case vegitarian = "Vegitarian" | |
case kids = "Kids" | |
} | |
protocol People { | |
var people: [Person] { get } | |
} |
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
for (i, table) in tables.enumerated() { | |
print("Table #\(i+1)") | |
print(table.people | |
.map{"\($0.name),\($0.food.rawValue)"} | |
.joined(separator: "\n") | |
) | |
} |
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
protocol People { | |
var people: [Person] { get } | |
} | |
@_functionBuilder | |
struct PeopleBuilder { | |
static func buildBlock(_ people: People...) -> [Person] { | |
return people.reduce([], {$0+$1.people}) | |
} | |
} |
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
@_functionBuilder | |
struct PeopleBuilder { | |
static func buildBlock(_ people: Person...) -> [Person] { | |
return people | |
} | |
} | |
struct Table { | |
let people: [Person] | |
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
Table { | |
Family("Mr. & Mrs. Smith") { | |
Person("Mr. John Smith", .beef) | |
Person("Mrs. Jane Smith", .chicken) | |
} | |
Person("Mr. Ed Ford", .chicken) | |
Person("Mrs. Amanda Doolittle", .vegitarian) | |
Family("Mr. & Mrs. Appleseed") { | |
Person("Mr. Jonny Appleseed", .chicken) | |
Person("Mrs. Jessica Appleseed", .vegitarian) |
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
enum Food: String { | |
case beef = "Beef" | |
case chicken = "Chicken" | |
case vegitarian = "Vegitarian" | |
case kids = "Kids" | |
} | |
struct Person { | |
let name: String | |
let food: Food |
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
enum Food: String { | |
case beef = "Beef" | |
case chicken = "Chicken" | |
case vegitarian = "Vegitarian" | |
case kids = "Kids" | |
} | |
struct Person { | |
let name: String | |
let food: Food |
NewerOlder