\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Abdulla Achilov (artifactzone)} \pdfinfo{ /Title (ruby-interview-seniour.pdf) /Creator (Cheatography) /Author (Abdulla Achilov (artifactzone)) /Subject (ruby-interview-seniour Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{ruby-interview-seniour Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Abdulla Achilov (artifactzone)} via \textcolor{DarkBackground}{\uline{cheatography.com/129081/cs/25460/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Abdulla Achilov (artifactzone) \\ \uline{cheatography.com/artifactzone} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 1st May, 2024.\\ Updated 1st May, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{OOP short}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Object Oriented Programming} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Encapsulation: Bundling data and methods that operate on it, restricting direct access.} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Abstraction: Hiding complex details, presenting a simple interface.} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Inheritance: Child classes can inherit methods and properties from parent classes.} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Polymorphism: Allows using an object like its parent while maintaining its own unique behavior.} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{0.85825 cm} x{2.57475 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{OOP}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Encapsulation} & private public methods \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Abstractions} & user blindly \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{Inheritance} & u can replace parent methods with child methods \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{Polymorphism} & Polymorphism gives us a way to use an object exactly like its parent but keeping its own methods as they are \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.64784 cm} x{1.78516 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Method Access Control short}} \tn % Row 0 \SetRowColor{LightBackground} Public: Methods accessible by anyone. & Protected: Only accessible by the defining class and its subclasses. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Private: Only accessible by the current object; cannot be called with an explicit receiver.} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Method Access Control}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Public methods can be called by everyone - no access control is enforced. A class's instance methods (these do not belong only to one object; instead, every instance of the class can call them) are public by default; anyone can call them. The initialize method is always private.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Protected methods can be invoked only by objects of the defining class and its subclasses. Access is kept within the family. However, usage of protected is limited.} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Private methods cannot be called with an explicit receiver - the receiver is always self. This means that private methods can be called only in the context of the current object; you cannot invoke another object's private methods.} \tn % Row Count 15 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{ActiveJob}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{emails} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{image processing} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{external API call} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{analytics calculations} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Rails Enige}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Rails::Engine allows you to wrap a specific Rails application or subset of functionality and share it with other applications or within a larger packaged application. Every Rails::Application is just an engine, which allows for simple feature and application sharing. \newline \newline Any Rails::Engine is also a Rails::Railtie, so the same methods (like rake\_tasks and generators) and configuration options that are available in railties can also be used in engines. \newline \newline \# lib/my\_engine.rb \newline module MyEngine \newline class Engine \textless{} Rails::Engine \newline end \newline end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{0.96124 cm} x{2.47176 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{RESTful}} \tn % Row 0 \SetRowColor{LightBackground} INDEX & GET users \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} NEW & GET users/new \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} SHOW & GET users/1 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} EDIT & GET users/1/edit \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} UPDATE & PUT/PATCH users/1 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} DELETE & GET users/1/delete \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} DESTROY & DELETE users/1 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} CREAET & POST users \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{How should you test routes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\# Asserts that the default action is generated for a route with no action \newline assert\_generates "/items", controller: "items", action: "index" \newline \newline \# Tests that the list action is properly routed \newline assert\_generates "/items/list", controller: "items", action: "list" \newline \newline \# Tests the generation of a route with a parameter \newline assert\_generates "/items/list/1", \{ controller: "items", action: "list", id: "1" \} \newline \newline \# Asserts that the generated route gives us our custom route \newline assert\_generates "changesets/12", \{ controller: 'scm', action: 'show\_diff', revision: "12" \} \newline \newline \# Asserts that POSTing to /items will call the create action on ItemsController \newline assert\_recognizes(\{controller: 'items', action: 'create'\}, \{path: 'items', method: :post\})} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Active Record short}} \tn % Row 0 \SetRowColor{LightBackground} ORM: Maps objects to database tables, providing methods to represent models, relationships, and validations. & Associations: Defines relationships like has\_many, belongs\_to, and has\_many :through. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Conventions: Naming conventions for tables and associations, e.g., User has many Posts.} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{ActiveRecord}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database. It is an implementation of the Active Record pattern which itself is a description of an Object Relational Mapping system. \newline % Row Count 8 (+ 8) In Active Record, objects carry both persistent data and behavior which operates on that data. Active Record takes the opinion that ensuring data access logic as part of the object will educate users of that object on how to write to and read from the database. \newline % Row Count 14 (+ 6) Active Record gives us several mechanisms, the most important being the ability to: \newline % Row Count 16 (+ 2) Represent models and their data. \newline % Row Count 17 (+ 1) Represent associations between these models. \newline % Row Count 18 (+ 1) Represent inheritance hierarchies through related models. \newline % Row Count 20 (+ 2) Validate models before they get persisted to the database. \newline % Row Count 22 (+ 2) Perform database operations in an object-oriented fashion.% Row Count 24 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Object Relational Mapping}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Object Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.% Row Count 9 (+ 9) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.85382 cm} x{1.57918 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Active Record conventions}} \tn % Row 0 \SetRowColor{LightBackground} user has\_many & posts \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Article & articles \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} PostComment & post\_comments \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Mouse & mice \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} post belongs\_to & user \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Fat controllers}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{retrieving data from the model, transforming it as appropriate for the view, and then passing it to the view for rendering} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Refactor of models}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{If some code does work from the point of view of an ActiveRecord model, it can go into the model. \newline % Row Count 2 (+ 2) If some code does work that spans multiple tables/objects, and doesn't really have a clear owner, it could go into a Service Object. \newline % Row Count 5 (+ 3) Anything that's attribute-like (like attributes calculated from associations or other attributes) should go into your ActiveRecord model. \newline % Row Count 8 (+ 3) If you have logic that has to orchestrate the saving or updating of multiple models at once, it should go into an ActiveModel Form Object. \newline % Row Count 11 (+ 3) If code is mostly meant for displaying or formatting models in a view, it should go into a Rails helper or a Presenter.% Row Count 14 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{E-Tags short}} \tn % Row 0 \SetRowColor{LightBackground} Definition: Response headers that identify a resource version, aiding in caching and content validation. & Usage: If-None-Match header checks if a resource has changed, allowing "304 Not Modified" responses. \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{E-tags}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Definition: An E-tag is a response header used to identify a specific version of a resource on a server. It's often a unique identifier, such as a hash or a version number, that changes whenever the resource changes.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Caching: E-tags are crucial for caching mechanisms. When a client requests a resource, it receives an E-tag with the response. On subsequent requests, the client can send this E-tag back to the server with an "If-None-Match" header, allowing the server to determine if the resource has changed. If it hasn't, the server can respond with a "304 Not Modified" status, reducing bandwidth usage by skipping the resource transfer.} \tn % Row Count 14 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Content Validation: E-tags also help ensure content integrity. By comparing E-tags, clients and servers can verify that they are accessing the correct version of a resource, ensuring consistency between versions.} \tn % Row Count 19 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Implementation: In practice, E-tags are generated and managed by the server. Developers might create custom logic to generate these tags or rely on server frameworks that handle them automatically.} \tn % Row Count 23 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{E-tags are particularly useful in: Web APIs: For API responses, E-tags help reduce data transfer and ensure clients receive the latest information. Static Content: For web pages, CSS files, and JavaScript assets, E-tags prevent redundant downloads, speeding up page loads.} \tn % Row Count 29 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{SOLID short}} \tn % Row 0 \SetRowColor{LightBackground} Single Responsibility: A class should handle one responsibility. & Open/Closed: Classes should be open for extension but closed for modification. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Liskov Substitution: Subtypes should be substitutable for their parent types. & Interface Segregation: Clients shouldn't depend on unused interfaces. \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Dependency Inversion: High-level modules should depend on abstractions, not low-level modules.} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{SOLID}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Single Responsibility Principle: A class should have only one reason to change, meaning it should handle a single responsibility or functionality. This helps create modular code that's easier to understand and maintain.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Open/Closed Principle: Software entities (such as classes or functions) should be open for extension but closed for modification. This means you should be able to add new functionality without altering existing code, typically through inheritance or composition.} \tn % Row Count 11 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Liskov Substitution Principle: Subtypes should be substitutable for their base types. In other words, derived classes should be able to replace their parent classes without affecting the functionality of the application.} \tn % Row Count 16 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Interface Segregation Principle: Clients should not be forced to depend on interfaces they do not use. This encourages the creation of small, specific interfaces, rather than large, general ones, making the design more flexible and reducing coupling.} \tn % Row Count 22 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Dependency Inversion Principle: High-level modules should not depend on low-level modules; both should depend on abstractions. This means code should rely on abstract interfaces rather than concrete implementations, promoting decoupling and making the system easier to extend and maintain.} \tn % Row Count 28 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{self}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{The keyword self in Ruby gives you access to the current object – the object that is receiving the current message. To explain: a method call in Ruby is actually the sending of a message to a receiver} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.39495 cm} p{0.39495 cm} x{1.23751 cm} p{0.60559 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{3.833cm}}{\bf\textcolor{white}{Ruby method lookup path}} \tn % Row 0 \SetRowColor{LightBackground} user & User & Parent::User & Object \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.78516 cm} x{1.64784 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Ruby callbacks}} \tn % Row 0 \SetRowColor{LightBackground} Create & Update \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} before\_save; before\_validation & after\_update; after\_commit \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Destroying & Touch \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} around\_destroy; after\_rollback & after\_initialize; after\_find \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Proc and lambda}} \tn % Row 0 \SetRowColor{LightBackground} Lambda & Proc \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Proc class (lambda) & Proc class \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} checks the number of arguments passed to it & proc does not \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} lambda returns, it passes control back to the calling method & proc returns, it does so immediately, without going back to the calling method \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Asset Pipeline}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The asset pipeline provides a framework to concatenate and minify or \newline % Row Count 2 (+ 2) compress JavaScript and CSS assets. It also adds the ability to write these assets \newline % Row Count 4 (+ 2) in other languages and pre-processors such as CoffeeScript, Sass, and ERB% Row Count 6 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Caching short}} \tn % Row 0 \SetRowColor{LightBackground} Page Caching: Caches entire pages directly to disk. & Action Caching: Similar to page caching but runs before filters. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Fragment Caching: Caches parts of views separately. & Low-Level Caching: Allows caching values or query results, reducing database load. \tn % Row Count 9 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.2132 cm} x{1.5165 cm} p{0.3033 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{3.833cm}}{\bf\textcolor{white}{Caching 1/2}} \tn % Row 0 \SetRowColor{LightBackground} Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the web server (i.e. Apache or NGINX) without having to go through the entire Rails stack. While this is super fast it can't be applied to every situation (such as pages that need \seqsplit{authentication).} Also, because the web server is serving a file directly from the filesystem you will need to implement cache expiration. & Page Caching cannot be used for actions that have before filters - for example, pages that require authentication. This is where Action Caching comes in. Action Caching works like Page Caching except the incoming web request hits the Rails stack so that before filters can be run on it before the cache is served. This allows authentication and other restrictions to be run while still serving the result of the output from a cached copy. & \tn % Row Count 27 (+ 27) % Row 1 \SetRowColor{white} \mymulticolumn{3}{x{3.833cm}}{Dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. When different parts of the page need to be cached and expired separately you can use Fragment Caching. Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in.} \tn % Row Count 35 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Caching 2/2}} \tn % Row 0 \SetRowColor{LightBackground} Low-level & SQL caching \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Sometimes you need to cache a particular value or query result instead of caching view fragments. Rails' caching mechanism works great for storing any kind of information. & Query caching is a Rails feature that caches the result set returned by each query. If Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again. \tn % Row Count 13 (+ 12) % Row 2 \SetRowColor{LightBackground} Rails.cache.fetch("\#\{cache\_key\_with\_version\}/competing\_price", expires\_in: 12.hours) do \seqsplit{Competitor::API.find\_price(id)} end & User.first; User.first \tn % Row Count 20 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Migrations}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Rails provides a set of rake tasks to work with migrations which boil down to running certain sets of migrations. \newline % Row Count 3 (+ 3) The very first migration related rake task you will use will probably be rake db:migrate. In its most basic form it just runs the up or change method for all the migrations that have not yet been run. If there are no such migrations, it exits. It will run these migrations in order based on the date of the migration. \newline % Row Count 10 (+ 7) Note that running the db:migrate also invokes the db:schema:dump task, which will update your db/schema.rb file to match the structure of your database.% Row Count 14 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Associations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{belongs\_to} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{has\_one} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{has\_many} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{has\_many :through} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{has\_one :through} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{has\_and\_belongs\_to\_many} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{scopes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Scoping allows you to specify commonly-used queries(it can be considered as a shortcut for long or most frequently used queries) which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as where, joins and includes. All scope methods will return an ActiveRecord::Relation object which will allow for further methods (such as other scopes) to be called on it.% Row Count 9 (+ 9) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Basic info}} \tn % Row 0 \SetRowColor{LightBackground} Class is the blueprint from which individual objects are created & class variables are shared between a class and all its subclasses \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Objects are instances of the class. & class instance variables only belong to one specific class \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Use a constructor in Ruby}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{def initialize(\{\});end;} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{getter and setter methods in Ruby}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{attr\_reader} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{attr\_accessor} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Class and a module}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Modules are collections of methods and constants.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{They cannot generate instances. Classes may generate instances (objects), and have per-instance state (instance variables).} \tn % Row Count 4 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{everything is an object in Ruby}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Every data type that we work with is a class and classes are objects. Even the Object class is an object. Strings, integers, floats, hashes, arrays, symbols, classes, modules, errors and more are all objects.} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Rack}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Rack is the underlying technology behind nearly all of the web frameworks in the Ruby world. \newline % Row Count 2 (+ 2) "Rack" is actually a few different things: \newline % Row Count 3 (+ 1) An architecture - Rack defines a very simple interface, and any code that conforms \newline % Row Count 5 (+ 2) to this interface can be used in a Rack application. This makes it very easy to build small, \newline % Row Count 7 (+ 2) focused, and reusable bits of code and then use Rack to compose these bits into a larger application. \newline % Row Count 10 (+ 3) A Ruby gem - Rack is is distributed as a Ruby gem that provides the glue code needed to compose our code. \newline % Row Count 13 (+ 3) require "rack" \newline % Row Count 14 (+ 1) require "thin" \newline % Row Count 15 (+ 1) class HelloWorld \newline % Row Count 16 (+ 1) def call(env) \newline % Row Count 17 (+ 1) {[} 200, \{ "Content-Type" =\textgreater{} "text/plain" \}, {[}"Hello World"{]} {]} \newline % Row Count 19 (+ 2) end \newline % Row Count 20 (+ 1) end \newline % Row Count 21 (+ 1) Rack::Handler::Thin.run HelloWorld.new \newline % Row Count 22 (+ 1) \seqsplit{https://github.com/sunlightlabs/rack-honeypot} \newline % Row Count 23 (+ 1) Rack defines a very simple interface. Rack compliant code must have the following three characteristics: \newline % Row Count 26 (+ 3) It must respond to call \newline % Row Count 27 (+ 1) The call method must accept a single argument - \newline % Row Count 28 (+ 1) This argument is typically called env or environment, and it bundles all of the data about the request. \newline % Row Count 31 (+ 3) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Rack (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The call method must return an array of three elements These elements are, in order, \newline % Row Count 2 (+ 2) status for the HTTP status code, headers, and body for the actual content of the response. \newline % Row Count 4 (+ 2) A nice side effect of the call interface is that procs and lambdas can be used as Rack objects. \newline % Row Count 6 (+ 2) Middleware are the building blocks of larger applications built using the Rack pattern. \newline % Row Count 8 (+ 2) Each middleware is a Rack compatible application, and our final application is built by composing together, or nesting these middleware. \newline % Row Count 11 (+ 3) Unlike base Rack apps, middleware must be classes as they need to have an initializer which will be passed the next app in the chain. \newline % Row Count 14 (+ 3) For our first middleware example, we'll introduce a middleware that logs the amount of time the request took and adds that to the response. \newline % Row Count 17 (+ 3) To begin, we'll update our core Rack app to sleep for 3 seconds to give us something worth logging, and then we'll build our middleware: \newline % Row Count 20 (+ 3) Rack::Handler::Thin.run \seqsplit{LoggingMiddleware.new(app)} \newline % Row Count 22 (+ 2) Middleware are perfect for non-app specific logic. \newline % Row Count 24 (+ 2) Things like setting caching headers, logging, parsing the request object, etc. all are great use cases for Rack middleware. \newline % Row Count 27 (+ 3) For example, in Rails, cookie parsing, sessions, and param parsing are all handled by Middleware.% Row Count 29 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Rack Middleware}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{require "rack" \newline require "thin" \newline \newline app = -\textgreater{} (env) do \newline sleep 3 \newline {[} 200, \{ "Content-Type" =\textgreater{} "text/plain" \}, {[}"Hello World\textbackslash{}n"{]} {]} \newline end \newline \newline class LoggingMiddleware \newline def initialize(app) \newline @app = app \newline end \newline \newline def call(env) \newline before = Time.now.to\_i \newline status, headers, body = @app.call(env) \newline after = Time.now.to\_i \newline log\_message = "App took \#\{after - before\} seconds." \newline \newline {[}status, headers, body \textless{}\textless{} log\_message{]} \newline end \newline end \newline \newline Rack::Handler::Thin.run \seqsplit{LoggingMiddleware.new(app)}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{optimistic pessimistic locking}} \tn % Row 0 \SetRowColor{LightBackground} Optimistic & Pessimistic \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Optimistic locking is a mechanism to prevent data overrides by assuming that a database transaction conflict rarely happens & When one user is editing a record and we maintain an exclusive lock on that record, another user is prevented from modifying this record until the lock is released or the transaction is completed. This explicit locking is known as a pessimistic lock \tn % Row Count 14 (+ 13) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{uses a "version-number" column to track changes in each table that needs to implement concurrent access} \tn % Row Count 17 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Optimistic locking is just a mechanism to prevent processes from overwriting changes by another process. Optimistic locking is not a magic wand to manage or auto-merge any conflicting changes. It can only allow users to alert or notify about such conflicting changes.} \tn % Row Count 23 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Optimistic locking works by just comparing the value of the "version" column. Thus, optimistic locking is not a real database lock} \tn % Row Count 26 (+ 3) % Row 5 \SetRowColor{white} multiple users can read the same resource at the same time but if more then one tries to modify the database , then we prevent it & multiple users will not be able to read while others are reading \tn % Row Count 33 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{optimistic pessimistic locking (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Advisory Lock} \tn % Row Count 1 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{An advisory lock is a voluntary locking mechanism that requires transactions to explicitly request and release locks on resources. How it works: Transactions explicitly acquire advisory locks on resources, signaling to other transactions that they should also respect these locks. Advisory locks don't inherently block transactions; instead, they rely on voluntary adherence. Use cases: Advisory locks are useful in systems where developers want fine-grained control over concurrency or when specific business logic dictates locking behavior, such as file management systems.} \tn % Row Count 13 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{postgres indexes}} \tn % Row 0 \SetRowColor{LightBackground} B-tree Index: Default type, suitable for equality (=) and range queries (\textless{}, \textgreater{}, BETWEEN). & Hash Index: Optimized for equality comparisons (=). \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} GIN Index: Useful for indexing array, JSONB, and full-text search fields. & GiST Index: Flexible structure for complex data types, including geometric and range queries. \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Partial Index: create index where condition} \tn % Row Count 11 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{The order of columns in a multi-column index affects how well it optimizes queries. Consider these factors: Query Patterns: Place the column most frequently used in queries or filters first. This increases the chances of the index being utilized effectively. Selective Columns: Columns with high selectivity (i.e., a wide range of unique values) should appear first. This maximizes the potential for early filtering. Combining Columns: If queries often filter by a combination of columns, ensure the index order matches the most common query patterns.} \tn % Row Count 23 (+ 12) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Highiest cardinality means better index. Columns with high cardinality have many unique values relative to the total number of rows.} \tn % Row Count 26 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{singleton methods, Eigenclass}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{In Ruby, a class is an object. Indeed, a class is literally an instance of the class Class The eigenclass is an unnamed instance of the class Class attached to an object and which instance methods are used as singleton methods of the defined object.} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{RubyGems}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The RubyGems software allows you to easily download, install, and use ruby software packages on your system. \newline % Row Count 3 (+ 3) The software package is called a "gem" which contains a packaged Ruby application or library.% Row Count 5 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Eigenclass}} \tn % Row 0 \SetRowColor{LightBackground} An eigenclass is a unique, anonymous class associated with an individual object in Ruby. It allows for the addition of methods directly to that object, without affecting other instances of its class. & Every Ruby object has an associated eigenclass, which is created automatically the first time a singleton method (a method defined only for that specific object) is added to it. The eigenclass stores these singleton methods. \tn % Row Count 12 (+ 12) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Eigenclasses can be useful in Rails for extending or modifying specific instances of classes without affecting the class as a whole: Singleton Methods: You might use a singleton method to add behavior directly to an individual object, such as a single instance of a model, without altering its class definition. Meta-Programming: Eigenclasses play a role in meta-programming techniques, allowing for dynamic modifications to objects.} \tn % Row Count 21 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{class User \textless{} ApplicationRecord end user = User.find(1) def user.greet "Hello, \#\{self.name\}!" end puts user.greet \# Outputs "Hello, {[}User's name{]}!"} \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{build your own Ruby gem}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{.gemspec} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{lib/mygem} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{gem build .gemspec} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Use the basic lib/gem.rb and lib/gem/ structure for code.} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Put any executables in bin, any data files in data and tests in test or spec.} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Don't require or depend upon files outside of the load path. (VERSION files often seem to live in odd places in gems.)} \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Do not require 'rubygems'.} \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Do not tamper with the \$LOAD\_PATH.} \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.72792 cm} p{0.66726 cm} x{1.63782 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{3.833cm}}{\bf\textcolor{white}{Favourites gems}} \tn % Row 0 \SetRowColor{LightBackground} rspec & \seqsplit{cancancan} & \seqsplit{ActiveModelSerializers} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{capistrano} & sidekiq & annotate \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Filters in controllers}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{class ChangesController \textless{} ApplicationController \newline around\_action :wrap\_in\_transaction, only: :show \newline \newline private \newline \newline def wrap\_in\_transaction \newline \seqsplit{ActiveRecord::Base.transaction} do \newline begin \newline yield \newline ensure \newline raise ActiveRecord::Rollback \newline end \newline end \newline end \newline end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Strong params}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Strong Parameters is a feature of Rails that prevents assigning request parameters to objects unless they have been explicitly permitted. It has its own DSL (Domain Specific Language, or in other words, a predefined syntax it understands), that allows you to indicate what parameters should be allowed. It also lets you indicate if each parameter should be a hash, array or scalar (i.e. integer, string, etc.), as well as some other functionality% Row Count 9 (+ 9) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Controller specs}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Send http requests to application and writing assertions about the response.% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{yield, content\_for}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{They are opposite ends of the rendering process, with yield specifying where content goes, and content\_for specifying what the actual content is. \newline % Row Count 3 (+ 3) The best practice is to use yield in your layouts, and content\_for in your views. There is a special second use for content\_for, where you give it no block and it returns the previously rendered content. This is primarily for use in helper methods where yield cannot work. Within your views, the best practice is to stick to yield :my\_content to recall the content, and content\_for :my\_content do...end to render the content.% Row Count 12 (+ 9) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.95681 cm} x{1.47619 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Security}} \tn % Row 0 \SetRowColor{LightBackground} Content Security Policy & xss inj \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{https://rails-sqli.org/} & sql inj \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} use ssl & session hijacking \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} reset\_session (expire) & session fixation \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Password}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Iterate over an HMAC with a random salt for about a 100ms duration and save the salt with the hash. Use functions such as password\_hash, PBKDF2, Bcrypt and similar functions.} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{https (ssl)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{HTTPS protects the communication between your browser and server from being intercepted and tampered with by attackers. This provides confidentiality, integrity and authentication to the vast majority of today's WWW traffic. Any website that shows a lock icon in the address bar is using HTTPS% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Unit testing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures—are tested to determine whether they are fit for use% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.03122 cm} x{1.00089 cm} x{1.00089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{3.833cm}}{\bf\textcolor{white}{Patterns}} \tn % Row 0 \SetRowColor{LightBackground} Creational & Structural & Behaviour \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Abstract Factory is a creational design pattern that lets you produce families of related objects without specifying their concrete classes. & Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate. & Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they're observing. \tn % Row Count 15 (+ 14) % Row 2 \SetRowColor{LightBackground} Singletone & Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. & Command is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This \seqsplit{transformation} lets you parameterize methods with different requests, delay or queue a request's execution, and support undoable operations. \tn % Row Count 37 (+ 22) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{x{1.03122 cm} x{1.00089 cm} x{1.00089 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{3.833cm}}{\bf\textcolor{white}{Patterns (cont)}} \tn % Row 3 \SetRowColor{LightBackground} Prototype & Facade & Chain of \seqsplit{responsibility} \tn % Row Count 2 (+ 2) % Row 4 \SetRowColor{white} Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. & Bridge is a structural design pattern that lets you split a large class or a set of closely related classes into two separate \seqsplit{hierarchies—abstraction} and \seqsplit{implementation—which} can be developed \seqsplit{independently} of each other. & \tn % Row Count 20 (+ 18) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{What is the primary technique for writing a test}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Test actual result of execution, integration tests, rather than only unit tests. Write scenario as a complex test% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Eigenclass}} \tn % Row 0 \SetRowColor{LightBackground} An eigenclass is a unique, anonymous class associated with an individual object in Ruby. It allows for the addition of methods directly to that object, without affecting other instances of its class. & Every Ruby object has an associated eigenclass, which is created automatically the first time a singleton method (a method defined only for that specific object) is added to it. The eigenclass stores these singleton methods. \tn % Row Count 12 (+ 12) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Eigenclasses can be useful in Rails for extending or modifying specific instances of classes without affecting the class as a whole: Singleton Methods: You might use a singleton method to add behavior directly to an individual object, such as a single instance of a model, without altering its class definition. Meta-Programming: Eigenclasses play a role in meta-programming techniques, allowing for dynamic modifications to objects.} \tn % Row Count 21 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{```class User \textless{} ApplicationRecord end user = User.find(1) def user.greet "Hello, \#\{self.name\}!" end puts user.greet \# Outputs "Hello, {[}User's name{]}!"```} \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}