Skip to content

Instantly share code, notes, and snippets.

@wibed
wibed / simplewebsocketstore.swift
Created October 20, 2023 13:44
simple websocket store
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 {
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");
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";
#!/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})"
/// 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] }
}
// 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,
/// 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()
}