Skip to content

Instantly share code, notes, and snippets.

View the-vampiire's full-sized avatar
💭
ive lost a shade of color in my life. rest in peace.

the-vampiire

💭
ive lost a shade of color in my life. rest in peace.
View GitHub Profile
@the-vampiire
the-vampiire / README.md
Created July 24, 2019 00:19
generate a usable object of jwt.kid:RSA entries for verifying AWS cognito tokens

generation

$ node index.js <AWS cognito user pool ID> <relative/output/path.js>

generates the following file shape

module.exports = {
@the-vampiire
the-vampiire / extract-cookies.js
Last active November 1, 2023 23:46
express supertest / superagent utility for accessing response cookies as objects
const shapeFlags = flags =>
flags.reduce((shapedFlags, flag) => {
const [flagName, rawValue] = flag.split("=");
// edge case where a cookie has a single flag and "; " split results in trailing ";"
const value = rawValue ? rawValue.replace(";", "") : true;
return { ...shapedFlags, [flagName]: value };
}, {});
const extractCookies = headers => {
const cookies = headers["set-cookie"]; // Cookie[]
@the-vampiire
the-vampiire / medium-editor-sucks.md
Last active July 1, 2019 04:33
what do the command line notations mean

it can be frustrating but it was likely left out because writing a CLI is predicated by having seen this notation used in the documentation when using a CLI.

to answer your question though (and a bit extra because i was there once too):

when you see $ this is almost always used to indicate that everything after the $ is a single line to paste into the command line (shell) and hit enter. it will usually be in this general form

$ program command <required arg> [optional arg]
@the-vampiire
the-vampiire / clonaphile.js
Created June 10, 2019 19:45
github clone a single file or entire directory. short script with no dependencies
const fs = require("fs");
const https = require("https");
const fetch = url =>
new Promise((res, rej) => {
try {
https.get(url, res);
} catch (error) {
rej(error);
}
@the-vampiire
the-vampiire / .travis.yml
Created May 27, 2019 04:55
travis config yml - node + postgres 11 + psql commands
sudo: true
language: node_js
cache: npm
node_js: "10.15.3"
before_install:
- sudo apt-get --yes remove postgresql\*
- sudo apt-get install -y postgresql-11 postgresql-client-11
- sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf
- sudo service postgresql restart 11
- npm i
@the-vampiire
the-vampiire / .env
Last active May 24, 2019 05:44
set node process.env variables without dependencies
PORT=8008
OTHER_VAR='stuff'
@the-vampiire
the-vampiire / psql-mongodb-installation-mac.md
Last active May 12, 2019 08:02
easy mac osx postgresql and mongodb installation / usage

postgres

install

$ brew install postgresql

add shortcut function in your .bashrc or .zshrc file

$ vim ~/.zshrc

VIM commands

@the-vampiire
the-vampiire / accumulator-to-reduce.md
Last active March 4, 2024 14:24
The Accumulator Pattern

.reduce()

  • usage: occasionally
  • purpose: loops over an array and reduces the elements into a single element
    • an application of the accumulator pattern
  • returns the reduced item, one of several possibilities:
    • plain object - {}
    • Array - []
    • String - ""
    • Number - 1
@the-vampiire
the-vampiire / solution.js
Created November 12, 2018 22:19
fix for mongoose connect / disconnect using Jest
require('dotenv').config();
const mongoose = require('mongoose');
const { MONGO_URI, MONGO_DB } = process.env;
const mongo_db = mongoose.createConnection(`${MONGO_URI}${MONGO_DB}`); // moved to global space
describe('User.formSubmit() Mutation', () => {
let user;
beforeAll(async (done) => {
user = await models.User.create(userMock());
@the-vampiire
the-vampiire / before.js
Created November 12, 2018 22:15
fixing mongoose disconnect using Jest
describe('User.formSubmit() Mutation', () => {
beforeAll(async (done) => {
await mongoose.connect(`${MONGO_URI}${MONGO_DB}`, { useNewUrlParser: true });
done();
});
afterAll(async (done) => {
await mongoose.disconnect();
done();
});