Skip to content

Instantly share code, notes, and snippets.

View kfox's full-sized avatar

Kelly Fox kfox

  • Unity Technologies
  • Austin, TX, USA
View GitHub Profile
@kfox
kfox / README.md
Last active December 4, 2023 11:08
TCP echo server for Node.js

TCP echo server for Node.js

Usage

  1. Make sure you have a modern-ish version of Node.js installed.
  2. Type npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3
  3. Connect to it from a client, e.g. netcat or similar: nc localhost 9000
@kfox
kfox / Active Status Bar Components.png
Last active September 9, 2022 15:48
Define and set dynamic variables for iTerm2 badges and status bar components
Active Status Bar Components.png
@kfox
kfox / apply_environment_variables.sh
Created September 9, 2022 15:17
Apply environment variables to your current shell context, useful for when you SSH into a server and need your user to operate in the same context as a service already running as that user, e.g. Celery, etc.
eval $(xargs -0 -L1 -a /proc/1/environ | grep -E '^[A-Z].*' | sed -e 's/=/="/' -e 's/$/"/')
@kfox
kfox / asdf and direnv.md
Created December 2, 2021 02:26
Keeping two or more SCM accounts separate using asdf and direnv

Keeping SCM accounts separate using asdf and direnv

These instructions will enable you to use different SSH keys for different accounts across different Source Code Management (SCM) providers like GitHub, Gitlab, and others, including internal on-prem versions of those providers. You can also use this approach to switch between multiple accounts for a single SCM provider, e.g. a personal Github account and a work Github account.

Installation and Setup

  1. Install asdf by following the Getting Started instructions. asdf is the tool used to manage any number of versions of various programming language runtimes or environments. You can use asdf and the appropriate asdf plugins to replace separate tools like nvm, pyenv, rvm, etc.

  2. Install the direnv plugin for asdf per these instructions. Direnv is the bit that "automagially"

@kfox
kfox / yes_or_no.sh
Last active November 9, 2020 21:01
Bash function to prompt for yes or no with a single keypress
#!/usr/bin/env bash
affirmative_response_to() {
PROMPT=$*
IFS= read -n 1 -s -p "${PROMPT}? [Y/n]: " answer
if [ "${answer:-Y}" = "${answer#[Yy]}" ]; then
# anything other than enter, Y, or y was pressed
echo "NO"
@kfox
kfox / download-bing-wallpaper.js
Last active October 26, 2019 00:42
Download Desktop Wallpaper from Bing's "Picture of the Day" (macOS)
#!/usr/local/bin/node
const { spawnSync } = require('child_process')
const { createWriteStream, existsSync, mkdirSync } = require('fs')
const { get } = require('https')
const { join } = require('path')
const { parse: queryParser } = require('querystring')
const { parse: urlParser } = require('url')
const { HOME } = process.env
@kfox
kfox / getDateRange.js
Created August 14, 2019 23:18
Date range using moment.js
// startDate and endDate are moment() dates
// returns an array of dates in the given format
const getDateRange = (startDate, endDate, { format = 'YYYY-MM-DD' } = {}) => {
const date = startDate.clone()
const dates = []
while (date.isSameOrBefore(endDate)) {
dates.push(date.format(format))
date.add(1, 'days')
@kfox
kfox / update-slack-status-from-spotify.sh
Created March 9, 2018 02:20
Updates your Slack status with the current artist and song title in Spotify
#!/usr/bin/env bash
: "${SLACK_API_TOKEN:?Need to set SLACK_API_TOKEN environment variable}"
STATUS=$(/usr/bin/osascript <<"EOF"
if application "Spotify" is running and application "Slack" is running then
tell application "Spotify"
set currentArtist to artist of current track as string
set currentSong to name of current track as string
return currentArtist & " - " & currentSong
@kfox
kfox / colors.js
Created January 11, 2018 18:48
RGB/Hex Color Conversions in JavaScript
const convertRGBArrayToHexString = rgb =>
`#${rgb.map(color => ('0' + color.toString(16)).slice(-2)).join('')}`;
const convertHexStringToRGBArray = hex =>
hex.match(/[^#]{2}/g).map(color => parseInt(color, 16));
@kfox
kfox / gpr.sh
Last active September 9, 2022 15:31
Bash function to open a GitHub pull request from the command line
# in a git repo, compare your branch to another branch on github.com
# and optionally create a pull request
function gpr {
local repo
local branch
local title
repo=$(git ls-remote --get-url 2>/dev/null)
branch=$(git branch --no-color --contains HEAD 2>/dev/null | awk '{ print $2 }')