Skip to content

Instantly share code, notes, and snippets.

View ashleygwilliams's full-sized avatar

ashley williams ashleygwilliams

  • 18:07 (UTC -05:00)
View GitHub Profile
# Write a method `format` for the class integer that converts the number to a
# string and adds commas at the appropriate places
#To test your solution run `rspec format_number_spec.rb` in your terminal
class Integer
def format
#code goes here...
end
# Write a method on String called `count_sentences` that returns the number of
# sentences in the string it is called on
class String
def count_sentences
# code goes here
end
end
def fizzbuzz_rand_sequence15_0123
(0..99).map {|i| srand(1781773465) if (i%15).zero?; [i+1, "Fizz", "Buzz", "FizzBuzz"][rand(4)]}
end
#Write a method called is_a_teenager that takes age as a parameter and returns
#true/false depending on whether the age indicates that the person is a
#teenager
#To test your solution run `rspec teenager_spec.rb` in your terminal
def is_a_teenager? age
age <= 19 && age >= 13
end
@ashleygwilliams
ashleygwilliams / ruby_each.md
Created October 22, 2013 18:58
walking through the each method in ruby

Let's do this with a simpler example:

Let's write a program that prints each word in an array to the console.

Here's our array words = ["Pikachu", "Bulbasaur", "Charmander"]

Here's our code:

words.each do |word|
 puts word
@ashleygwilliams
ashleygwilliams / git-workflow.txt
Created October 22, 2013 17:23
an introductory git workflow
1. make a project folder
2. git init inside project folder
3. create file(s)/folder(s)
- touch, mkrdir (actions)
- sublime, vim (editor)
4. add files/changes: git add <file>
5. commit files: git commit -m "<message>"
(if you get stuck in vim, :wq)
6. go to github and make a repo
7. connect the local with the remote repository
<div id="icons">
<a href="#txt1"><img src="http://placekitten.com/200/200"/></a>
<a href="#txt2"><img src="http://placekitten.com/201/200"/></a>
<a href="#txt3"><img src="http://placekitten.com/202/200"/></a>
<a href="#txt4"><img src="http://placekitten.com/206/200"/></a>
</div>
<div id="text">
<p id="txt1">Chew iPad power cord use lap as chair stretch...</p>
<p id="txt2">Intently sniff hand intrigued by the shower...</p>
<p id="txt3">Hopped up on goofballs. Throwup on your pillow...</p>
-module(listmaker).
-export([add_to_head/2, add_to_tail/2, add_to_tail_recursive/2]).
-import(flatten, [flatten/1]).
%% add a non-list item to the beginning of a list
-spec(add_to_head(any(), list()) -> list()).
add_to_head(Item, List) -> [Item | List].
%% add a non-list item to the end of a list
-spec(add_to_tail(any(), list()) -> list()).
puts self.respond_to? :poop
def self.poop
"poop"
end
puts self.respond_to? :poop
puts poop
puts self.methods.include? :poop
puts self.class
def step1(x)
if x==1
puts "it was all a dream"
end
return 2
end
def step2(x)
if x==2
puts "i used to read"