Skip to content

Instantly share code, notes, and snippets.

View Jamie-BitFlight's full-sized avatar

Jamie Nelson Jamie-BitFlight

View GitHub Profile
@Jamie-BitFlight
Jamie-BitFlight / esbuild-add-dynamic-require-shim.mjs
Created October 19, 2023 13:43
'Dynamic require of "os" is not supported' or 'Dynamic require of "fs" is not supported' etc - can esbuild load dynamic imports? Yes!
const ESM_REQUIRE_SHIM = `
await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname=e(globalThis.__filename)),typeof globalThis.require>"u"){let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();
`;
@Jamie-BitFlight
Jamie-BitFlight / benchmark_command.sh
Created March 9, 2023 19:47
To help choose which to use to check if a command or function exists this is a benchmark to compare the execution times of `type`, `declare`, `command`, and `which` in bash version 3, bash version 5, zsh version 5.8 and zsh version 5.9
#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2296,SC2162
# Posix compliant way to check if a command exists,
# works in bash and zsh, and is used in this script
command_exists() { command -v "${@}" > /dev/null 2>&1; }
# I'm avoiding subshells in bash and zsh for performance reasons
\shopt -s lastpipe 2> /dev/null
reenable_lastpipe() { \shopt -u lastpipe 2> /dev/null; }
@Jamie-BitFlight
Jamie-BitFlight / buildspec.yml
Created April 11, 2018 22:59
Terraform module that causes aws_codebuild_project to fail
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- REPOSITORY_URI=${ecr_address}
- GITHUB_TOKEN=${gh_token}
@Jamie-BitFlight
Jamie-BitFlight / aws_codebuild_project bug
Created April 11, 2018 22:51
Terraform codebuild error output - Sensitive data swapped out
* module.staging-codepipeline.aws_codebuild_project.project: aws_codebuild_project.project: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.
Please include the following information in your report:
Terraform Version: 0.11.7
Resource ID: aws_codebuild_project.project
Mismatch reason: attribute mismatch: source.456871274.auth.#
Diff One (usually from plan): *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff{"source.~1681127761.location":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "source.~1681127761.type":*terraform.ResourceAttrDiff{Old:"", New:"CODEPIPELINE", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "source.~1681127761.auth.#":*terraform.ResourceAttrDiff{Old:"0", New:"0", NewComputed:false, NewRemoved:f
# File: /srv/salt/apache/map.yaml
{% load_yaml as osmap %}
Debian:
pkg: apache2
srv: apache2
RedHat:
pkg: httpd
srv: httpd
{% endload %}
# File: /srv/salt/apache/init.sls
{% from "apache/map.yaml" import osmap with context %}
# Filter dictionary by grain
{% set apache = salt['grains.filter_by'](osmap) %}
wait_for_refresh:
module.run:
- name: test.sleep
- length: 15
@Jamie-BitFlight
Jamie-BitFlight / autoscaling_boto.py
Created February 6, 2017 22:24 — forked from numan/autoscaling_boto.py
Example of setting up AWS auto scaling using boto API
"""
The MIT License (MIT)
Copyright (c) 2011 Numan Sachwani
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
@Jamie-BitFlight
Jamie-BitFlight / Terraform-Blue-Green-AWS.md
Created February 6, 2017 21:59 — forked from ryan0x44/Terraform-Blue-Green-AWS.md
Blue-Green AWS Auto Scaling Deployments with Terraform

A quick note on how I'm currently handling Blue/Green or A/B deployments with Terraform and AWS EC2 Auto Scaling.

In my particular use case, I want to be able to inspect an AMI deployment manually before disabling the previous deployment.

Hopefully someone finds this useful, and if you have and feedback please leave a comment or email me.

Overview

I build my AMI's using Packer and Ansible.

@Jamie-BitFlight
Jamie-BitFlight / sqs.py
Created February 1, 2017 13:24 — forked from philchristensen/sqs.py
Minimal script for sending/reading from Amazon SQS using Boto/Python.
conf = {
"sqs-access-key": "",
"sqs-secret-key": "",
"sqs-queue-name": "",
"sqs-region": "us-east-1",
"sqs-path": "sqssend"
}
import boto.sqs
conn = boto.sqs.connect_to_region(
@Jamie-BitFlight
Jamie-BitFlight / aws-ssm.sh
Created February 1, 2017 13:23 — forked from lalyos/aws-ssm.sh
Aws ssm command execution
#!/bin/bash
set -eo pipefail
if [[ "$TRACE" ]]; then
: ${START_TIME:=$(date +%s)}
export START_TIME
export PS4='+ [TRACE $BASH_SOURCE:$LINENO][ellapsed: $(( $(date +%s) - $START_TIME ))] '
set -x
fi
debug() {