Skip to content

Instantly share code, notes, and snippets.

View treyhuffine's full-sized avatar

Trey Huffine treyhuffine

View GitHub Profile
#!/usr/bin/env bash
echo "Restoring database"
psql -U postgres -c "CREATE DATABASE ${DBNAME}"
pg_restore -v -d ${DBNAME} /tmp/${FILE} > /tmp/log
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE ${DBNAME} TO postgres"
echo "Database restored successfully"
const throttle = (callback, delay) => {
let throttleTimeout = null;
let storedEvent = null;
const throttledEventHandler = event => {
storedEvent = event;
const shouldHandleEvent = !throttleTimeout;
if (shouldHandleEvent) {
const poll = ({ fn, validate, interval, maxAttempts }) => {
console.log('Start poll...');
let attempts = 0;
const executePoll = async (resolve, reject) => {
console.log('- poll');
const result = await fn();
attempts++;
if (validate(result)) {
const poll = async ({ fn, validate, interval, maxAttempts }) => {
let attempts = 0;
const executePoll = async (resolve, reject) => {
const result = await fn();
attempts++;
if (validate(result)) {
return resolve(result);
} else if (maxAttempts && attempts === maxAttempts) {
import express from 'express';
import { rootHandler, helloHandler } from './handlers';
const app = express();
const port = process.env.PORT || '8000';
app.get('/', rootHandler);
app.get('/hello/:name', helloHandler);
app.listen(port, err => {
import { Request, Response } from 'express';
interface HelloResponse {
hello: string;
}
type HelloBuilder = (name: string) => HelloResponse;
const helloBuilder: HelloBuilder = name => ({ hello: name });
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// Pass in the callback that we want to throttle and the delay between throttled events
const throttle = (callback, delay) => {
// Create a closure around these variables.
// They will be shared among all events handled by the throttle.
let throttleTimeout = null;
let storedEvent = null;
// This is the function that will handle events and throttle callbacks when the throttle is active.
const throttledEventHandler = event => {
// Update the stored event every iteration
import <PageComponentName> from './<PageComponentName>';
export default <PageComponentName>;