Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Ninjex / lookup.rb
Last active August 29, 2015 13:56
MD5 Lookup Table Generator
#!/usr/bin/ruby
require 'digest/md5' # Hashing strings to MD5
if ARGV[0] != '-i' || ARGV[2] != '-o' || ARGV[3].nil?
puts "Syntax Error!"
puts "Usage: ruby lookup.rb -i <input file> -o <output file>"
else
input_file = ARGV[1]
if File.exist?(input_file)
output_file = ARGV[3]
text = File.open(input_file).read
@Ninjex
Ninjex / gist:9048279
Last active August 29, 2015 13:56 — forked from Amazingred/gist:4104717
#!/usr/bin/env ruby
# Ruby script to generate SSHA (Good for LDAP)
require 'digest/sha1'
require 'base64'
# The output in hash will never have trailing whitespace, removed .chomp!
hash = Base64.encode64(Digest::SHA1.digest(#{pass}#{salt}#{salt}))
# Use string interpolation, no need to add \n puts does this for you
puts "userPassword: #{hash}"
@Ninjex
Ninjex / flood.rb
Last active July 19, 2018 01:42
Ruby UDP Flood
#!/usr/bin/ruby
require 'socket'
if ARGV[0] == '-ip' then ip = ARGV[1] end
if ARGV[2] == '-t' then seconds = ARGV[3].to_i end
if ARGV[2].nil? || ARGV[2].empty? then abort "Usage: ruby flood.rb -ip <ip address> -t <time in seconds>" end
bytes = 'Z' * 1000
def get_time(one, two)
(two - one).to_i
end
puts "UDP flooding IP: #{ip} for #{seconds} seconds!"
@Ninjex
Ninjex / fizzbuzz.rb
Last active August 29, 2015 13:56
FizzBuzz with classes
class Enumerator::Lazy
def filter_map
Lazy.new(self) do |holder, *values|
result = yield *values
holder << result if result
end
end
end
class Fizz
@Ninjex
Ninjex / hailstorm.rb
Created February 27, 2014 15:32
Hailstorm Function
#!/usr/bin/ruby
def hailstorm n
vals = [n]
while n > 1 and n = (n.even?) ? (n/2) : (3 * n + 1)
vals << n
end
p vals # List returns
end
hailstorm(27)
@Ninjex
Ninjex / stego.rb
Created February 28, 2014 16:20
This script will take text and embed it into a picture via tampering with pixel LSB values.
#!/usr/bin/ruby
require 'rubygems'
require 'RMagick'
prompt = '> '
puts "Image to embed (not overwritten):"
print prompt
image_file = gets.chomp
img = Magick::Image::read(image_file)[0]
width = img.columns
height = img.rows
@Ninjex
Ninjex / exec.rb
Created March 10, 2014 19:31
A Weechat plugin coded in Ruby. This plugin allows you to run command on your machine from IRC, additionally you may choose to directly post the messages to all users in IRC with the -p option. For example: /exec -p echo 'hi'
#!/usr/bin/ruby
def weechat_init
Weechat.register('exec', 'Ninjex', '1.0', 'GPL3', 'Execute a terminal command via /exec <command>', '', '')
Weechat.hook_command('exec', 'Execute a terminal command from chat', '', '', '', 'exec', '')
return Weechat::WEECHAT_RC_OK
end
def exec(data, buffer, args)
to = nil
buffer = Weechat.current_buffer
@Ninjex
Ninjex / short_url.rb
Last active August 29, 2015 13:57
A Weechat plugin for shortening long URL's. This script uses the URL shortening application at hts.io
#!/usr/bin/ruby
# Need to add a validation check on URL's -- just don't be ignorant with it :D
require 'mechanize' # Necessary to communicate with the server.
def weechat_init
Weechat.register('short_url', 'Ninjex', '1.0', 'GPL3', 'Shorten a URL /short_url <link>', '', '')
Weechat.hook_command('short_url', 'Shorten URL /short_url <link>', '', '', '', 'short_url', '')
return Weechat::WEECHAT_RC_OK
end
def short_url(data, buffer, args)
@Ninjex
Ninjex / rsub-doc.md
Last active August 26, 2022 10:57
How to: Setting up Sublime Text to work through an SSH tunnel.

First, you need to install the Sublime Text package manager.

To do this, open up Sublime Text, and hit hit the cntrl+p key binding (or navigate to: Preferences -> Package Control)

When prompted for the search query, type the following: 'Package Control: Install Package'

Press enter, and shortly it should generate a list of plugins that can be installed to Sublime.

Search for the following plugin: 'RemoteOpen' and press enter. This will begin the installation.

@Ninjex
Ninjex / sql.rb
Created March 17, 2014 15:07
Query a MySQL database from within Weechat. Ruby plugin
#!/usr/bin/ruby
# Required packages / gems
# libmysql-ruby libmysqlclient-dev
# gem mysql2
require 'mysql2'
@options = {
"public" => "false", # MySQL query result publicly visible
"host" => "localhost", # MySQL host
"user" => "root", # MySQL username