Skip to content

Instantly share code, notes, and snippets.

@MelanieS
MelanieS / step_and_time.rb
Last active August 29, 2015 14:02
Something
#ruby 2.2.1p85 (2015-02-26 revision 49769)
#energies files must contain time on left column, energy on right, separated by space
#change paths on line 73
energies = Dir.glob('*energies.txt')
energies = energies.pop
text = File.open(energies).read
text = text.to_s
array = text.split("\n")
@MelanieS
MelanieS / name_sanitizer.pl
Last active August 29, 2015 13:58
Sanitizes user input (names) and prints out in form of "First M. Last"
#!/usr/bin/perl
use strict;
use warnings;
#Prints out the name in a "sanitized" form of "First M. Last"; that is, first name, space, middle initial, period, space, last name.
#If there is no middle name, prints the letter X with no period following it.
#If there are multiple middle names, uses the initial of the first one.
my $name = "Melanie Aurelia Shebel";
@MelanieS
MelanieS / Fibonacci.rb
Last active August 29, 2015 13:58
Calculates user defined nth number in the Fibonacci sequence. Script doesn't utilize recursion.
puts "How many Fibonacci numbers would you like?"
n = gets.to_i
puts "Awesome! I'll get started on that right away!"
def fibonacci(n)
array = []
a,b = 0,1
n.times do
array << a
a,b = b,a+b
end
if rocks > pebbles
puts "You have more rocks than pebbles."
elsif rocks < pebbles
puts "You have more pebbles than rocks."
end
if rocks > pebbles
puts "You have more rocks than pebbles."
elsif pebbles > rocks
puts "You have more pebbles than rocks."
puts "Enter a starting number for your range"
range_begin = gets.chomp.to_i
puts "Enter the ending number for your range"
range_end = gets.chomp.to_i
range = (range_begin..range_end)
dirty_prime_list = []
range.each do |x|
euler = x**2 + x + 41
@MelanieS
MelanieS / melsort.rb
Created October 21, 2012 01:16
A bad sorting algorithm
unsorted_array = [5, 2, 8, 0, 9, 3, 1]
sorted_array = []
count = 0
while sorted_array.count != unsorted_array.count
unsorted_array.each do |i|
if i == count
sorted_array << i
end
end
@MelanieS
MelanieS / gist:3630535
Created September 5, 2012 04:35
Counter
puts "Pick a number 1-50"
number = gets
if number.include? "."
puts "I'm getting rid of that decimal. That was a dumb move."
end
number = number.chomp.to_i
while number < 1 || number > 50
@MelanieS
MelanieS / gist:3001649
Created June 27, 2012 05:19
ascii_gui.rb
motion = ""
while motion != "off"
puts
puts
puts
puts " STOP"
puts " FORWARD"
puts "Left Speed......Left..........................Right.......Right speed"
puts
@MelanieS
MelanieS / slope_of_a_line.rb
Created May 17, 2012 06:34
Simple script to find the slope of a straight line
#This is just a gist because I felt like writing something
#and don't have Ruby installed on the computer I'm using
puts "What is the x value for the first point?"
x1 = gets
puts "What is the y value for the first point?"
y1 = gets
puts "What is the x value for the second point?"
string = "| t%%> + ~+$ -+*> t% ~y r%%~, | s~%>&@ #|~ |$ -&@."
string = string.gsub(/[|]/, 'i')
#string = string.gsub(/[]/, '')
#string = string.gsub(/[]/, '')
#string = string.gsub(/[]/, '')
puts string