Skip to content

Instantly share code, notes, and snippets.

View smartwatermelon's full-sized avatar
🏠
Working from home permanently

Andrew Rich smartwatermelon

🏠
Working from home permanently
View GitHub Profile
@smartwatermelon
smartwatermelon / bounce-synergy.sh
Last active May 8, 2018 00:45
reset the Synergy 1.x server and client processes after sleep/wake
#!/bin/bash -x
## this runs on the Synergy *server* Mac and assumes the *client* is connected via bridge0
## server: 169.254.168.87 ; client: 169.254.168.86
## use e.g. ControlPlane to run the script on wake
## brew install terminal-notifier
## use ssh-copy-id to enable passwordless ssh from the server to the client
## add to /etc/sudoers.d/youruser e.g. $YOUR_USER ALL=(ALL) NOPASSWD: /usr/bin/killall,/sbin/ifconfig
## replace $YOUR_USER with your username on the client
echo "bouncing Synergy..." | terminal-notifier -title controlplane
@smartwatermelon
smartwatermelon / start-synergy
Last active July 21, 2022 05:31
start-synergy: Wait for connection to counterpart, then start Synergy.
#!/usr/local/bin/bash
set -eux -o pipefail
## this runs on both the client and server Mac
## configure CLIENT and SERVER appropriately
## brew install terminal-notifier
## use with e.g. ControlPlane (launch this script when Thunderbolt network connection becomes active)
CLIENT=my-client-mac.local
SERVER=the-server-mac.local
@smartwatermelon
smartwatermelon / days-countdown.sh
Last active August 13, 2019 15:52
days-countdown: generate a png showing the number of days remaining until a specified date
#!/usr/bin/env bash
#####
# usage: just run days-countdown.sh to get a countdown until the default date of October 25
# or specify "from" (e.g. today) and "to" (your target date) in this terrible, terrible format:
# days-countdown.sh "$(gdate)" "$(gdate -d 25-Dec)"
# result is ~/tmp/days-countdown.png
# the png's text color is the hex interpretation of the three-digit days-remaining number ;)
# I use Geektool to position the png on my desktop, and run the script in crontab every hour:
## 44 * * * * /Users/andrewrich/Documents/scripts/days-countdown.sh >/dev/null 2>&1
#
@smartwatermelon
smartwatermelon / .profile
Last active September 1, 2019 00:39
My current .profile, annotated
## path
export PATH="/usr/local/opt/ruby/bin:$PATH"
## prompt
export PS1='\h:\W \u\$ '
## aliases
# /etc/sudoers.d/andrewrich: andrewrich ALL=(ALL) NOPASSWD: /sbin/ifconfig
alias bouncewifi='sudo ifconfig en0 down && sudo ifconfig en0 up && ifconfig en0'
alias brewup='/usr/local/etc/brewupdate.sh'
@smartwatermelon
smartwatermelon / logicgate.sh
Created May 15, 2020 22:50
Logic Gates in bash, based on @cassidoo's interview question from November 11, 2019
#!/usr/bin/env bash
set -eu -o pipefail
about () {
cat <<EOF
$( basename "$0" ) by Andrew Rich <[email protected]>
Based on @cassidoo's interview question from https://tinyletter.com/cassidoo/letters/be-curious-read-widely-try-new-things-what-people-call-intelligence-just-boils-down-to-curiosity-aaron-swartz
Definition and table of logic gates: https://whatis.techtarget.com/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR
EOF
@smartwatermelon
smartwatermelon / rps.sh
Last active August 16, 2020 03:19
Rock, Paper, Scissors in bash, based on @cassidoo's interview question from November 24, 2019
#!/usr/bin/env bash
set -eu -o pipefail
# shellcheck source=/Users/andrewrich/etc/functions.sh
. "$HOME/etc/functions.sh"
readonly R="ROCK" P="PAPER" S="SCISSORS"
about () {
cat <<EOF
$( basename "$0" ) by Andrew Rich <[email protected]>
Based on @cassidoo's interview question from https://buttondown.email/cassidoo/archive/be-careful-with-your-words-once-they-are-said/
@smartwatermelon
smartwatermelon / htmlvalidator.sh
Last active October 19, 2020 23:11
htmlValidator: @cassidoo's 2020-10-19 newsletter interview question
#!/bin/bash
function htmlValidator ()
{
if xmllint --noout --nowarning - 2> /dev/null <<< "$1"; then
echo "valid";
else
echo "not valid";
fi
}
@smartwatermelon
smartwatermelon / sameDigits.sh
Created May 10, 2021 22:45
@cassidoo's Interview question of the week for May 10, 2021
#!/usr/bin/env bash
set -eu -o pipefail
if [ $# -eq 0 ] || [ -n "$(printf '%s\n' "$1" | sed 's/[0-9]//g')" ]; then
echo "$(basename $0): enter a positive integer"
exit 1
else
echo "$(basename $0): you entered $1"
fi
@smartwatermelon
smartwatermelon / find_meeting.rb
Last active May 23, 2021 03:45
@cassidoo's Interview question of the week for May 16, 2021
#!/usr/bin/env ruby
=begin
This week’s question:
Given a list of people with their names and the time slots when they are available in a given week, and a meeting length, return the first meeting time available (if possible). Format the input however you’d like to receive it!
=end
=begin
Andrew Rich [email protected]
https://projectinsomnia.com/
=end
@smartwatermelon
smartwatermelon / lonelyNumber.sh
Created June 7, 2021 16:55
@cassidoo's Interview question of the week for June 6, 2021
#!/usr/bin/env bash
set -eu -o pipefail
# lonelyNumber.sh
# @cassidoo 2021-06-06
# Given three numbers, return their product. But, if one of the numbers is the same as
# another, it does not count: If two numbers are similar, return the lonely number. If all
# numbers are same, return 1.
if [ $# -ne 3 ] || ! ([[ $1 =~ ^[0-9]+$ ]] && [[ $2 =~ ^[0-9]+$ ]] && [[ $3 =~ ^[0-9]+$ ]]); then