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 / 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 / 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 / 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 / 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 / sum_exists.rb
Created March 5, 2014 04:07
Find all number pairs in a Ruby array that add up to a given number
#!/usr/bin/env ruby
numbers = [2, 6, 4, 8, 8, 9]
sum = ARGV.empty? ? 10 : ARGV.first.to_i
def sum_exists(numbers, sum)
Array(numbers).combination(2).find_all { |x, y| x + y == sum } || []
end
result = sum_exists(numbers, sum)
@kfox
kfox / saveimages.rb
Created August 14, 2013 17:16
A quick Ruby script to download PNG, GIF, or JPEG images from a given URL
#!/usr/bin/env ruby
# usage: saveimages.rb <url>
# locally save all images from a web site
require 'nokogiri'
require 'open-uri'
exit if ARGV[0].nil?
@kfox
kfox / httpproxy.js
Created July 18, 2013 21:43
Simple HTTP proxy for Node.js v0.10.x
var http = require('http');
var host = process.argv[2] || '127.0.0.1';
var port = process.argv[3] || 8080;
http.createServer( function (req, res) {
var proxy = http.request(req.url, function (proxy_res) {
proxy_res.on('data', function (chunk) {
@kfox
kfox / forget.sh
Created February 8, 2013 15:45
An easy way to remove old SSH host keys from your ~/.ssh/known_hosts file. Useful if you often re-image systems.
# forget.sh: remove matching lines from ~/.ssh/known_hosts
# usage: forget <hostname|IP|substring> [...]
function forget {
known_hosts=~/.ssh/known_hosts
for host in $*
do
host=$(echo "${host}" | sed -e 's/^ssh:\/\///' -e 's/^.*@//')
line=$(awk '{ print $1 }' ${known_hosts} | grep -n "${host}" | sed 's/:.*$//g' | xargs)
while [ -n "${line}" ]
@kfox
kfox / kittenproxy.coffee
Last active August 27, 2020 11:08
Cat Attack! coffeescript and node.js
# to run:
# 1. npm install -g coffee-script
# 2. npm install http-proxy
# 3. coffee kittenproxy.coffee
# 4. change browser proxy settings to <thishost>:8080
httpProxy = require("http-proxy")
address = process.argv[2] or "0.0.0.0"
port = process.argv[3] or 8080
@kfox
kfox / syslogd.js
Last active August 27, 2020 09:49
Simple syslogd server
var dgram = require('dgram');
var host = process.argv[2] || '0.0.0.0';
var port = process.argv[3] || 514;
var server = dgram.createSocket('udp4');
server.on('message', function(msg, rinfo) {
console.log("received: %s from %s:%s", msg, rinfo.address, rinfo.port);
});