Skip to content

Instantly share code, notes, and snippets.

View austingebauer's full-sized avatar

Austin Gebauer austingebauer

  • SpaceX
  • Redmond, WA
View GitHub Profile
@austingebauer
austingebauer / sqs.go
Created May 19, 2023 16:06
sqs reader
package main
import (
"context"
"fmt"
"log"
"runtime"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
on run {input, parameters}
if (count of input) > 0 then
tell application "iTerm"
activate
# Support editing of multiple files with vim tabs.
set filesPathsToEdit to ""
set numItems to the count of items of input
repeat with x from 1 to numItems
set posixPath to quoted form of POSIX path of item x of input
// lowercaseAlphaHasUniqueChars returns true if the passed string contains
// all unique lowercase alphabet characters.
func lowercaseAlphaHasUniqueChars(s string) bool {
var mask int
for i := 0; i < len(s); i++ {
// left shift 1 the distance of the character from 'a' times
position := 1 << (s[i] - 'a')
// if the bitwise logical AND is equal to 0,
// then we've not seen the character before
@austingebauer
austingebauer / sort_go_map_by_key.go
Last active January 6, 2020 09:11
Sorting Go Maps by Key
m := map[string]int{
"Alien Covenant": 202,
"The Imitation Game": 98,
"Good Will Hunting": 98,
"Spaceballs": 146,
}
// Place each movie's title into an slice of strings
var movies []string
for k := range m {
@austingebauer
austingebauer / sort_go_map_by_key_and_value.go
Last active January 6, 2020 08:51
Sorting Go Maps by Key and Value
m := map[string]int{
"Alien Covenant": 202,
"The Imitation Game": 98,
"Good Will Hunting": 98,
"Spaceballs": 146,
}
// Create a structure to capture the association in the map
type movie struct {
title string
@austingebauer
austingebauer / sort_go_map_by_value.go
Last active January 6, 2020 08:48
Sorting Go Maps by Value
m := map[string]int{
"Alien Covenant": 202,
"The Imitation Game": 98,
"Good Will Hunting": 98,
"Spaceballs": 146,
}
// Create a structure to capture the association in the map
type movie struct {
title string
@austingebauer
austingebauer / Makefile
Last active September 10, 2019 04:53
go-makefile
# Targets not related to individual files
.PHONY: all build test cover_func cover_html out clean vet loc run fmt test_v bench
# Build constants
BUILD_OUT_DIR = bin
BINARY_FILE_NAME = <name of binary output file for program>
MAIN_PROGRAM_FILE = main.go
TEST_COVERAGE_PROFILE = coverage.out
all: out fmt vet test_v loc build
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

https://martinfowler.com/articles/mocksArentStubs.html#UsingEasymock

  • Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
  • Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.
  • Spies are stubs that also record some information based on how they were called. One form of this might be an email service that records how many messages it was sent.
  • Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.