I use .env
files to set environment variables for projects, but those values are different in local vs test
vs prod. I also want support from my IDE and the commandline. VSCode and Intellij both support .env
files,
but if you want to point your application from local to test or prod, you have to update the .env
file, which
leaves me with an env file with lots of comments. Alternatively, you can update the IDE to point to another
env file, but that gets a little non-standard by not using .env
.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$(whoami)" != "root" ]]; then | |
echo "script must be run as root" | |
exit 1 | |
fi | |
block_size=1024 | |
swapfile="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
// whoCalledMe is a function that returns the name, fileName, and lineNumber of the caller that called function X | |
// the code doesn't check for edge cases | |
func whoCalledMe() (callerName, callerFileName string, callerLineNumber int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# custom set -x output | |
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' | |
# set -x | |
set -Eeuo pipefail | |
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | |
echo "script was executed" | |
else | |
echo "script was sourced" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go build helloworld.go | |
GOOS=windows GOARCH=amd64 go build helloworld.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log2(x): | |
if x == 0: | |
return False | |
return math.log10(x) / math.log10(2) | |
def is_power_of_two(n): | |
return math.ceil(log2(n)) == math.floor(log2(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# disable verifying developer | |
spctl --master-disable | |
defaults write com.apple.dock expose-animation-duration -float 0.1 | |
defaults write com.apple.LaunchServices LSQuarantine -bool false | |
defaults write com.apple.finder DisableAllAnimations -bool true | |
defaults write com.apple.finder ShowStatusBar -bool true | |
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true | |
defaults write com.apple.finder _FXSortFoldersFirst -bool true | |
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Create a link named json2yml and yml2json to this file. | |
If invoked as json2yml, it will convert json file to yml. | |
If invoked as yml2json, it will convert yml file to json. | |
""" | |
import sys | |
import json |