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 / mongo-atlas-whitelist-entrypoint.md
Last active March 26, 2024 08:26
docker entrypoint to automatically whitelist mongo atlas IP

why

mongo atlas provides a reasonably priced access to a managed mongo DB. CSPs where containers are hosted charge too much for their managed mongo DB. they all suggest setting an insecure CIDR (0.0.0.0/0) to allow the container to access the cluster. this is obviously ridiculous.

this entrypoint script is surgical to maintain least privileged access. only the current hosted IP address of the service is whitelisted.

related searches, hope this shows up for you

  • "How to connect to mongodb atlas cluster to container app service EKS ECS cloudrun compute engine"
  • "mongodb atlas cluster access without using whitelist 0.0.0.0"
@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 / 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 / FIX_MY_NAME.sh
Last active March 25, 2023 22:19
Django + PostgreSQL Google Cloud Flexible App Engine deployment templates [app.yaml, settings.py, Conda environment loader shell scripts]
# when you call conda deactivate this script will be executed
# removes the environment variables automatically on environment deactivation
# this goes in /anaconda3/envs/ENVIRONMENT-NAME/etc/conda/deactivate.d
# CHANGE FILE NAME TO 'env_vars.sh' (gist requires unique file names...)
unset DEBUG SECRET_KEY DB_HOST DB_PORT DB_NAME DB_USER DB_PASSWORD STATIC_URL
@the-vampiire
the-vampiire / interface-ids.js
Last active May 11, 2022 14:59
ERC165 interface IDs (ERC721 etc)
const INTERFACE_IDS = {
ERC165: '0x01ffc9a7',
ERC721: '0x80ac58cd',
ERC721Enumerable: '0x780e9d63',
ERC721Metadata: '0x5b5e139f',
ERC1155: '0xd9b67a26',
ERC1155Receiver: '0x4e2312e0',
AccessControl: '0x7965db0b',
AccessControlEnumerable: '0x5a05180f',
Governor: '0xbf26d897',
@the-vampiire
the-vampiire / .test.env
Last active February 2, 2022 19:54
algorand sandbox global jest setup consistent test accounts
# using algorand sandbox
# https://github.com/algorand/sandbox
ALGORAND_ALGOD_API_BASE_URL=http://localhost
ALGORAND_ALGOD_API_PORT=4001
ALGORAND_ALGOD_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ALGORAND_KMD_API_BASE_URL=http://localhost
ALGORAND_KMD_API_PORT=4002
ALGORAND_KMD_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@the-vampiire
the-vampiire / 00-https-single-instance.yaml
Created September 2, 2019 10:13
AWS EB elastic beanstalk single instance nodejs nginx SSL/HTTPS ebextensions config file
# REQUIREMENTS
# set the following configuration environment variables at: configuration -> software -> modify -> environment variables
# CERT_EMAIL: the email address used for registering the cert
# CERT_DOMAIN: the domain to create a cert for
# EB environment URL (listed at the top of the environment page) or a custom domain, custom domains must have a DNS CNAME record pointing to the EB environment URL
# !! MUST NOT have "http://" prefix or the trailing "/" at the end !!
# EXAMPLES
@the-vampiire
the-vampiire / 1-dom-counter.js
Last active December 9, 2020 18:57
react basics (DOM, class-based, function with hooks)
// vanilla DOM approach: you manage state (externally) and updating the DOM manually
// state must be managed externally in a variable
const state = { count: 0 };
const counterDiv = document.createElement("div");
const counterSpan = document.createElement("span");
counterSpan.textContent = `The count is: ${state.count}`;
@the-vampiire
the-vampiire / mapAttributes.js
Last active March 20, 2020 05:06
5 line Apollo Server GraphQL Type resolver efficiency proof of concept
const mapAttributes = (model, { fieldNodes }) => {
// get the fields of the Model (columns of the table)
const columns = new Set(Object.keys(model.rawAttributes));
const requested_attributes = fieldNodes[0].selectionSet.selections
.map(({ name: { value } }) => value);
// filter the attributes against the columns
return requested_attributes.filter(attribute => columns.has(attribute));
};
@the-vampiire
the-vampiire / table-foreign.stub
Created January 30, 2020 03:54
knex-stub-sample
/* eslint func-names:0 */
exports.up = function (knex) {
return knex.schema.createTable("", (table) => {
table.increments();
table
.integer("") // foreign_key_name
.unsigned()
.notNullable()
.references("") // table.primary_key_name