This file contains hidden or 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
| function cast<T>(value: unknown, type: { new (): T }): T { | |
| if (value instanceof type) { | |
| return value as T; | |
| } | |
| if (typeof value === "object" && value !== null && "toJSON" in value) { | |
| return cast(value.toJSON(), type); | |
| } | |
| const coercedValue = type(value); |
This file contains hidden or 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 axios from "axios"; | |
| import { isDevMode } from "utils/core"; | |
| /** | |
| * Returns an identical console object that can send logs to a log server | |
| * if URL is specified | |
| * | |
| * @param remoteUrl? URL to send logs to | |
| * @returns {{debug: () => void, error: () => void, info: () => void, log: () => void, warn: () => void}} Remote console object | |
| */ |
This file contains hidden or 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 http = require("http"); | |
| const fs = require("fs"); | |
| const { networkInterfaces } = require("os"); | |
| const path = require("path"); | |
| const PORT = process.argv.length > 2 ? process.argv[2] : 8081; | |
| const LOG_PATH = process.argv.length > 3 ? process.argv[3] : "logs"; | |
| if (!fs.existsSync(LOG_PATH)) { | |
| fs.mkdirSync(LOG_PATH); | |
| } |
This file contains hidden or 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/bash | |
| # http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| ################################### | |
| # BREW uninstall script for osx_bootstrap.sh script | |
| ################################### | |
| SUDO_USER=$(whoami) |
This file contains hidden or 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/bash | |
| # http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| # inspired by | |
| # https://gist.github.com/codeinthehole/26b37efa67041e1307db | |
| # https://github.com/why-jay/osx-init/blob/master/install.sh | |
| # https://github.com/timsutton/osx-vm-templates/blob/master/scripts/xcode-cli-tools.sh |
This file contains hidden or 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
| # Install dependencies only when needed | |
| FROM node:16-alpine AS deps | |
| # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | |
| RUN apk add --no-cache libc6-compat | |
| WORKDIR /app | |
| COPY package*.json ./ | |
| RUN npm ci --only=production | |
| # Rebuild the source code only when needed | |
| FROM node:16-alpine AS builder | |
| WORKDIR /app |
This file contains hidden or 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
| #include <boost/asio.hpp> | |
| class TcpServer | |
| { | |
| public: | |
| TcpServer(boost::asio::io_service& io_service, short port) | |
| : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)) | |
| { | |
| StartAccept(); | |
| } |
This file contains hidden or 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
| /** | |
| * set interval react hook | |
| */ | |
| import React, { useState, useEffect, useRef } from 'react'; | |
| function useInterval(callback, delay) { | |
| const savedCallback = useRef(); | |
| // Remember the latest callback. | |
| useEffect(() => { |
This file contains hidden or 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
| /** | |
| * Example local storage custom hook | |
| * | |
| * Usage: | |
| * Same as useState hook | |
| */ | |
| import { useState, useEffect } from 'react'; | |
| function getSavedValue(key, initialValue) { | |
| const savedValue = localStorage.getItem(key); |
This file contains hidden or 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
| /** | |
| * Usage: | |
| * | |
| * export default function MyComponent() { | |
| * const customVariable = useCustom(); | |
| * const changeCustomVarible = useCustomUpdate(); | |
| * // Call change custom variable function to change value to reflect to all other places | |
| * } | |
| * <CustomProvider><MyComponent /></CustomProvider> | |
| */ |
NewerOlder