Skip to content

Instantly share code, notes, and snippets.

View EfeAgare's full-sized avatar
🎯
Focusing

Efe Agare EfeAgare

🎯
Focusing
View GitHub Profile
@EfeAgare
EfeAgare / crud.rb
Created February 6, 2025 13:29 — forked from rahulnyk/crud.rb
A Ruby on Rails controller concern which adds basic CRUD operations for any model.
# frozen_string_literal: true
# Controller concern for basic crud.
# Can be added to any controller like so
# include Crud
# Assumptions:
# 1. Model class defines a constant called WHITELIST_FIELDS
# as an array of symbols for attributed that are allowed for creating a record.
# 2. Model is serialized elsewhwere. This can be done either by overwriting as_json
# method in the model class, or by using separate serializers. By default as_json
@EfeAgare
EfeAgare / Design-pattern -Strategy--and--Factory--Adapter.rb
Last active December 30, 2024 12:28
Design-pattern -Strategy--and--Factory--Adapter
class CreditCardPayment
def pay(amount)
puts "Processing credit card payment of #{amount}"
end
end
class PayPalPayment
def pay(amount)
puts "Processing PayPal payment of #{amount}"
end
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@EfeAgare
EfeAgare / poodir-notes.md
Created May 15, 2024 13:39 — forked from speric/poodir-notes.md
Notes From "Practical Object-Oriented Design In Ruby" by Sandi Metz

Chapter 1 - Object Oriented Design

The purpose of design is to allow you to do design later, and it's primary goal is to reduce the cost of change.

SOLID Design:

  • Single Responsibility Principle: a class should have only a single responsibility
  • Open-Closed Principle: Software entities should be open for extension, but closed for modification (inherit instead of modifying existing classes).
  • Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
  • Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.
@EfeAgare
EfeAgare / System Design.md
Created April 1, 2024 17:11 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@EfeAgare
EfeAgare / database.yml.example mysql2
Created March 25, 2024 14:16 — forked from erichurst/database.yml.example mysql2
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@EfeAgare
EfeAgare / direct_uploads_controller.rb
Created August 14, 2023 10:52 — forked from arefaslani/direct_uploads_controller.rb
Active Storage's direct uploads controller
# frozen_string_literal: true
# Creates a new blob on the server side in anticipation of a direct-to-service upload from the client side.
# When the client-side upload is completed, the signed_blob_id can be submitted as part of the form to reference
# the blob that was created up front.
class ActiveStorage::DirectUploadsController < ActiveStorage::BaseController
skip_before_action :verify_authenticity_token, :only => [:create]
def create
blob = ActiveStorage::Blob.create_before_direct_upload!(blob_args)
@EfeAgare
EfeAgare / routes.js
Created March 2, 2023 08:29 — forked from rcanepa/routes.js
Private routes with React Router v4
function PrivateRoute ({component: Component, authenticated, ...rest}) {
return (
<Route
{...rest}
render={(props) => authenticated === true
? <Component {...props} />
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
)
}
@EfeAgare
EfeAgare / foobar.rb
Created January 3, 2023 13:21 — forked from rubyginner/foobar.rb
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Foo” instead of the number and for the multiples of five print “Bar”. For numbers which are multiples of both three and five print “FooBar”.
# version 1
for counter in 1..100
if (counter % 3 == 0) && (counter % 5 == 0)
puts 'FooBar'
elsif (counter % 3 == 0)
puts 'Foo'
elsif (counter % 5 == 0)
puts 'Bar'
else

nginx sites-available folder not found

create the sites-available and sites-enabled folder

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled

edit the http block inside /etc/nginx/nginx.conf and add this line

include /etc/nginx/sites-enabled/*;