Skip to content

Instantly share code, notes, and snippets.

View andersr's full-sized avatar
😅
Focusing

Anders Ramsay andersr

😅
Focusing
View GitHub Profile
# Create a method, apple_picker, that will pick all the apples out of an array. Implement it with collect and then implement it with select. Write a sentence about how select differs from collect.
fruits = ["orange", "banana", "apple", "orange", "apple", "banana", "orange", "apple"]
#with collect
def apple_picker_collect(array)
array.collect do |array_element|
array_element if array_element == "apple"
end
end
# Write a method that takes a sentence and returns it with each word reversed in place.
my_sentence = "This is a sentence we'll use to reverse each word in the sentence."
def reversed_words(sentence)
reversed_words_sentence = sentence.split(/[" ",.]/).collect do |word|
word.reverse
end
reversed_words_sentence.join(" ")
end
def normalize_path(path)
"#{"#{Dir.pwd}/" if relative_path?(path)}#{path}"
end
def relative_path?(path)
!absolute_path?(path)
end
def absolute_path?(path)
path.start_with?("/")
unsorted_files = [
"foo-1.10.2.ext",
"foo-1.11.ext",
"foo-1.3.ext",
"foo-1.50.ext",
"foo-1.8.7.ext",
"foo-1.9.3.ext",
"foo-1.ext",
"foo-10.1.ext",
"foo-10.ext",
# each
def my_each(array)
i = 0
until i == array.length do
yield(array[i])
i+=1
end
array
end
@andersr
andersr / hello_rack
Created October 21, 2013 13:33
hello_rack
require 'rack'
class App
def call(env)
[200, {'Content-Type'=>'text/plain'}, ["Hello Rack!"]]
end
@andersr
andersr / gist:10471560
Last active November 15, 2021 23:34
Pseudocode Example: A Signup Form

#Pseudocode Example: A Signup Form ##Entities

  • Email field: input type = email, placeholder: “[email protected]
  • Password field: input type = password, placeholder: “Password”
  • Password confirmation field: input type = password, placeholder: “Password again”
  • Signup submit: value: “Sign Up”, default state, disabled

##Signup Flow/Logic

###On leave focus of email field

@andersr
andersr / gist:11004954
Last active January 12, 2025 17:58
Explain to an alien how to make a PBJ Sandwich

#Alien Sandwich A numbered list of instructions for explaining to an alien how to make a peanut butter and jelly sandwich

###Collect and define items needed to make a Peanut Butter and Jelly Sandwich.

  • "PBJ-sandwich" = Peanut Butter and Jelly Sandwich (the thing we will be making)
  • "pb-jar" = the cylindrical object in front of you containing a brown substance
  • "jelly-jar" = the cylindrical object in front of you containing a red substance
  • "plate" = the flat white object in front of you
  • "bread-loaf" = the brown, rectangle-shaped thing in front of you that is soft to the touch
  • "knife" = the narrow, silver-colored thing in front you with one side that is sharp to the touch. The side that is not sharp is the side you grasp. The knife can be used for two purposes: cutting and spreading. When used for cutting, grasp the knife and face the sharp part downward. When used for spreading, grasp the knife and and turn the knife so that the sharp part is horizontal.
@andersr
andersr / alien_sandwich_workshop.md
Last active August 29, 2015 14:00
Alien Sandwich Workshop

Drawing of Alien with materials for making a PBJ sandwich

#Explain to an Alien How to Make a Peanut Butter and Jelly Sandwich

  • An alien is positioned in front of a table.
  • On the table is a plate, a knife, a jar of jelly, a jar of peanut butter, and a loaf of bread.
  • The alien can read and recognize English and English grammar, but may not understand what specific words mean.

##Your assignment

  • Pair up
  • Together, create a list of instructions for making a peanut butter and jelly sandwich.
@andersr
andersr / convert_pseodo_code_to_test.rb
Last active August 29, 2015 14:00
Example of converting a pseudo code line into a test
describe "Cut two slices of bread and place on the plate" do
it "grasps the Knife in a cutting grasp" do {
#code that attempts to complete this task
#if it passes, it returns something to hte effect of "test passed"
#if it fails, it returns a message like "grasps the Knife in a cutting grasp" failed, for the following reasons, eg no 'No Knife was found'
}
# Grasp the bread-loaf and place it on the table, such that it is directly below the knife.
# Position the bread-loaf such that it is perpendicular to the cutting edge of the knife and move the bread-loaf laterally until only a half inch is below the knife.