Skip to content

Instantly share code, notes, and snippets.

@gregberns
gregberns / wait-for-file.sh
Last active November 11, 2020 17:44
wait-for-file.sh
#!/bin/sh
# Wait for a file to exist
# Modeled off this script
# https://gist.github.com/gregberns/7e1254209860632f7a1bf9aa7c7638ee
TIMEOUT=15
QUIET=0
echoerr() {
@gregberns
gregberns / wait-for-port.sh
Last active November 3, 2020 13:25
wait-for-port.sh
#!/bin/sh
TIMEOUT=15
QUIET=0
echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
}
usage() {
@gregberns
gregberns / README.md
Last active November 12, 2020 19:23
Git: Windows switch CRLF to LF

Git: Windows switch CRLF to LF

When working on Windows with Docker, Linux, etc, your files should be standardized to LF. This command only needs to be run once:

git config --global core.autocrlf input

Source: https://stackoverflow.com/a/5834094/684966

@gregberns
gregberns / README.md
Last active September 10, 2020 23:31

Stripe Payment Example

Example of how to use Stripe.js and Node.JS libraries.

  • index.html - Client side workflow (JS)
  • index.js - Server side workflow (Node.JS)

Note: Examples are a very rough POC, so please excuse the rough style.

@gregberns
gregberns / Azure-SQL-Server-Application-Connectivity.md
Last active October 18, 2023 12:15
Azure SQL Server Application Connectivity

Tags: Azure, Managed Identity, SQL Server Access Token, Managed Service Identity, SQL Server Authentication, App Registrations

This document will outline the concepts needed to connect to a "Secure" Azure SQL Server database, both from within Azure and outside of Azure. It also provides code snippets to demonstrate what is involved.

TLDR

Today's best practice is to access SQL databases with OAuth tokens. To connect to an Azure SQL DB, you get an OAuth token, then supply it when connecting to the SQL Database. Getting the OAuth token is different whether you're accessing it in Azure or outside Azure.

Overview

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

@gregberns
gregberns / setup.sh
Last active November 12, 2021 05:53 — forked from bradp/setup.sh
New Mac Setup Script
# curl ~~Get gist raw url~~ > setup.sh
# chmod +x ~/setup.sh
# ~/setup.sh
GIT_USERNAME=________
GIT_EMAIL=________
GITHUB_ACCOUNT_NAME=________
MAC_USERNAME=________
MAC_MACHINE_NAME=________
@gregberns
gregberns / problems-parse-file.md
Last active April 9, 2020 22:02
Programming Problem - Parse File

Programming Problem - Parse File

  • Either read the "File Contents" from a file or place the text into a multi-line block
  • Parse the contents
  • Aggregate the time (last field)
  • Report of total calls
  • Report any error cases (non-200)
    • Bonus points: report what line number the error occured on

File Contents

@gregberns
gregberns / jq-filters.md
Last active March 30, 2020 22:47
jq - filter keys containing dash

jq can filter keys with dashes (-), but that requires special syntax: [\"field-name\"]

Input:

echo '{"the-long-field-name":"true"}' | jq ". | select(.[\"the-long-field-name\"] != null)"

Output:

@gregberns
gregberns / latency.txt
Created October 12, 2019 03:22 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD