Skip to content

Instantly share code, notes, and snippets.

View drhuffman12's full-sized avatar

Daniel Huffman drhuffman12

View GitHub Profile
@drhuffman12
drhuffman12 / env_printer.rb
Created November 1, 2016 18:33
Snippet for printing ENV key-value pairs, w/ keys right-aligned and values left-aligned
puts
longest_key = ENV.keys.max_by(&:length)
key_formatter = '%' + "#{longest_key.length}" + 's'
puts "longest_key: '#{longest_key}'"
puts "key_formatter: '#{key_formatter}'"
puts "ENV:"
puts
ENV.each_pair do |k,v|
puts "#{key_formatter % k}: #{v}"
end
@drhuffman12
drhuffman12 / star_curves.rb
Created November 2, 2016 03:18
simple txt grapher
def stars(y,scale,char);y>0 ? char * ((y*scale).round) : '';end
def curve(n);(0..n+1).each.collect{|x| y=Math.sin(Math::PI*2*x/n); [x, y]};end
def star_set(y,scale,char_neg,char_zero,char_pos); yn = y < 0 ? stars(-y,scale,char_neg) : ''; yp = y > 0 ? stars(y,scale,char_pos) : ''; ("%#{scale.round.to_i}s" % yn) + char_zero + ("%-#{scale.round.to_i}s" % yp); end
def star_set_def(y);star_set(y,10,'-','.','+');end
puts curve(16).collect{|n| star_set_def(n[1])+" #{n[0]}, #{n[1]}\n"}.join('')
=begin
. 0, 0.0
.++++ 1, 0.3826834323650898
@drhuffman12
drhuffman12 / hash_utils.rb
Created November 30, 2016 19:03
utility methods for hashes
class HashUtils
# See also various flattening solutions at http://stackoverflow.com/questions/23521230/flattening-nested-hash-to-a-single-hash-with-ruby-rails
def self.flatten_hash(param, prefix='')
param.each_pair.reduce({}) do |a, (k, v)|
v.is_a?(Hash) ? a.merge(flatten_hash(v, "#{prefix}#{k}.")) : a.merge("#{prefix}#{k}".to_sym => v)
end
end
end
class Hash
@drhuffman12
drhuffman12 / windows_to_linux_line_endings.rb
Last active January 27, 2017 23:49
Replace all "\r\n" occurances with "\n" for all files in a folder
@folder_path = 'path/to/your/folder'
Dir.glob(File.join(@folder_path,'*')).each {|f| File.open(f, 'w', crlf_newline: false) {|f| f.write(File.read(f).gsub("\r\n","\n") } };nil
@drhuffman12
drhuffman12 / xml_formatter.rb
Last active March 23, 2017 19:05
xml_formatter
#!/usr/bin/env ruby
# USAGE:
# $> ./xml_formatter path/from/my/file.xml
# $> ./xml_formatter path/from/my/file.xml path/to/my/file_formatted.xml
require 'nokogiri'
in_file = ARGV[0]
out_file = ARGV[1]
@drhuffman12
drhuffman12 / _clean_docker_.sh
Last active August 18, 2017 01:39
Clean Docker containers and images based on given filter text
#!/usr/bin/env sh
filter="$1"
if [ -z "$1" ]
then
echo "Clean Docker containers and images based on given filter text."
echo
echo " Error: No filter argument supplied."
echo " Usage: `basename "$0"` <filter>"
echo " e.g. `basename "$0"` my_image_or_container_name"
echo
@drhuffman12
drhuffman12 / keybase.md
Created February 15, 2018 16:48
keybase.md

Keybase proof

I hereby claim:

  • I am drhuffman12 on github.
  • I am drhuffman12 (https://keybase.io/drhuffman12) on keybase.
  • I have a public key ASBPyKOg-p-18ANv6JCy3ywED_bb1obMMNe5rNls0dg4HQo

To claim this, I am signing this object:

@drhuffman12
drhuffman12 / gist_edit_textbox_height.js
Created April 16, 2018 03:11
Modify Gist Edit Textbox Height
// xpath: '//*[@id="gists"]/div[2]/div[2]/div[2]/div'
// selector: '#gists > div.js-gist-file > div.file.js-code-editor.container-preview.show-code > div.commit-create > div'
// reset to orig:
$('#gists > div.js-gist-file > div.file.js-code-editor.container-preview.show-code > div.commit-create > div').style.height = '352px'
// expand to 600px high:
$('#gists > div.js-gist-file > div.file.js-code-editor.container-preview.show-code > div.commit-create > div').style.height = '600px'
// expand to 900px high:
@drhuffman12
drhuffman12 / docker_cleanup.sh
Last active April 23, 2018 18:40
docker scratchpad
# Remove all images by name
export IMAGE_NAME
IMAGE_NAME=<none>
docker rmi -f `docker images -a | grep $IMAGE_NAME | awk '{print $3}'`
@drhuffman12
drhuffman12 / common.rb
Last active February 1, 2019 17:14
NUT-4229_comparing_OUTER_vs_INNER_joins
esha_pks = [6760530, 6776057, 7279784, 7370300, 8253591, 9797725, 10311137, 10455343, 11402152, 17796699, 18295998, 19227419, 21647821, 21868381, 22096443, 25284036, 32992254, 33039508, 35801083, 37408869, 37500344, 38846565, 44116874, 45503193, 45540890, 46292022, 46676413, 46997137, 48713161, 49538949, 52445686, 52668422, 55396354, 55749456, 56973217, 59940706, 66485593, 66941662, 67180364, 69097944, 70879458, 74598952, 74644922, 74715709, 81621084, 81864393, 82291812, 87092433, 91220972, 92292419, 92622167, 96111237, 96843940, 98217617, 98408699, 99470316, 102108591, 107904280, 108078113, 109046683, 110267344, 110684336, 112318653, 115528891, 115725084, 119023790, 119158512, 120247555, 123243383, 123817113, 124422809, 127195547, 129628259, 130922680, 134762489, 140120855, 143885669, 148806873, 149404244, 149810346, 149867253, 154129202, 160165198, 160803062, 163535839, 165656452, 167844561, 167987582, 168849158, 169287900, 169465839, 170000559, 170062431, 170281645, 179569209, 180810565, 181493232, 182530