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
function onlyUnique<T>(value: T, index: number, self: T[]) { | |
return self.indexOf(value) === index; | |
} | |
function onlyNonUnique<T>(value: T, index: number, self: T[]) { | |
return self.indexOf(value) !== self.lastIndexOf(value); | |
} | |
const data = []; |
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
export type Procedure = (...args: any[]) => void; | |
function makeSync<F extends Procedure>( | |
func: F, | |
): (this: ThisParameterType<F>, ...args: Parameters<F>) => void { | |
let inProgress = false; | |
return async function(this: ThisParameterType<F>, ...args: Parameters<F>) { | |
const context = this; |
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 { useState, useEffect } from 'react'; | |
import { useLocation } from 'react-router-dom'; | |
type Params<T extends string> = { [key in T]: string }; | |
// Returns object that contains all path query parameters listed in the `names` argument. | |
// If any path query parameters from the `names` is missing in the path, the returned object is undefined. | |
function useQueryParams<T extends string>(...names: T[]) { | |
const location = useLocation(); |
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
export function notEmpty<T>(value: T | null | undefined): value is T { | |
return value !== null && value !== undefined; | |
} |
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 { exec, execFile } from 'child_process'; | |
function executeCommand(command: string): Promise<string> { | |
return new Promise((resolve, reject) => { | |
exec(command, (error, stdout) => { | |
if (error) { | |
return reject(error); | |
} | |
return resolve(stdout); | |
}); |
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
#!/usr/bin/env node | |
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager'); | |
const secretManager = new SecretManagerServiceClient(); | |
async function getSecret(name) { | |
const [secretVersion] = await secretManager.accessSecretVersion({ | |
name: `${name}/versions/latest`, | |
}); |
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 { | |
RequestHandler, | |
Request, | |
Response, | |
NextFunction, | |
Router, | |
} from 'express'; | |
export enum APIVersion { | |
v0 = 'v0', |
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 | |
DIR=$1 | |
export BUCKET=$2 | |
cd $DIR | |
ls -l ./ | tr -s ' ' | cut -d' ' -f9 | | |
tr ' ' '\n' | | |
xargs -n 1 -I{} gsutil -h "Cache-Control:no-cache, max-age=0" cp {} gs://$BUCKET |
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
#!/usr/bin/env node | |
const esbuild = require('esbuild'); | |
const path = require('path'); | |
const makeAllPackagesExternalPlugin = { | |
name: 'make-all-packages-external', | |
setup(build) { | |
const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../" | |
build.onResolve({ filter }, args => ({ path: args.path, external: true })); |
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 | |
docker run -p 8000:80 \ | |
-e GOOGLE_APPLICATION_CREDENTIALS=/path/to/creds/in/container.json \ | |
-v $GOOGLE_APPLICATION_CREDENTIALS:/path/to/creds/in/container.json \ | |
gcr.io/$PROJECT_ID/$IMAGE_ID |
OlderNewer