Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
#
# These are the commands available in an .envrc context
#
# ShellCheck exceptions:
#
# SC1090: Can't follow non-constant source. Use a directive to specify location.
# SC1091: Not following: (file missing)
# SC1117: Backslash is literal in "\n". Prefer explicit escaping: "\\n".
# SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".
@loganlinn
loganlinn / open_url.sh
Last active September 29, 2020 20:49
bash script for opening URLs cross-platform (open, xdg-open, wslview)
#!/bin/bash
main() {
local url=${1}
case "$OSTYPE" in
darwin*)
open "${url}" ;;
mysys*)
exe /c start "${url/&/^&}" ;;
@loganlinn
loganlinn / config.yml
Last active June 30, 2022 19:25
github cli config
aliases:
pv: pr view --web
land: pr merge --squash --delete-branch
config-export: '!cat ~/.config/gh/config.yml | jq --raw-input --slurp -r "{files: {\"config.yml\": {content: .}}}" | gh api -X PATCH /gists/ba5517759522578585830221e88c1658 --input - | jq .html_url | xargs open'
clone: |-
!mkdir -p "${CODE}/$1" && gh repo clone "$1" "${CODE}/$1"
v: repo view --web
@loganlinn
loganlinn / delete-login-item.sh-session
Last active August 29, 2020 22:06
Removing macOS login item for Steam from the command-line using `osascript`
$ osascript -e 'tell application "System Events" to get the name of every login item'
Steam, Google Drive File Stream
$ osascript -e 'tell application "System Events" to delete login item "Steam"'
$ osascript -e 'tell application "System Events" to get the name of every login item'
Google Drive File Stream
@loganlinn
loganlinn / theme.json
Last active August 4, 2020 00:17
Structurizr theme for Apache Samza
{
"name": "Apache Samza",
"description": "",
"elements": [
{
"tag": "Apache Samza - Job",
"stroke": "#693cc5",
"color": "#693cc5",
"icon": "http://samza.apache.org/img/samza-just-logo-transparent.png"
}
#!/bin/bash
bazel query 'kind(".*binary rule", //...)' --output=label
@loganlinn
loganlinn / ClickHouseDialect.kt
Last active July 16, 2020 17:51
Beginnings of ClickHouse <> JetBrains/Exposed integration
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.vendors.DataTypeProvider
import org.jetbrains.exposed.sql.vendors.FunctionProvider
import org.jetbrains.exposed.sql.vendors.VendorDialect
import java.util.*
object ClickHouseDataTypeProvider : DataTypeProvider() {
override fun binaryType(): String = "String"
override fun binaryType(length: Int): String = "FixedString($length)"
override fun blobType(): String = "String"
@loganlinn
loganlinn / dodns-refresh.sh
Created June 19, 2020 07:43
BASH script for dynamic DNS for domain managed with Digital Ocean
#!/usr/bin/env bash
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Exit on error inside any functions or subshells.
set -o errtrace
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
# Turn on traces, useful while debugging but commented out by default
@loganlinn
loganlinn / Makefile
Created June 16, 2020 23:08
Base Makefile for Python project
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
help: ## displays available make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help
@loganlinn
loganlinn / compression_ratio.sql
Last active September 19, 2020 01:13
ClickHouse Queries
SELECT table,
name,
formatReadableSize(c) compressed,
formatReadableSize(u) uncompressed,
floor((c/u) * 100, 4) percent
FROM (
SELECT table,
name,
sum(data_compressed_bytes) c,
sum(data_uncompressed_bytes) u