Skip to content

Instantly share code, notes, and snippets.

View yigitbacakoglu's full-sized avatar
©️
:trollface:

Yigit C. Bacakoglu yigitbacakoglu

©️
:trollface:
View GitHub Profile

Explain Strategy Pattern and create an example

4- What are some best practices to prevent memory leaks in a Rails application?

class WeeklyEmailJob < ApplicationJob
  queue_as :default

  def perform
    User.find_each do |user|
      UserMailer.weekly_email(user).deliver_now
 end

3- Explain how you would implement a caching strategy for a page that shows the most recent posts to reduce database load.

  • 3.1- Explain fragment Caching

    <table>
    <thead>
      <tr>
        <th>Title</th>
        <th>Description</th>
    

2- Indexing Strategy You have a Post model with a large number of records. Explain how you would determine which columns to index and how to implement these indexes.

       create_table :posts do |t|
         t.string :title
         t.integer :user_id
         t.text :text

1- You have a User model with thousands of records. There is an existing query that performs a full table scan, causing significant performance issues. The query looks like this:

users = User.all.select { |user| user.created_at > 1.year.ago && user.active? }

Tasks:

Identify the Problem:

  • Explain why this query is causing performance issues.
  • Describe what a table scan is and why it’s inefficient in this context.
//search-result.js
//this is a Web Component, NOT a React,Vue or Angular component.
const template = document.createElement('template');
template.innerHTML = `
<style>
div {
margin-top: 20px;
color: green;
}
@yigitbacakoglu
yigitbacakoglu / 1 Setup vps.md
Created January 12, 2021 21:32 — forked from deHelden/"torn" 1 Setup vps.md
Deploy Rails 6.0.0 to VPS(DigitalOcean Ubuntu 19). Nginx, Puma, Capistrano3, PostgreSQL, Rbenv.

SETUP VPS

based on DigitalOcean guide

Create local project

local$ rails new appname -T -d postgresql
local$ rails g scaffold Story title:string body:text
local$ rails db:migrate

install nodejs

sudo apt-get update
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn
@yigitbacakoglu
yigitbacakoglu / izm.json
Last active October 27, 2018 17:18
izm
{"event": {
"title": "Event title",
"excerpt": "Event excerpt",
"description": "Event description",
"group": "A",
"form": [
{
"type": "select",
"options": [
[