Skip to content

Instantly share code, notes, and snippets.

View redperadot's full-sized avatar

Cody Hannafon redperadot

  • Ithaca NY
View GitHub Profile
@redperadot
redperadot / loginfortune.rb
Last active January 4, 2016 01:19
Change the OS X login window message to a fortune.
#!/usr/bin/env ruby
# ___
# /\ \
# \ \ \ loginfortune
# \ \ \ Created by redperadot@darkgem.net
# _____\_\ \ ___________
# /\ _____ \/\ _____ \
# \ \ \___/\ \ \ \___/\ \ If you're running OS X and are tired of your boring
# \ \ \__\_\ \ \ \__\_\ \ lock screen message this is the script for you!
# \ \__________\ \________ \ Using the fortune command this script will change
@redperadot
redperadot / plex_list.sh
Created January 29, 2014 17:43
Export your plex library to the terminal.
#!/usr/bin/env bash
# redperadot@darkgem.net
# plex_list.sh
[[ $(uname) != "Darwin" ]] && echo "OS X Only" && exit 1
cd /Users/redperadot/Library/Application\ Support/Plex\ Media\ Server/Metadata/Movies
for file in $(find ./ -name '*.bundle'); do
file=$(echo "$file" | rev | cut -c 1- | rev)
title=$(cat "$file/Contents/com.plexapp.agents.localmedia/info.xml" | grep "<title>" | sed -e 's,.*<title>\([^<]*\)</title>.*,\1,g')
echo "$title"
@redperadot
redperadot / host_down.sh
Last active August 29, 2015 13:55
Do you ping constantly but only want to know when a host is down? Well this little script does just that.
#!/usr/bin/env bash
# redperadot@darkgem.net
# host_down.sh
[[ $1 == "-a" ]] && audible='\a' && shift || audible=
address_1=$1
address_2=$2
[[ -z $address_1 ]] && read -p "Address #1 to ping: " address_1
[[ -z $address_2 ]] && read -p "Address #2 to ping: " address_2
@redperadot
redperadot / mac_vendor.sh
Last active May 16, 2023 21:39
Get the vendor for a mac address from the terminal.
#!/usr/bin/env bash
#
# mac_vendor.sh - Get the vendor for a mac address from the terminal.
# Made with ❤︎ by redperadot@darkgem.net
# Set Functions
usage()
{
echo "MAC Vendor Help"
echo "mac_vendor -a 'MAC Address' | Get the vendor of the specified address."
@redperadot
redperadot / raffle.rb
Last active August 29, 2015 13:57
Raffle off items with ruby.
#!/usr/bin/env ruby
#
# raffle.rb - Raffle off items with ruby. Version 0.2
# Made with ❤︎ by redperadot@darkgem.net
#
# To use cd into a directory with a 'tickets.txt'
# file and a 'items.txt' file. Then just run the
# script. Items in the files should be separated
# by new lines.
@redperadot
redperadot / uninstall_node.sh
Created March 21, 2014 17:29
Script to uninstall node.js on OS X.
#!/bin/bash
[[ $(uname) != "Darwin" ]] && echo "OS X Only" && exit 1
sudo -v
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
sudo rm /usr/local/${i}
done
@redperadot
redperadot / uri.rb
Last active November 22, 2022 08:12
Encode and decode URI strings with Ruby.
#!/usr/bin/env ruby
require 'uri'
pb = ( (/darwin/ =~ RUBY_PLATFORM) != nil ? true : false )
## Get Options
if ARGV[0] == "-h"
puts "#{$0} -e [STRING] (Encode String)"
puts "#{$0} -d [STRING] (Decode String)"
exit 0
end
@redperadot
redperadot / as_user.rb
Created April 28, 2014 22:04
Run a block of code as another user in Ruby. You could use it to unsudo a sudoed script.
#!/usr/bin/env ruby
require 'etc'
def as_user(user = Etc.getlogin, &block)
u = (user.is_a? Integer) ? Etc.getpwuid(user) : Etc.getpwnam(user)
puts "Running child process as the user #{user}(#{u.uid})."
pid = Process.fork do
Process.uid = u.uid
block.call(user)
end
@redperadot
redperadot / grsp.rb
Created May 21, 2014 13:25
Get remote OS X system profile.
#!/usr/bin/env ruby
#
# grsp.rb - Get remote OS X system profile. Version 0.1
# Made with ❤︎ by redperadot@darkgem.net
require 'optparse'
require 'io/console'
require 'net/ssh'
Signal.trap("INT") { puts; exit 0 }
@redperadot
redperadot / auto-ssh.rb
Last active August 29, 2015 14:01
Setup SSH login without a password.
#!/usr/bin/env ruby
#
# auto-ssh.rb - Setup SSH login without a password.
# Made with ❤︎ by redperadot@darkgem.net
## Gem Installer
def require_gems(*gems)
gems.each do |_gem|
begin require _gem
rescue LoadError