- What's the difference between a cookie and a session? A session lasts until the browser is closed, a cookie is persistent state stored in a small text file.
- What's serialization and how does it come into play with cookies? The cookies stores serialized data about the session.
- Can a cookie be shared by more than one user? How/why? Probably.
- What would it mean to store a shopping cart in a cookie? The shopping cart would persist from session to session.
- What advantages/disadvantages are there between cookie-stored carts and database-stored carts?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter | |
def self.counter(session) | |
session[:hit_counter] ||= 0 | |
session[:hit_counter] += 1 | |
end | |
end | |
# access with | |
class ItemsController < ApplicationController | |
before_action :load_counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "the idea creation process", :type => :feature do | |
it "goes to the home page" do | |
visit '/' | |
within("#session") do | |
fill_in 'Title', :with => 'great idea' | |
fill_in 'Description', :with => 'so awesome all the things' | |
end | |
click_button 'submit' | |
expect(page).to have_content 'Great Idea' | |
end |
#What are database tables, column, and rows? What's the purpose of each?
Table is a collection of columns and rows
Column is a particular datatype, named with lowercase_separated_with_underscores
Row is a collection of data elements in a table each represented by a column, synonym for record
#How's a database similar and different from a spreadsheet?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cleaner | |
def domain_from_email(email) | |
email.match(/([\w+\-.]+)@([a-z\d\-.]+\.[a-z]{2,4}+)/)[2] | |
end | |
def area_code_only(phone_number) | |
phone_number.match(/(\+*\d{1,})*([ |\(])*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4})/)[3] | |
end | |
def get_secret_message(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH table_scans as ( | |
SELECT relid, | |
tables.idx_scan + tables.seq_scan as all_scans, | |
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes, | |
pg_relation_size(relid) as table_size | |
FROM pg_stat_user_tables as tables | |
), | |
all_writes as ( | |
SELECT sum(writes) as total_writes | |
FROM table_scans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuditInfo < ActiveRecord::Base | |
belongs_to :arc_info | |
def self.import(file) | |
begin | |
if file.path | |
CSV.foreach(file.path, headers: true, col_sep: "\t") do |row| | |
audit_info = AuditInfo.create! row.to_hash | |
arc_info = audit_info.arc_info | |
arc_info.update_attribute(:status, audit_info.computed_status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Forum < ActiveRecord::Base | |
has_many :posts, :inverse_of => :forum | |
end | |
class Post < ActiveRecord::Base | |
belongs_to :forum, :inverse_of => :posts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f.collection_select :some_id_in, Model.all, :id, :name, {}, {:multiple => true} | |
# I have to do the following to get the select field I want: | |
search_form_for @search do |f| | |
f.collection_select :level_in, Log.levels, :to_s, :to_s, {}, { size: Log.levels.length, multiple: true } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model CLINIC has many TREATMENTS | |
<%= check_box_tag "q[treatments_id_eq_ALL][]", treatment.id, {} %> | |
= f.input :category_name_eq, :collection=>Estate::Category.all.map(&:name), :as=>:check_boxes |