Skip to content

Instantly share code, notes, and snippets.

View awhit012's full-sized avatar

Alex White awhit012

View GitHub Profile
@awhit012
awhit012 / Alex_Boyer-Moore
Last active August 29, 2015 14:09
Boyer-Moore
# big text for timed tests
big_text = "The RSVP Hello message exchange was introduced in [RFC3209]. The
usage of RSVP Hello has been extended in [RFC3473] to support RSVP
Graceful Restart (GR) procedures.
More specifically, [RFC3473] specifies the use of the RSVP Hello
messages for GR procedures for Generalized MPLS (GMPLS). GMPLS
introduces the notion of control plane and data plane separation. In
other words, in GMPLS networks, the control plane information is
carried over a control network whose end-points are IP capable and
that may be physically or logically disjoint from the data bearer
@awhit012
awhit012 / volumes_to_shapes
Created January 8, 2015 21:55
Simple Ruby program that accepts a volume in cubic meters and gives the dimensions of shapes that contain that volume
class Volume_To_Shapes
def initialize volume_input
@volume_input = volume_input
@height = cube_root @volume_input
get_cube_dimensions
get_sphere_dimensions
get_cylinder_dimensions
get_cone_dimensions
end
@awhit012
awhit012 / rail_fence_cypher
Created January 10, 2015 00:15
Ruby implementation of the old school Rail Fence Cypher, encrypts and decrypts using 2, 3 or 4 rows.
class Rail_Fence_Cipher
def initialize instruction, number, text
@letter_array = text.split("")
@text_length = text.length
@number = number
case instruction
when "encrypt"
encrypt
@awhit012
awhit012 / alex_brute_force_pattern_match.rb
Last active August 29, 2015 14:13
A brute force pattern matching algorithm in ruby
# Brute Force
# Takes a string and a pattern and returns the index of the pattern in the string,
# or returns "not found"
def brute_search string, pattern
pattern_length = pattern.length
for string_index in (0... string.length)
match_count = 0
loop do
# if a non-match is found, then break.
@awhit012
awhit012 / alex_brute_force_right_to_left.rb
Last active August 29, 2015 14:13
A brute force pattern matching algorithm that works right to left on the pattern, in ruby
#Brute Force Right to Left
# Function accepts a string and a pattern to find in that string
def brute_search_2 string, pattern
pattern_length = pattern.length
# Iterate through the string starting at string[pattern_length-1]
# We are starting there because we are looking for matches in the pattern starting
# at the last char.
for string_index in (pattern_length - 1 ... string.length)
match_count = 0
@awhit012
awhit012 / alex_basic_horspool.rb
Last active August 29, 2015 14:13
More basic version of Horspool pattern matching algorithm, that jump uses a simplified version of the bad character table, in ruby.
#First iteration moving towards Harspool algorithm simply jumps forward by
# pattern_length if char not in pattern is found
# function accepts a string and a pattern and returns the index in the string where
# the pattern first occurs, or "not found"
def brute_search_2 string, pattern
pattern_length = pattern.length
bad_match_table = Hash.new
# Generates hash table with keys as all chars in pattern, and values as true
@awhit012
awhit012 / alex_horspool.rb
Last active July 15, 2016 16:46
Horspool string matching algorithm in Ruby
#Horspool algorithm implements the good suffix rule.
# If the char is not present, it still skips ahead by the length of the pattern.
# If the char is not a match, but it is present in the string, it jumps forward by the appropriate ammount.
# pattern_length if char not in pattern is found
# function accepts a string and a pattern and returns the index in the string where
# the pattern first occurs, or "not found"
def brute_search_2 string, pattern
pattern_length = pattern.length
bad_match_table = Hash.new
@awhit012
awhit012 / alex_knp.rb
Last active June 23, 2024 15:31
A ruby implementation of the Knuth-Morris-Pratt algorithm
class KMP
attr_reader :results
def initialize string, pattern
@string = string
@pattern = pattern
@string_length = string.length
@pattern_length = pattern.length
@table = kmp_table
@results = []
kmp
@awhit012
awhit012 / quote_bot.py
Last active February 12, 2018 21:56
BotMother: A Reddit QuoteBot template using Praw
# UPDATED 7/15
# Thanks to kootenpv for the code review!
# This makes it easy to create a reddit bot that
# A. Grabs comments from subreddits of your choice
# B. Searches for a keyword
# C. Replies to comments with that keyword from a list of responses on a CSV file
# Follow correct etiquette:
# https://www.reddit.com/r/Bottiquette
@awhit012
awhit012 / mckenna_quotes.csv
Created May 2, 2015 06:49
McKenna Quotes!
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 2 columns, instead of 4. in line 2.
“I think of going to the grave without having a psychedelic experience like going to the grave without ever having sex. It means that you never figured out what it is all about. The mystery is in the body and the way the body works itself into nature.”,
“Stop consuming images and start producing them.”,
“You are a divine being. You matter, you count. You come from realms of unimaginable power and light, and you will return to those realms.”,
“You are an explorer, and you represent our species, and the greatest good you can do is to bring back a new idea, because our world is endangered by the absence of good ideas. Our world is in crisis because of the absence of consciousness.”,
“The male dominant agenda is so fragile that any competitor is felt as a deadly foe.”,