Skip to content

Instantly share code, notes, and snippets.

View kkchu791's full-sized avatar

Kirk Chu kkchu791

  • Los Angeles, CA
View GitHub Profile
c = Charlie.new(arg)
c.speak => "hi"
c.run => "Running"
_________________
speak = "Good code"
#optional: 1. rewrite only w/ class methods, 2. persist this method
def count_num(arr)
arr.each_with_object({}) { |i, hash| hash[i] = arr.count(i) }
end
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
class CountTest < Minitest::Test
def test_count
def capitalize_even_(word)
word.downcase
word.gsub /..?/, '3'
end
def capitalize_third(word)
word_array = word.split("")
word_array.map.with_index do |i, index|
if (index + 1) % 3 == 0
word_array[index].upcase

##Quiz: Lesson 3 Solutions

####1. What's the difference between rendering and redirecting? What's the impact with regards to instance variables, view templates?

Rendering displays a view template that accesses the instance variables available in that action. Therefore, instance variables must be declared in that action before the render will work. Redirecting will send a new request to the browser based on the route path that was provided. In this case, the instance variables in that action are not related to the redirected view.

####2. If I need to display a message on the view template, and I'm redirecting, what's the easiest way to accomplish this?

You can use flash, which saves the message with a session. The message will be displayed on your next action and will be removed after that. flash[:message] = 'Your account was created.' redirect_to :back

@kkchu791
kkchu791 / map.md
Last active March 18, 2016 07:08

We are going to setup a map feature that will allow you to see all your adventures on a map and search for adventures by address.

First let’s setup our migrations

Setup an address column

In your command line, generate the migrations for address, latitutde and longitude.

$ rails generate migration AddAddressToAdventures address:string

@kkchu791
kkchu791 / S3.md
Last active March 18, 2016 21:44
Persisting Images

##Setting up Carrierwave for S3

It's time to setup your AWS bucket so your photos can persist on the internet. Instead of pushing photos to your local machine, you will be pushing them to an Amazon Web Service cloud.

You will need your credit card for doing this. It's free to use but be forewarned, be careful not to push your AWS credentials up to any public domains or somebody could use your credit card.

Before we begin let's get our app setup for Amazon Web Services(AWS):

###Adding Fog Gem and Carrierwave Configs

def odd_or_even(array)
array.each do |num|
puts num % 2 == 0 ? "#{num}=even" : "#{num}=odd"
end
end
collection = [12, 23, 456, 123, 4579]
odd_or_even(collection)
def sum(array)
array.reduce(:+)
end
p sum([1,2,3,4,5])
def reverse_word_order(string)
string.split(" ").reverse
end
p reverse_word_order("I want to eat pizza.")
counter = 0
puts "Say something to grandma:"
while counter < 1
say = gets.chomp
if say == "BYE"
puts "LEAVING ALREADY? WELL GOODBYE!"
counter += 1
elsif say == say.upcase
random_year = rand(1930..1950)