Skip to content

Instantly share code, notes, and snippets.

View pbredenberg's full-sized avatar
🖖

Paul Bredenberg pbredenberg

🖖
View GitHub Profile
@pbredenberg
pbredenberg / asyncQueue.ts
Created April 26, 2023 15:22
In memory async queue in typescript
type Callback<T> = () => Promise<T>
export type AsyncQueue<T = void> = {
push: (task: Callback<T>) => Promise<T>
flush: () => Promise<void>
size: number
}
/**
* Ensures that each callback pushed onto the queue is executed in series.
@pbredenberg
pbredenberg / .zshrc
Created November 17, 2020 14:51 — forked from callumlocke/.zshrc
ZSH function to auto-switch to correct Node version
####
# ZSH function to auto-switch to correct Node version
# https://gist.github.com/callumlocke/30990e247e52ab6ac1aa98e5f0e5bbf5
#
# - Searches up your directory tree for the closest .nvmrc, just like `nvm use` does.
#
# - If you are already on the right Node version, IT DOES NOTHING, AND PRINTS NOTHING.
#
# - Works correctly if your .nvmrc file contains something relaxed/generic,
# like "4" or "v12.0" or "stable".
import { Connection, ConnectionManager, ConnectionOptions, createConnection, getConnectionManager } from 'typeorm'
import { inspect } from 'util'
import { SnakeNamingStrategy } from './SnakeNamingStrategy'
import 'envkey'
/**
* Database manager class
*/
export class Database {
private connectionManager: ConnectionManager
import { Connection, ConnectionManager, ConnectionOptions, createConnection, getConnectionManager } from 'typeorm'
import { inspect } from 'util'
import { SnakeNamingStrategy } from './SnakeNamingStrategy'
import 'envkey'
/**
* Database manager class
*/
export class Database {
private connectionManager: ConnectionManager
@pbredenberg
pbredenberg / function.ts
Created May 16, 2020 01:13 — forked from kvarela/function.ts
Sample function connecting to typeorm
import * as lambda from 'aws-lambda'
import connectionOptions from '../db/ConnectionOptions'
import { Connection } from 'typeorm'
import { Database } from '../db'
import { User } from '../entities'
import 'reflect-metadata'
import 'envkey'
exports.api = async (event: lambda.APIGatewayProxyEvent, serverlessContext: lambda.Context) => {
// This enables Lambda function to complete
@pbredenberg
pbredenberg / app.ts
Created May 15, 2020 18:22 — forked from Wintereise/app.ts
TypeORM broken on aws-lambda runtime
import "reflect-metadata";
import { APIGatewayEvent, Context } from "aws-lambda";
import { BaseEntity, Column, Connection, Entity, getConnectionManager, PrimaryColumn } from "typeorm";
import v4 = require("uuid/v4");
@Entity()
export class TData extends BaseEntity {
@PrimaryColumn()
public id: string;
@pbredenberg
pbredenberg / deploy_pm2_app.sh
Last active January 30, 2020 17:25
Script to restart/re-deploy a pm2-managed node.js application remotely over ssh via non-interactive shell.
#!/bin/bash
# Put this in your deployment user's home directory. Make sure nvm is installed for that user.
# Execute this file from the directory where the pm2 app package.json resides.
# Example: ssh user@server "cd /path/to/app/root && /home/user/deploy_pm2_app.sh pm2_app_name"
NVM_DIR=/home/username/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
## Run whatever you need to do to prepare for restart:
@pbredenberg
pbredenberg / wifi-connect.sh
Created September 11, 2019 15:27
macOS WiFi connection script
#!/bin/bash
WIFI_INTERFACE=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}')
NETWORK_SSID=YourNetworkSSID
# You can set $NETWORK_PASSWORD in your profile if you don't want to be prompted for it every time.
PASSWORD=$NETWORK_PASSWORD
if [ -z ${PASSWORD+x} ]; then
echo "Give me the password for $NETWORK_SSID immediately!"

Keybase proof

I hereby claim:

  • I am pbredenberg on github.
  • I am pbredenberg (https://keybase.io/pbredenberg) on keybase.
  • I have a public key ASAjL5GzWlPWVGTlJdoAquobzfDWAdMD6W1RamkG5yLocQo

To claim this, I am signing this object:

@pbredenberg
pbredenberg / lemp-macos.md
Created August 20, 2019 14:03
Setup steps to install LEMP stack on macOS

Install homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install xcode command line tools

xcode-select --install

PHP 7.2

brew install php@7.2