Skip to content

Instantly share code, notes, and snippets.

View gjohnson's full-sized avatar

Garrett Johnson gjohnson

View GitHub Profile
@gjohnson
gjohnson / tips.md
Last active December 11, 2024 15:53

In JavaScript, when using a fetch() call that results in an exception (e.g., a network error), only the catch() block is executed, not the then() block. Here's how it works in detail:

  1. If the fetch() request succeeds in making the HTTP request (even if the response is an error, such as a 404 or 500 status code), it does not reject the promise. The then() block is called, and you need to check the response.ok property or response.status to determine if the response was successful.

  2. If the fetch() call fails completely due to a network error, DNS failure, or other reasons that prevent it from connecting to the server, the promise is rejected, and the catch() block is executed.
fetch('https://example.com/api/data')
 .then(response => {
@gjohnson
gjohnson / test.js
Last active September 9, 2024 18:40
const mongoose = require('mongoose');
mongoose.connect('mongodb://admin:admin@mongodb:27017/').catch(err => {
console.error('Error connecting to MongoDB:', err);
}).then(() => {
console.log('Connected to MongoDB');
});
import * as cdk from 'aws-cdk-lib';
import * as glue from 'aws-cdk-lib/aws-glue';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
class GlueWorkflowStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@gjohnson
gjohnson / glue-stack.ts
Created October 4, 2023 12:09
Example Glue CDK app
import * as cdk from 'aws-cdk-lib';
import * as glue from 'aws-cdk-lib/aws-glue';
import * as redshift from 'aws-cdk-lib/aws-redshift';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as core from 'aws-cdk-lib/core';
export class YourCdkStack extends core.Stack {
constructor(scope: core.Construct, id: string, props?: core.StackProps) {
super(scope, id, props);
@gjohnson
gjohnson / resize.sh
Created February 23, 2022 15:49
Resize script for Cloud9 based workshops.
#!/bin/bash
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-40}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/')
# Get the ID of the Amazon EBS volume associated with the instance.
@gjohnson
gjohnson / notes.md
Last active December 25, 2018 04:38
AMQP error handling.

Producer

Simple producer, nothing wrong here...

var amqp = require('amqp');

var connection = amqp.createConnection({
  port: 5672, host: 'localhost'
});
@gjohnson
gjohnson / example.js
Created December 20, 2012 22:33
mongoose revision plugin
var mongoose = require('mongoose')
, revision = require('..')
, Schema = mongoose.Schema;
mongoose.connect('localhost', 'sandbox');
var schema = new Schema({
title: String,
content: String
});
package main
import (
_ "context"
"flag"
"fmt"
"github.com/go-kit/kit/log"
"net/http"
"net/http/pprof"
"os"
docker run --rm -it -v "${GOPATH}":/gopath -v "$(CURDIR)":/app -e "GOPATH=/gopath" -w /app golang:1.7 sh -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o app'

Keybase proof

I hereby claim:

  • I am gjohnson on github.
  • I am gjj (https://keybase.io/gjj) on keybase.
  • I have a public key whose fingerprint is 407C A136 5E34 F542 4EF5 2A92 89A7 7D5B 4490 D956

To claim this, I am signing this object: