Skip to content

Instantly share code, notes, and snippets.

View nicdoye's full-sized avatar
🚲
All shall be well, and all shall be well, and all manner of thing shall be well

Nic Doye nicdoye

🚲
All shall be well, and all shall be well, and all manner of thing shall be well
View GitHub Profile
@nicdoye
nicdoye / tunnel.sh
Created June 15, 2017 16:12
SSH tunnel to Windows server in AWS VPC
#!/bin/bash
# SECURITY WARNING: the password will be visible in the process list on your local machine.
# Note: you need PuTTY's plink to get this to work, even on macOS
# macOS: `brew install putty`
# Windows: `choco install putty`
# Arguments:
# vpc_ip = Private IP Address of the Windows box. e.g. 172.16.1.1
@nicdoye
nicdoye / inode-remover.sh
Created June 15, 2017 13:20
Incredibly dangerous script to remove open inodes of deleted files
#!/bin/bash
while [[ $(lsof -nP +L1 | wc -l) > 1 ]]
do
pair=$(lsof -nP +L1 | tail -n 1 | awk '{print $2" " $4}')
pid=$(echo $pair | awk '{print $1}')
fd=$(echo $pair | awk '{print $2}' | sed -e 's_[a-z]__g')
file=$(mktemp)
# Race condition check on first line of lsof output
@nicdoye
nicdoye / mount-cleaner.sh
Created April 18, 2017 12:52
Unmounting installation disks on macOS
#!/bin/bash
# IMPORTANT ASSUMPTION:
# YOU DO NOT HAVE ANY OTHER DISKS MOUNTED WITH AN `s1` PARTITION!
# A better way would be to use `diskutil list --plist` and parse the
# plist using ruby/python/javascript/your-language-of-choice
for disk in $(mount | egrep 'disk.+s1' | awk '{print $1}' | sed -e 's_^/dev/__' -e 's_s1$__')
do
diskutil eject ${disk}
@nicdoye
nicdoye / config
Created March 4, 2017 17:48
A sample ssh config for bastions/gateways
# Your bastion host
Host bastion bastion.example.com
IdentityFile ~/.ssh/bastion-example-com.pem
Port 12345
User bastion-user
# Inside the VPC
Host host0.internal host1.internal
@nicdoye
nicdoye / keybase.md
Created February 20, 2017 11:00
Ignore.

Keybase proof

I hereby claim:

  • I am nicdoye on github.
  • I am nicdoye (https://keybase.io/nicdoye) on keybase.
  • I have a public key ASB0JEma1L_Ga1DDnc5C5PjOQeUqdd-te4Byt53qpDDzFAo

To claim this, I am signing this object:

@nicdoye
nicdoye / shrink-png.sh
Created February 14, 2017 10:41
Shrink a PNG file so you can make a custom emoji in Slack, using NetPBM
pngtopam -alphapam < filename.png | pamscale -xyfit 128 128 | pamtopng > filename-shrunk.png
@nicdoye
nicdoye / gotcha.sh
Created February 8, 2017 17:30
bash gotcha
# This is what you'd expect - prints 1
declare var
var=$(false)
echo $?
# This does not do what you'd expect - prints 0
declare var2=$(false)
echo $?
@nicdoye
nicdoye / jira-regex.md
Created January 18, 2017 10:56
Replace JIRA project-numbers with Markdown Links in VS Code/regex

Replace JIRA Project numbers with links

Assuming

  1. your project prefix is EXAMPLE
  2. your JIRA installation is at https://example.com/jira then regex to match is
(EXAMPLE-(\d)*)
@nicdoye
nicdoye / google-dmarc-parser.rb
Created January 4, 2017 15:27
Parse GSuite DMARC Reports
#!/usr/bin/env ruby
require 'nokogiri'
require 'optparse'
require 'resolv'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: google-dmarc-parser.rb [options]"
# A quick alias for those of us without such a command
tiff2png ()
{
local ifile=$1
local ofile=$(dirname "${ifile}")/$(basename "${ifile}" .tiff).png
tifftopnm < "${ifile}"| pnmtopng > "${ofile}"
}