Skip to content

Instantly share code, notes, and snippets.

@bitdivine
bitdivine / dapp-url
Last active July 30, 2022 04:12
dfinity ic dapp url
DAPP_NAME="${1}"
export DFX_NETWORK
export DAPP_NAME
jq -r '.networks[env.DFX_NETWORK].config.HOST' dfx.json | awk -F '://' -v canister_id="$(jq -r .[env.DAPP_NAME][env.DFX_NETWORK] canister_ids.json)" '{print $1 FS "." canister_id $2}'
#!/usr/bin/env bash
set -euo pipefail
: Move to the repo root, assuming this is installed at ./scripts/dfx-start-join
cd "$(dirname "$(realpath "$0")")/.."
help_text() {
cat <<-EOF
Joins an existing locally running dfx server.
@bitdivine
bitdivine / gitignore2dockerignore
Last active January 31, 2022 02:02
Convert .gitignore files in a repo into a dockerignore file
git ls-files --recurse-submodules --full-name |\
awk -F/ '($(NF) == ".gitignore")' |\
xargs -I{} awk -vx="{}" 'BEGIN{gsub(/[.]gitignore$/,"", x)}/^ *#/{print;next}/./{print x$0}' "{}" |\
awk 'BEGIN{print ".git"}{print}'
@bitdivine
bitdivine / mkuser
Created April 25, 2021 00:20
Create a user with sudo and ssh keys
set -eux
user="$1"
github_user="$2"
mkdir -p "users"
rm -fr "users/${user}"
cp -R /etc/skel "users/${user}"
mkdir -p "users/${user}/.ssh"
chmod 700 "users/${user}/.ssh"
curl --fail "https://github.com/${github_user}.keys" > "users/${user}/.ssh/authorized_keys2"
on: [push, pull_request]
name: Code Coverage
jobs:
tarpaulin:
name: Rust Tarpaulin
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
@bitdivine
bitdivine / cargo-test-faster.sh
Last active November 20, 2020 01:48
Fast failing cargo tests - runs new, recently broken and fast tests first
set -eu
touch ,logtimes
FLAGS="${FLAGS:-}"
all_tests_with_dummy_times() {
set -x
cargo test $FLAGS -- --list --format terse | awk '/: test/{print "0s", "new", substr($1, 1, length($1)-1)}'
}
test_times() {
@bitdivine
bitdivine / prepare-commit-msg
Created June 18, 2020 12:17
Conventional commit git hook; enforces the format of commit messages.
#!/bin/bash
set -euo pipefail
COMMIT_MESSAGE="$(head -n1 "$1")"
echo "$COMMIT_MESSAGE" | gawk '
BEGIN{
types["feat"]=0;
types["fix"]=0;
types["doc"]=0;
types["text"]=0;
types["style"]=0;
@bitdivine
bitdivine / bluetooth-screen-lock
Last active August 12, 2022 06:49
Lock Apple Mac screen when bluetooth device, such as a phone, goes out of range
# MAC=xx-xx-xx-xx-xx-xx
MAX_IDLE=10
while true ; do
idle=$(/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/awk '/HIDIdleTime/ {print int($NF/1000000000); exit}')
if (( idle < MAX_IDLE )) ; then
sleep $(( MAX_IDLE - idle + 1 ))
else
blueutil --inquiry 4 | grep -E "$MAC" || {
echo "Locking screen..."
pmset displaysleepnow
@bitdivine
bitdivine / check-local-dns.sh
Created April 26, 2019 12:17
Check that the DNS server provided by DHCP is working
dig +short @$(ipconfig getoption en0 server_identifier) google.com
@bitdivine
bitdivine / keybase.md
Created March 21, 2019 00:20
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object: