Skip to content

Instantly share code, notes, and snippets.

View OfTheDelmer's full-sized avatar

Delmer OfTheDelmer

View GitHub Profile
@OfTheDelmer
OfTheDelmer / sinatra.md
Created January 15, 2014 18:09
Intro to web frameworks and sinatra

Intro to Web Application Frameworks

First Principles with Sinatra

OBJECTIVE
We will use the concepts discussed in client-server model and request-response handling in a simple web application, use our first web application framework, and be able to build a simple web application.
Self-Assesment
@OfTheDelmer
OfTheDelmer / adventure.rb
Created January 9, 2014 17:55
adventure code along
# Classes and Objects
## Code Along
story_hash = {
"question" => "Welcome to the haunted hotel. What room would you like to go into?",
"room 1" => "you're dead",
"room 2" => { "question" => "You picked a good room. What would like to do?",
"sleep" => "You're rested for the morning",
@OfTheDelmer
OfTheDelmer / classes_lec.md
Last active January 2, 2016 15:09
Lecture Points on Classes

Intro to Classes

Methods, Variables, and All That

Learning Objectives

  • Understand difference between obbjects and classes
  • Understand how objects are referenced
  • Understand getters and setters
  • Understand attr_writer, attr_reader, attr_accessor
  • Understand instance variables and instance methods
@OfTheDelmer
OfTheDelmer / bounded_box
Created December 6, 2013 02:44
bound_box.rb
#takes two squares
def check_square(square)
if(square[0][0] > square[1][0])
puts square
square[0][0], square[1][0] = square[1][0], square[0][0]
end
@OfTheDelmer
OfTheDelmer / bfs_and_trees.rb
Created December 4, 2013 00:19
trees with many children and BFS
class BinTree
attr_accessor :left, :right, :val
def initialize(val)
@left = nil
@right = nil
@val = val
end
class BinTree
attr_accessor :left, :right, :val
def initialize(val)
@left = nil
@right = nil
@val = val
end

Exercises/Lab for Linked Lists

1.) Write a function called last that finds the last node in the list.

2.) Write a function called count that gets the length of linked list. Don't use the #count method.

3.) Write a function called average that sums a linked list of numbers and divides it by the length.

4.) Write a function to reverse a linked list.

###
# Node List
###
class Node
attr_accessor :val, :next
def initialize(val, next_ref =nil)
@val=val
@next=next_ref
end
###
# Node List
###
class Node
attr_accessor :val, :next
def initialize(val,next=nil)
@val=val
@next=next
end