View simplewebsocketstore.swift
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 Vapor | |
@available(macOS 12.0, *) | |
actor WebSocketStore { | |
private var webSockets: [WebSocket] = [] | |
private var heartbeats: [WebSocket: TimeInterval] = [:] | |
private var channels: [String: [WebSocket]] = [:] | |
struct CustomMessage: Content { |
View gist:d5d70e8e2c57da2ca6dcfd3a460c1b55
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 "./styles.css"; | |
import { useState, useEffect } from "react"; | |
function useTimer(timeInSeconds) { | |
const [timer, setTimer] = useState(0); | |
const [timeLeft, setTimeLeft] = useState(timeInSeconds); | |
if (typeof timer !== "number") { | |
return console.log("useTimer first argument must be a number"); |
View gist:deb77a76163acdcf90aea81836261096
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 React, { useState, useEffect, useCallback } from "react"; | |
import { useHistory } from "react-router-dom"; | |
import { Typography, Button } from "@material-ui/core"; | |
import { Link } from "react-router-dom"; | |
import "./styles.css"; | |
import B1 from "./img/1.png"; | |
import B5 from "./img/5.png"; | |
import B3 from "./img/3.png"; |
View shell_crudeCI
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
#!/bin/sh | |
# | |
# Description: | |
# sync with git remote and rebuild | |
# docker image if files have been modified | |
# VARS | |
_SCRIPTPATH="$(cd "$(dirname $0)"; pwd -P)" | |
_HEADPATH="${_SCRIPTPATH}/.git/refs/heads/master" | |
_MODDATE="$(stat -c %Y ${_HEADPATH})" |
View swift_asDictionary
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
/// converts any conforming struct to a Dictionary<String, String> | |
extension Encodable { | |
var asDictionary: Dictionary<String, Any>? { | |
let encoder = JSONEncoder() | |
encoder.dateEncodingStrategy = .iso8601 | |
guard let data = try? encoder.encode(self) else { return nil } | |
return (try? JSONSerialization | |
.jsonObject(with: data, options: .allowFragments)) | |
.flatMap { $0 as? [String: Any] } | |
} |
View swift_defaultVaporError
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
// Convienience function for short throws | |
func defaultVaporError( | |
_ reason: String, | |
file: String = #file, | |
function: String = #function, | |
line: UInt = #line, | |
column: UInt = #column | |
) -> Abort { | |
return Abort( | |
.badRequest, |
View swift_unwrapnil
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
/// checks a value is not nil else throws a custom error | |
public extension Future where Expectation: OptionalType { | |
func unwrapnil(or error: @autoclosure @escaping () -> Error) -> | |
Future<Expectation.WrappedType> { | |
return map(to: Expectation.WrappedType.self) { optional in | |
guard optional.wrapped != nil else { | |
throw error() | |
} |