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 / inline_svg.js.coffee
Created November 25, 2014 16:30
Replace SVG images loaded via img tags with inlined svg elements
inline_svg_images = (svg) ->
svg_selector = if svg? and $(svg)? then svg else 'img.svg'
$(svg_selector).each ->
$img = $(@)
$.get $img.attr('src'), (data) ->
$svg = $(data).find 'svg'
for attribute in [ 'id', 'class', 'height', 'width' ]
@kfox
kfox / gh.sh
Last active June 1, 2017 17:50
Bash function to open a GitHub repo from the command line
# this should be added to or loaded by your .bashrc
# usage: gh
# gh <repo_name>
# gh <user>/<repo_name>
function gh {
repo="$1"
if [ -z "$repo" ]; then
# if no argument provided, then get the
@kfox
kfox / excuse.sh
Last active June 9, 2017 21:06
Generates a plausible excuse when you need one
#!/bin/bash
# brew install httpie pup recode
# usage: git commit -m "$(excuse.sh)"
http http://programmingexcuses.com/ | pup 'center a text{}' | recode html..ascii
@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 }')
@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 / 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 / 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 / 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 / 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 / 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"