Sunday, July 28, 2019

Best prompt ever, Improved!

#!/bin/bash
u_color="\e[38;5;212m"
amp_color="\e[38;5;183m"
h_color="\e[38;5;51m"
col_color="\e[1;34m"
dir_color="\e[1;32m"
ps_color="\e[38;5;226m"
reset="\e[0m"
PS1="$u_color\u$amp_color@$h_color\h$col_color:$dir_color\w$ps_color\$$reset "
echo "PS1=\"$PS1\""

Thursday, June 27, 2019

Chef HOWTO: Encrypted Data Bags


Create a new encrypted data bag


1. Create a secret for the data bag

$ openssl rand -base64 1024 > db_secret_key.txt

2. Make an encrypted data bag:

$ export EDITOR=vim

$ knife data bag create BAG_NAME --secret-file db_secret_key.txt

Created data_bag[BAGNAME]

3. Create data bag entry and edit contents:

$ knife data bag create BAG_NAME ITEM_NAME --secret-file db_secret_key.txt

Data bag BAG_NAME already exists

Created data_bag_item[ITEM_NAME]

4. (optional) Download data bag as json:

knife download data_bags/BAG_NAME

5. (optional) Upload data bag from json file:

knife data bag from file BAG_NAME BAG_FILENAME.json

6. (optional) Access data bag from a recipe:

db_secret = Chef::EncryptedDataBagItem.load_secret('/path/to/db_secret_key.txt')

private_key_value = Chef::EncryptedDataBagIten.load('BAG_NAME', 'ITEM_NAME', db_secret)['ITEM_KEY']

### note: ITEM_KEY is often an Environment name

Tuesday, June 25, 2019

Super Easy Encryption w/ GPG

To import somebody's public key:


gpg --import your_friend.pub


To encrypt a text file for them:


gpg -a -se -r 'friend name in address book' FILENAME.txt


To list the keys (your friends') in your address book:


gpg --list-keys


To import a new friend's key:


gpg --import friend_key.pub


To generate a new private key for yourself:

gpg --full-generate-key
or
gpg --default-new-key-algo rsa4096 --gen-key


Monday, May 6, 2019

Most important SED syntax

This is how Unix SED was meant to be used.

Take a text file and substitute 1 regex match for a new one, in place.

My file:
-rw-r--r-- 1 matt matt  7338 May  6 00:05 merge.rb


sed -i s/OLDVALUE/NEWVALUE/g merge.rb


-i means in-place
-s means substitute
-g means globally

Friday, May 3, 2019

Ruby - How to make your program run from any directory (with libraries)



#!/usr/bin/ruby

### Save the folder name that this lives in
folder = File.expand_path('.',__dir__)

### Add to the Ruby default load path the pwd this was executed from
$LOAD_PATH.unshift(folder) unless $LOAD_PATH.include?(folder)

### Here we can now interpolate a relative path
load "#{folder}/../lib/modules.rb"

puts "stub.rb pwd: #{Dir.pwd}"

Sunday, April 28, 2019

Friday, April 12, 2019

An even better PS1

\[\033[38;5;201m\]\u\[\033[38;5;51m\]@\[\033[38;5;183m\]\h\[\033[1;34m\]:\[\033[1;32m\]\w\[\033[1;31m\]\$\[\033[00m\]

Ruby: Best way to boolean grep for a string contained in a file

File.readlines('./mystuff.txt').grep(/Word123/).any?

Tuesday, February 26, 2019

Best vim Color Mod



Put these files in your (unix) home directory:

~/.vim/autoload/palenight.vim
https://github.com/drewtempelmeyer/palenight.vim/blob/master/autoload/palenight.vim



~/.vim/colors/palenight.vim
https://github.com/drewtempelmeyer/palenight.vim/blob/master/colors/palenight.vim



Autoload?  Add line this to your ~/.vimrc

colorscheme palenight

Super Easy Ruby ERB template


#!/opt/chef-workstation/embedded/bin/ruby -w

 

require 'erb'

 

#template = File.read('./mytemplate.txt.erb')

 

template = 'i want to put stuff ===> <%= "here" %> <==='

 

obj_out = ERB.new(template)

 

STDOUT.puts obj_out.result