Skip to content

Instantly share code, notes, and snippets.

View index_approach.rb
string = "This is a Ruby tutorial."
# This returns the index where the 1st instance of i occurs
# This code returns 2
View scan_method.rb
string = "This is a Ruby tutorial."
# Here we will return an array containing each instance of i
# This code returns ["i", "i", "i"]
View count_method.rb
string = 'This is a Ruby tutorial.'
# This returns the integer 3
# case sensitive example
# This returns the integer 1
string.count('r', + 'R')
# This returns the integer 2
MelanieS /
Last active April 2, 2019 18:03
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
package rollingdie;
import java.util.Random;
import java.util.Scanner;
import java.util.*;
import java.util.Arrays;
View gist:2d576c294258fb5a22c4
rename "old" "new" *
# * means all files
MelanieS / permute_tri.rb
Created September 11, 2015 02:38
View permute_tri.rb
a = [60, -60]
# 4 refers to number of 60s or -60s in each element of array
a = a.repeated_permutation(6).to_a
puts "The array contains #{a.length} elements."
#creates output file called permute.txt
out_file ="permute_out.txt", "w")
MelanieS / course_tracker
Created July 9, 2014 20:15
PNC course tracker
View course_tracker
#Purdue North Central doesn't have waitlists, but you can get notified of seat availability with this app
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'twilio-ruby'
availability = 0
puts "Enter the CRN for the PNC course you would like to track:"
crn = gets.chomp.to_s
View gist:6f0abd275e9f76484980
if(comments_open( ) || have_comments()) : ?>
<div class="comments-area">
<?php if ( post_password_required() ) : ?>
<p><?php _e( 'This post is password protected. Enter the password to view any comments ', 'zeon' ); ?></p>
/* Stop the rest of comments.php from being processed,
MelanieS / step_and_time.rb
Last active August 29, 2015 14:02
View step_and_time.rb
#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 =
text = text.to_s
array = text.split("\n")
MelanieS /
Last active August 29, 2015 13:58
Sanitizes user input (names) and prints out in form of "First M. Last"
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";