Skip to content

Instantly share code, notes, and snippets.

View adamelliotfields's full-sized avatar

Adam Fields adamelliotfields

View GitHub Profile
@adamelliotfields
adamelliotfields / server.ts
Last active February 3, 2019 19:03
Node HTTP Server Destroy Sockets
/*!
* Destroy all open connections so a server can close.
* Inspired by https://github.com/marten-de-vries/killable
*/
import http from 'http';
import { Socket } from 'net';
// Set of open sockets
const sockets: Set<Socket> = new Set();
@adamelliotfields
adamelliotfields / wrap.js
Last active July 25, 2023 23:39
Express Async Handler Wrapper to Prevent Unhandled Promise Rejections
/**
* @template {(...args: any[]) => Promise<any>} T
* @param {T} fn
* @returns {(...args: Parameters<T>) => Promise<ReturnType<T>|void>}
*/
export const wrap = (fn) => (...args) => fn(...args).catch(args[2]);
@adamelliotfields
adamelliotfields / MemoryStore.ts
Last active February 3, 2019 17:15
Express Session Memory Store
import { BaseMemoryStore, Store } from 'express-session';
export class MemoryStore extends Store implements BaseMemoryStore {
/**
* A key/value mapping of session IDs to serialized (stringified) sessions.
*/
private readonly sessions: Map<string, string>;
public constructor() {
super();
@adamelliotfields
adamelliotfields / docker-compose.yml
Created February 10, 2019 22:39
Docker Compose Mongo with Mongo Express
version: "3.5"
services:
mongo:
image: mongo:latest
container_name: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
ports:
@adamelliotfields
adamelliotfields / supervisord.conf
Created March 1, 2019 03:28
Supervisord Example
[unix_http_server]
file=/tmp/supervisor.sock
;username=user
;password=pass
[inet_http_server]
port=*:9001
;username=user
;password=pass
@adamelliotfields
adamelliotfields / select.sql
Last active March 24, 2019 20:08
SQL Select Tables without Primary Key in Database
SELECT tables.table_schema, tables.table_name
FROM tables
LEFT JOIN key_column_usage AS kcu ON (
kcu.table_name = tables.table_name AND
kcu.constraint_schema = tables.table_schema AND
kcu.constraint_name = 'PRIMARY')
WHERE tables.table_schema = @db_name AND
kcu.constraint_name IS NULL;
@adamelliotfields
adamelliotfields / index.js
Last active March 24, 2019 21:01
Nodemailer v0.7 Gmail Example
const nodemailer = require('nodemailer');
const transport = nodemailer.createTransport('smtp', {
auth: {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS,
},
});
transport.sendMail({
@adamelliotfields
adamelliotfields / docker-compose.yaml
Created May 20, 2019 00:10
Docker Compose Nextcloud
version: '3.5'
services:
redis:
image: 'redis:5.0.5'
container_name: redis
ports:
- '0.0.0.0:6379:6379'
networks:
- nextcloud
@adamelliotfields
adamelliotfields / index.scss
Created July 27, 2019 20:50
Bootstrap 3 Sass Grid
$grid-columns: 12;
$grid-gutter-width: 30px;
$grid-breakpoints: (
xs: 0,
sm: 768px,
md: 992px,
lg: 1200px,
);
$screen-sm-min: map-get($grid-breakpoints, "sm");
@adamelliotfields
adamelliotfields / reset_iptables.sh
Last active November 12, 2019 03:47
Reset iptables / ip6tables
#!/bin/bash
set -e
if [ "$(id -u)" != '0' ]; then
SUDO=sudo
fi
policies=(
'INPUT'