Skip to content

Instantly share code, notes, and snippets.

View andersr's full-sized avatar
😅
Focusing

Anders Ramsay andersr

😅
Focusing
View GitHub Profile
@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 / 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 / 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
# each
def my_each(array)
i = 0
until i == array.length do
yield(array[i])
i+=1
end
array
end
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",
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?("/")
# 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
# 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
my_deli_line = []
def take_a_number(deli_line, customer_name)
deli_line << customer_name
end
def current_line(deli_line)
print "Current line: "
deli_line.each_with_index do |person_in_line, i|
print "#{i + 1}. #{person_in_line} "
# 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