Skip to content

Instantly share code, notes, and snippets.

View JGallardo's full-sized avatar

Juan Gallardo JGallardo

View GitHub Profile
@JGallardo
JGallardo / changedFiles.rb
Created December 13, 2012 02:35
File integrity validation script written in Ruby.
require 'find'
require 'digest/md5'
unless ARGV[0] and File.directory?(ARGV[0])
puts "\n\n\nYou need to specify a root directory: changedFiles.rb
<directory>\n\n\n"
exit
end
root = ARGV[0]
@JGallardo
JGallardo / decrypt.rb
Created December 13, 2012 03:03
File decryption script written in Ruby
require 'crypt/blowfish'
unless ARGV[0]
puts "Usage: ruby decrypt.rb <Encrypted_filename.ext>"
puts "Example: ruby decrypt.rb" Encrypted_secret.stuff"
exit
end
filename = ARGV[0].chomp
puts "Decrypting #{filename}."
@JGallardo
JGallardo / fileSplit.rb
Created December 14, 2012 02:50
Ruby script that can split a file into multiple smaller files
if ARGV.size != 2
puts "Usage: ruby fileSplit.rb <filename.ext> <size_of_pieces_in_bytes>"
puts "Example: ruby fileSplit.rb myfile.txt 10"
exit
end
filename = ARGV[0]
size_of_split = ARGV[1]
if File.exists?(filename)
@JGallardo
JGallardo / fileJoin.rb
Created December 14, 2012 02:52
Ruby script that can join files.
if ARGV.size != 1
puts "Usage: ruby fileJoin.rb <filename.ext>"
puts "Example: ruby fileJoin.rb myfile.txt"
exit
end
file = ARGV[0]
piece = 0
orig_file = "New.#{file}"
@JGallardo
JGallardo / compress.rb
Created December 14, 2012 03:00
Ruby script to compress files.
require 'zip/zip'
unless ARGV[0]
puts "Usage: ruby compress.rb <filename.ext>"
puts "Example: ruby compress.rb myfile.exe"
exit
end
file = ARGV[0].chomp
@JGallardo
JGallardo / decompress.rb
Created December 14, 2012 03:02
Ruby script to decompress files.
require 'zip/zip'
require 'fileutils'
unless ARGV[0]
puts "Usage: ruby decompress.rb <zipfilename.zip>"
puts "Example: ruby decompress.rb myfile.zip"
exit
end
archive = ARGV[0].chomp
@JGallardo
JGallardo / mortgageCalc.rb
Created December 14, 2012 03:06
Very basic script in Ruby to calculate mortgage payments.
print "enter loan amount: "
loan = gets.chomp.to_i
print "Enter length of time in months: "
time = gets.chomp.to_i
print "Enter interest rate: "
rate = gets.chomp.to_f/100
i = (1+rate/12)**(12/12)-1
annuity = (1-(1/(1+i))**time)/i
@JGallardo
JGallardo / linkValidator.rb
Created December 14, 2012 03:32
Ruby Script that can be used to validate all the links on a web page.
require 'uri'
require 'open-uri'
require 'rubyful_soup'
begin
print "\n\nEnter website to crawl (ex. http://www.google.com): "
url = gets
puts url
uri = URI.parse(url)
html = open(uri).read
@JGallardo
JGallardo / orphanCheck.rb
Created December 14, 2012 03:38
Ruby script to check for orphan files on a web server.
links = Array.new
orphans = Array.new
dir_array = [Dir.getwd]
unless File.readable?("links.txt")
puts "File is not readable."
exit
end
File.open('links.txt', 'rb') do |lv|
@JGallardo
JGallardo / formGenerator.rb
Created December 14, 2012 03:42
Ruby script to generate a form
require 'cgi'
cgi = CGI.new("html4Tr")
print "Enter Form Page Title: "
title = gets.chomp
print "Enter Head Title: "
input_title = gets.chomp
print "Enter value for button: "
value = gets.chomp