Skip to content

Instantly share code, notes, and snippets.

View brandoncruz3's full-sized avatar
🇺🇸

Brandon Cruz brandoncruz3

🇺🇸
View GitHub Profile
@hekmon
hekmon / awscliv2.sh
Last active May 23, 2023 16:02
AWS CLI v2 - install and update on a bash based linux system
#!/bin/bash -e
# https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html
echo "* Switching to tmp folder..."
cd "$(mktemp -d)"
echo
echo "* Downloading the AWS cli..."
wget -q "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -O awscliv2.zip

llimllib's five minute guide to jq

Let's say somebody just asked us to make a frontend for the CFPB's complaint search API, but we've never used it. The first thing we do is just call it, and see a giant blob:

$ curl "https://www.consumerfinance.gov/data-research/consumer-complaints/search/api/v1/geo/states?search_term=test"
{"_scroll_id":"cXVlcnlUaGVuRmV0Y2g7NTs3Mjg1ODU6ZzRIUGF4VEZScjY5Ym1fNG1HRWc3Zzs3Mjg1ODY6ZzRIUGF4VEZScjY5Ym1fNG1HRWc3Zzs2MDg4OTM6RU85cXdTM2tRa2FEbjhUVkdZamwwdzs2MDg4OTI6RU85cXdTM2tRa2FEbjhUVkdZamwwdzs2MDU2NTU6NlFSZXU3eTdTWkNhMkNsQm1mclNFUTswOw==","took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1871,"max_score":0.0,"hits":[]},"aggregations":{"product":{"doc_count":1871,"product":{"doc_count_error_upper_bound":0,"sum_other_doc_count":614,"buckets":[{"key":"Credit reporting, credit repair services, or other personal consumer reports","doc_count":373,"product":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Credit r
@dcmcand
dcmcand / grade.sh
Last active January 8, 2021 21:57
Homework grading script that adds homework to grading ami and opens visual studio code using sshfs
#!/bin/bash
# First click the link to download the zip file. It goes to ~/Downloads.
# This script requires SSHFS and VSCode to be installed
# Please replace username with your github username
# Now run grade.sh <submission number>
# Switch to ssh session
# cd <submission number>
# Evaluate! Code will be loaded using sshfs in VScode. Read code and comments in your editor. Run code in ssh session. Any edits you make in your editor will be reflected in the ssh session.
@llimllib
llimllib / mssql_to_csv.bash
Last active April 15, 2024 16:00
This is a script to convert every table in a Microsoft SQL Server database backup (.bak file) to a .csv file
#!/usr/bin/env bash
# import an MS SQL .bak backup file to an MS SQL database, then export all
# tables to csv. run this script as `import.sh <filename>`. It expects to be
# run in the same directory as the backup file.
# this is only tested on my mac (OS X Catalina). I tried to stick to posix, but
# It will probably require some tweaking for you. I hope it gives a general
# sense of what you need to do at the very least.
@quiver
quiver / eic-cli.sh
Last active June 15, 2022 21:23
simple shell script to demonstrate how EC2 Instance Connect CLI is implemented
#!/bin/bash
# simple shell script to demonstrate how EC2 Instance Connect CLI is implemented.
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html
#
# Usage
# $ bash eic-cli.sh i-1234
if [ $# -ne 1 ]; then
echo "Usage"
echo "$ bash eic-cli.sh i-1234"
@axw
axw / docker-compose.yml
Last active November 2, 2022 20:59
Docker Compose with Elastic Stack and APM Server 6.5.0
version: "2.1"
services:
apm-server:
image: docker.elastic.co/apm/apm-server:${STACK_VERSION:-6.5.0}
ports:
- "127.0.0.1:${APM_SERVER_PORT:-8200}:8200"
- "127.0.0.1:${APM_SERVER_MONITOR_PORT:-6060}:6060"
command: >
apm-server -e
-E apm-server.rum.enabled=true
const fs = require('fs');
const path = require('path');
const AWS = require('aws-sdk');
const { BUCKET_NAME, AWS_ACCESS_ID, AWS_SECRET_KEY } = process.env;
// helpers
function uploadToS3(file, name, type) {
@Slakah
Slakah / ssm-to-env.sh
Created May 14, 2018 10:20
Convert AWS SSM parameters to environment variables, used as `eval $(./ssm-to-env.sh "<ssm-path>")`
#!/bin/bash
set -uxe
# Reads the ssm path and echos out the parameters in the form
# export NAME=some-value
readonly path=$1
exec aws --region us-east-1 ssm get-parameters-by-path --no-paginate --path $path --with-decryption --query Parameters | \
jq -r 'map("\(.Name | sub("'$path'";""))=\(.Value)") | join("\n")' | \
@jeffbrl
jeffbrl / describe_instances.py
Created February 27, 2018 17:28
How to make datetime.datetime json serializable - boto3 ec2 describe_instances
# Adapted from https://stackoverflow.com/questions/35869985/datetime-datetime-is-not-json-serializable
import datetime
import json
import boto3
def datetime_handler(x):
if isinstance(x, datetime.datetime):
return x.isoformat()
@ipbastola
ipbastola / jq to filter by value.md
Last active June 5, 2024 09:07
JQ to filter JSON by value

JQ to filter JSON by value

Syntax: cat <filename> | jq -c '.[] | select( .<key> | contains("<value>"))'

Example: To get json record having _id equal 611

cat my.json | jq -c '.[] | select( ._id | contains(611))'

Remember: if JSON value has no double quotes (eg. for numeric) to do not supply in filter i.e. in contains(611)