Skip to content

Instantly share code, notes, and snippets.

View rpivo's full-sized avatar

Ryan Pivovar rpivo

  • New York City, NY
View GitHub Profile
@rpivo
rpivo / index.md
Created February 20, 2021 03:59
List Globally Installed NPM Packages (Top Level)

List Globally Installed NPM Packages (Top Level)

npm ls -g --depth=0

@rpivo
rpivo / index.md
Last active February 21, 2021 14:11
Altering a Bind Mount in a Named Docker Container From a Separate Terminal

Altering a Bind Mount in a Named Docker Container From a Separate Terminal

docker run --name bundler  -dt -v path/to/real/folder:/docker-folder amazonlinux

This first command starts a Docker container named bundler with a volume (-v) that is a bind mount between the real folder at path path/to/real/folder and the virtual Docker folder at docker-folder.

It creates the container from the amazonlinux image.

This also runs the container with the -d and the -t flags, which means that the container is running in detached mode (-d), and also with an attached TTY (-t), so it will accept commands that you give it.

@rpivo
rpivo / index.md
Created February 25, 2021 16:52
Truncating a Float in Python

Truncating a Float in Python

from decimal import Decimal as D, ROUND_DOWN

f = 1.2345

print(
  D(f).quantize(D('0.01'), rounding=ROUND_DOWN) # 1.23
)
@rpivo
rpivo / index.md
Last active March 2, 2021 22:56
Deeply Merge Objects with Recursive Reduce in JavaScript

Deeply Merge Objects with Recursive Reduce in JavaScript

function recursiveMerge(...objects) {
  function byMerger(newObj, obj) {
    if (!Object.keys(newObj).length) return obj

    for (const [key, value] of Object.entries(obj)) {
      if (newObj[key] && typeof newObj[key] !== 'string' && Object.keys(newObj[key]).length)
 newObj[key] = recursiveMerge(newObj[key], value)
@rpivo
rpivo / index.md
Last active March 6, 2021 23:52
If/Then Conditional Statements in Shell Scripts

If/Then Conditional Statements in Shell Scripts

The example below checks if the folder at bind-mount/package is empty.

if [ -z "$(ls -A bind-mount/package)" ]; then
  # do a thing here
else
  # else do a thing here
fi
@rpivo
rpivo / index.md
Last active March 8, 2021 03:00
Creating a GitHub Action That Forwards Commits to an AWS CodeCommit Repo

Creating a GitHub Action That Forwards Commits to an AWS CodeCommit Repo

You can use pixta-dev's repository-mirroring-action to forward commits to an AWS CodeCommit repo.

  1. You'll first need to create an AWS CodeCommit repo.
  2. You'll need to generate an SSH key pair (or have one ready to use).
  3. There is a section called SSH Keys for AWS CodeCommit inside the AWS IAM dashboard. Here, you'll upload the public portion of the SSH key pair.
  4. Copy the SSH Key ID that gets generated in the AWS IAM dashboard after you've uploaded the SSH public key.
  5. In the repo where the GitHub Action will be active, create a secret called CODECOMMIT_SSH_PRIVATE_KEY_ID. Paste in the SSH Key ID as the value of this secret and save it.
  6. Get the SSH URL of the CodeCommit repo. You can get this from the main CodeCommit dashboard where you see all your repos. This is the SSH URL that you would use to clone the repo via SSH.
@rpivo
rpivo / index.md
Last active March 11, 2021 03:22
Getting a File's Contents in Node

Getting a File's Contents in Node

const fs = require('fs')

function getFileContents(file) {
  try {
    return fs.readFileSync(file, 'utf8')
  } catch (e) {
 console.log('error in function getFileContents', e)
@rpivo
rpivo / index.md
Last active March 13, 2021 14:10
Adding Comments & Descriptions in GraphQL
@rpivo
rpivo / index.md
Created March 13, 2021 14:08
Getting a GitHub Action to Only Trigger on a Specific Branch

Getting a GitHub Action to Only Trigger on a Specific Branch

The example below runs on push and delete actions on only the main branch for the repo.

name: Example
on:
  push:
    branches:
 - main
@rpivo
rpivo / index.md
Last active March 18, 2021 00:35
How to Make a GraphQL API Call to AWS AppSync With Postman

How to Make a GraphQL API Call to AWS AppSync With Postman

  1. Create a new API call.
  2. Set the request type to POST.
  3. In the AppSync console, copy the API URL for the API you want to interact with. This is found in the Settings for the API.
  4. Inside the Headers tab for the API call, add an x-api-key header, and set the value to the API key for the API. This is found in the Settings for the API.
  5. Add another header called Content-Type, and set the value to application/graphql.
  6. In the Body tab, add the GraphQL query, and set the query type to GraphQL radio button.