Skip to content

Instantly share code, notes, and snippets.

View andrewsouthard1's full-sized avatar

Andrew Southard andrewsouthard1

View GitHub Profile
@andrewsouthard1
andrewsouthard1 / quotes_example.rb
Created February 26, 2017 15:38
Example of double quotes over single quotes
puts "Enter your name"
message = gets.chomp
# This will print your message.
puts "Your name is: #{message}"
# This will not.
puts 'Your name is: #{message}'
@andrewsouthard1
andrewsouthard1 / weather.dat
Created March 4, 2017 22:45
CodeKata problem
Dy MxT MnT AvT HDDay AvDP 1HrP TPcpn WxType PDir AvSp Dir MxS SkyC MxR MnR AvSLP
1 88 59 74 53.8 0.00 F 280 9.6 270 17 1.6 93 23 1004.5
2 79 63 71 46.5 0.00 330 8.7 340 23 3.3 70 28 1004.5
3 77 55 66 39.6 0.00 350 5.0 350 9 2.8 59 24 1016.8
4 77 59 68 51.1 0.00 110 9.1 130 12 8.6 62 40 1021.1
5 90 66 78 68.3 0.00 TFH 220 8.3 260 12 6.9 84 55 1014.4
6 81 61 71 63.7 0.00 RFH 030 6.2 030 13 9.7 93 60 1012.7
7 73 57 65 53.0 0.00 RF 050 9.5 050 17 5.3 90 48 1021.8
8 75 54 65 50.0 0.00 FH 160 4.2 150 10 2.6 93 41 1026.3
@andrewsouthard1
andrewsouthard1 / weather_reader.rb
Created March 4, 2017 22:52
CodeKata weather.dat solutiion
# Write a program to output the day number(column one) with the smallest temperature spread(the maximum temperature is the second column, the minimum the third column)
weather_data = File.new("weather.dat")
weather_data_array = []
row_num = 0
weather_data_array = weather_data.map do |x|
x.split(" ")
end
@andrewsouthard1
andrewsouthard1 / figures_controller.rb
Created May 4, 2017 17:00
SW pre API controller example
class FiguresController < ApplicationController
def index
@figures = Figure.all
render 'index.html.erb'
end
end
@andrewsouthard1
andrewsouthard1 / routes.rb
Created May 4, 2017 17:02
SW Pre Api routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/figures' => 'figures#index'
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/figures' => 'figures#index'
namespace :api do
namespace :v1 do
get '/figures' => 'figures#index'
end
end
end
class Api::V1::FiguresController < ApplicationController
def index
@figures = Figure.all
render 'index.json.jbuilder'
end
end
json.array! @figures.each do |figure|
json.id figure.id
json.character figure.character
json.price figure.price
json.description figure.description
end
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Created May 10, 2017 17:29
Binary Search - First Draft
def binary_search(n, arr)
middle = arr[arr.length / 2]
if middle == n
return true
elsif middle < n
i = middle
j = arr.length - 1
middle = i + j / 2
else
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Created May 10, 2017 17:30
Binary Search - Before Comments
def binary_search(n, arr)
middle = arr[arr.length / 2]
i = 0
j = arr.length - 1
while i < j
if middle == n
return true
elsif middle < n
i = middle