Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / data_validations.rb
Last active Jun 30, 2022
Data validations with axlsx gem
View data_validations.rb
#!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
require 'axlsx'
## Some documentation ##
### Axlsx Gem ###
# Axlsx Docs: http://rubydoc.info/gems/axlsx/frames
# Axlsx::DataValidation: http://rubydoc.info/gems/axlsx/Axlsx/DataValidation
@bradland
bradland / ssh-known-hosts-mgmt.sh
Last active Jun 19, 2022
SSH known_hosts tools
View ssh-known-hosts-mgmt.sh
# This is a short collection of tools that are useful for managing your
# known_hosts file. In this case, I'm using the '-f' flag to specify the
# global known_hosts file because I'll be adding many deploy users on this
# system. Simply omit the -f flag to operate on ~/.ssh/known_hosts
# Add entry for host
ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts
# Scan known hosts
ssh-keygen -f /etc/ssh/ssh_known_hosts -F github.com
@bradland
bradland / natophon.sh
Created Dec 27, 2011
NATO phonetic string converter for bash
View natophon.sh
#!/bin/bash
#########################################################################
# #
# #
# NATO String converter #
# #
# Description: converts string (first parameter given) #
# to NATO phonetics-alphabet #
# #
View john-swartzwelder-writing-trick.md

"I have a trick that makes things easier for me. Since writing is very hard and rewriting is comparatively easy and rather fun, I always write my scripts all the way through as fast as I can, the first day, if possible, putting in crap jokes and pattern dialogue—“Homer, I don’t want you to do that.” “Then I won’t do it.” Then the next day, when I get up, the script’s been written. It’s lousy, but it’s a script. The hard part is done. It’s like a crappy little elf has snuck into my office and badly done all my work for me, and then left with a tip of his crappy hat. All I have to do from that point on is fix it. So I’ve taken a very hard job, writing, and turned it into an easy one, rewriting, overnight. I advise all writers to do their scripts and other writing this way. And be sure to send me a small royalty every time you do it." - John Swartzwelder

The New Yorker, John Swartzwelder, Sage of “The Simpsons”

View cursed_report.rb
module ShellScriptUtils
class CursedReport
def initialize(message = nil)
@clear_commands = []
@message = message
update @message
end
def update(message)
clear @message # clear the current message
@bradland
bradland / data.txt
Created Jul 17, 2021
r/ruby question
View data.txt
A12345 Jon Osterman
A23456 Walter Kovacs
A34567 Daniel Dreiberg
987 Dr. Manhattan
876 Rorshach
765 Night Owl
A12345 987
A23456 876
@bradland
bradland / gencert.sh
Created Jan 27, 2012
Generate a self-signed SSL cert
View gencert.sh
#!/bin/bash
# Bash shell script for generating self-signed certs. Run this in a folder, as it
# generates a few files. Large portions of this script were taken from the
# following artcile:
#
# http://usrportage.de/archives/919-Batch-generating-SSL-certificates.html
#
# Additional alterations by: Brad Landers
# Date: 2012-01-27
@bradland
bradland / pingr
Created Mar 17, 2021
Ping a host and announce its status; requires macOS or suitable replacement for the say command line app.
View pingr
#!/usr/bin/env ruby
require 'logger'
require 'open3'
require 'optparse'
require 'ostruct'
require 'thread'
class ShellScript
View file_binary.rb
# Excerpt from ptools gem
# Returns whether or not +file+ is a binary non-image file, i.e. executable,
# shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
# It performs a "best guess" based on a simple test of the first
# +File.blksize+ characters, or 4096, whichever is smaller.
#
# By default it will check to see if more than 30 percent of the characters
# are non-text characters. If so, the method returns true. You can configure
# this percentage by passing your own as a second argument.
@bradland
bradland / ac-telemetry.rb
Last active May 13, 2020
Beginnings of a rudimentary CLI telemetry utility for Assetto Corsa written in Ruby.
View ac-telemetry.rb
#!/usr/bin/env ruby
$: << './lib'
require 'socket'
require 'bindata'
require 'json'
class UTF8String < BinData::String
def snapshot