Skip to content

Instantly share code, notes, and snippets.

@kangkyu
kangkyu / tl_c_2_q_1
Last active August 29, 2015 14:02
tealeaf academy course 2 Quiz 1
1. why do they call it a relational database?
because they have join and association between tables.
(solution: because the tables within the database are associated with each other. This association can be created with primary and foreign keys and various syntax.)
2. what is SQL?
language used in all database systems
(solution: SQL stands for "structured query language" and it is used to manage operations of a relational database.)
@kangkyu
kangkyu / tl_c_2_q_2
Last active August 29, 2015 14:02
tealeaf academy course 2 Quiz 2
lesson 2 Quiz
1. Name all the 7 or 8 routes exposed by the resources keyword in the routes.rb file. Also name the 4 named routes, and how the request is routed to the controller/action.
name_routes action
GET posts_path posts#index
GET post_path posts#show
GET new_post_path posts#new
POST posts#create
print "the first number: "
a = gets.chomp
print "operator: "
operator = gets.chomp
print "the second number: "
b = gets.chomp
answer = case operator.ord
when 43 then a.to_i + b.to_i
when 45 then a.to_i - b.to_i
@kangkyu
kangkyu / gist:61f7dc23f5b07a1a00dd
Created February 2, 2015 20:53
dismissible flash message in Rails
- if flash[:notice]
= content_tag(:div, class: ["alert", "alert-info", "alert-dismissible"], role: "alert", id: "notice") do
= content_tag(:button, class: "close", type: "button", "data-dismiss"=> "alert") do
= content_tag(:span, escape_once("×"), "aria-hidden"=> "true")
= content_tag(:span, "Close", class: "sr-only")
= flash[:notice]
@kangkyu
kangkyu / gist:90bda70e68af80b6274b
Created February 2, 2015 21:06
dismissible form error message in Rails
- if @task.errors.any?
= content_tag(:div, class: ["alert", "alert-danger", "alert-dismissible"], role: "alert", id: "error-explanation") do
= content_tag(:button, class: "close", type: "button", "data-dismiss"=> "alert") do
= content_tag(:span, escape_once("×"), "aria-hidden"=> "true")
= content_tag(:span, "Close", class: "sr-only")
%p= pluralize(@task.errors.count, "error") + " prohibited this user from being saved"
%ul
- @task.errors.full_messages.each do |msg|
%li= msg
@kangkyu
kangkyu / gist:107e375ec32f4c937f27
Last active August 29, 2015 14:14
9 digit password generation
(0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a + %w(! @ # $ % ^ & * < > ?)
a = _
a.shuffle.pop(9).join
@kangkyu
kangkyu / gist:2b1f9ed1b6ad26cfa6a4
Created February 10, 2015 20:35
html link buttons
<form action="http://google.com">
<input type="submit" value="Go to Google">
</form>
<a href="http://google.com">Go to Google</a>
@kangkyu
kangkyu / gist:962746a4ca2a1110d711
Created April 29, 2015 23:22
create a new repository on the command line
git clone https://github.com/kangkyu/list-of-hamburger-restaurants.git
cd list-of-hamburger-restaurants
echo "# list-of-hamburger-restaurants" >> README.md
git add README.md
git commit -m "first commit"
git push -u origin master

##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

@kangkyu
kangkyu / guard_exercism.md
Last active November 2, 2018 06:19
There should be better ways - hope anybody comment it

Use guard-shell gem.

# terminal (at exercism/ruby/)
gem install guard guard-shell
guard init shell
# Guardfile