Skip to content

Instantly share code, notes, and snippets.

View kfox's full-sized avatar

Kelly Fox kfox

  • Austin, TX, USA
View GitHub Profile
@kfox
kfox / README.md
Last active April 10, 2026 07:19
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 / sysctl.conf
Created February 29, 2012 17:32
Linux kernel tuning settings for large number of concurrent clients
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
@kfox
kfox / tcpproxy.js
Created April 5, 2012 20:03
A basic TCP proxy written in node.js
var net = require("net");
process.on("uncaughtException", function(error) {
console.error(error);
});
if (process.argv.length != 5) {
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
process.exit();
}
@kfox
kfox / README.md
Last active October 4, 2024 21:24
MacOS command line to convert a binary C64 character set to comma-delimited hex

Convert a binary C64 character set to comma-delimited hex

  1. Replace raw c64 character set with the file name of your raw binary Commodore 64 character set.
  2. Paste the results into the dialog for the "import raw byte stream" prompt on the PETSCII Editor site by Krisztián Tóth.
cat "raw c64 character set" | \
  od -v -j 2 -t xC | \
  sed \
 -e 's/^.......//g' \
@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 / 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 / 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 / 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 / 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 / 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"