Skip to content

Instantly share code, notes, and snippets.

View douglascodes's full-sized avatar

Douglas King douglascodes

View GitHub Profile
@douglascodes
douglascodes / controlled_perm.rb
Last active December 15, 2015 12:39
A controlled permutation. Cycles an array of arrays calling the proc with each possible set of the sub arrays whilst preserving the positions of the original array. Basically gets every combination of "One from column A, one from column B, ..." and so on.
a_of_a = [["Jazz", "Soul", "Rock"],["Cheeseburgers", "Hot dogs", "Milkshakes"], ["cable", "radio", "internet"]]
result = Array.new(a_of_a.length)
procky = Proc.new { |arg|
print arg.join(" and "), " are my favorite things. \n"
}
def controlled_perm(x, a_of_a, result, procky)
x += 1
if a_of_a.length == x
procky.call(result)
return
@douglascodes
douglascodes / percent_different_bash.sh
Last active December 16, 2015 06:48
Bash script for finding the percentage of Byte difference between two files. Uses wc, cmp, grep and bc.
#! /bin/bash
echo Reports the percentage of matching bytes between two files.
LENGTH_OF_A=$( wc -c $1 | grep -Eo [0-9]+)
LENGTH_OF_B=$( wc -c $2 | grep -Eo [0-9]+)
SAME_SIZE="false"
if [ "$LENGTH_OF_B" -gt "$LENGTH_OF_A" ]
then
LONGER=$2
@douglascodes
douglascodes / xml_parse
Created June 22, 2014 14:52
Download, parse and strip tags from two XML attributes in single Linux command line. Great for testing RSS feeds.
wget -q -O- {http://www.example.com/foo.xml} | xpath -q -e '{path/to/xml_element/attr1} | {path/to/xml_element/attr2}' | sed -re 's/(<\w+?>|<\/\w+?>)//g'
@douglascodes
douglascodes / diff directory listings
Last active August 29, 2015 14:05
Reads two sorted files as STDIN, one strips forward slashes if they exist
diff --suppress-common-lines -yw <(sort -u restore_log) <(sed -r 's/^\///g' <(sort -u original_log) )
@douglascodes
douglascodes / i3-wm_4.10.2_install
Created May 7, 2015 02:26
Installation instructions for getting i3-wm to compile on CentOS 7
yum update
#Install for compiling and configuring needs
yum install nano bzip2 gcc git pkgconfig autoconf automake libtool gperf byacc libxslt bison flex
#If in a VM you will need to install files for kernel dev to load Guest additions (VirtualBox)
yum install kernel-devel
#Mount the guest additions CD and install
sudo mount /dev/sr0 /media
@douglascodes
douglascodes / FormLetterPasswords
Created December 4, 2015 16:43
A form letter to send to my accounts where they have terrible 1990s limits on passwords.
The current password policy is insufficient for properly securing my account.
While trying to reset my password I noticed a limit of {pw_limit}.
1. This artificially imposed limit locks my account password to only {pw_limit} characters and not all symbols.
2. The above suggests the passwords are stored in plain text. Which is never a good thing.
3. The current input limit is {pw_limit} characters. Google recommends a 60 character limit and 8 character minimum.
4. I typically use passwords of at least 20 characters and use any symbol available in the regular US key set.
Please upgrade the service to be able to handle passwords of greater length, symbols, and enable proper hashing and salting. For reference please see the following.
@douglascodes
douglascodes / removeOldBackups.ps1
Last active February 23, 2017 02:36
Function for testing files in similar paths but different roots exist in both places
# Script for testing file existence in two places
# PS C:\> . .\removeOldBackups.ps1
# PS C:\> existsInBoth -DestRoot 'C:\Program Files\' -SourceRoot 'C:\Program Files (x86)\' -CommonPath "Common Files"
# True
# PS C:\> existsInBoth -DestRoot 'C:\Program Files\' -SourceRoot 'C:\Program Files (x86)\' -CommonPath "UnmatchedFile"
# False
function existsInBoth{
param ( [string] $SourceRoot,
[string] $DestRoot,
@douglascodes
douglascodes / getDaysOldFiles.ps1
Created February 23, 2017 02:40
Gets files where -14 days old. Can be turned into a function easily.
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-14) }
@douglascodes
douglascodes / inotify_sync.sh
Last active July 5, 2017 11:21
Script to update web directory on change. A -> B Watch using inotifywait.
#!/bin/sh
# Syncs files from directory A to B. With the 'chown' this will need to be run as root.
# Drop that to run as unprivileged user.
if [ $# -lt 2 ] ; then
echo "usage: $0 <dir to watch> <sync to>"
fi
source="$1"
destination="$2"
@douglascodes
douglascodes / aws_redhat_basic.yml
Last active September 17, 2017 21:46
An ansible file for setting up my default config
---
- hosts: redhat_aws
vars:
remote_user: ec2-user
target_user: myUserName
tasks:
- name: 1.Check if EPEL repo is already configured.
stat: path=/etc/yum.repos.d/epel.repo
register: epel_repofile_result