Skip to content

Instantly share code, notes, and snippets.

View AhmedNadar's full-sized avatar
🌎
Ready to work remote with you 😀 💻 🤝 👏🏼

Ahmed Nadar AhmedNadar

🌎
Ready to work remote with you 😀 💻 🤝 👏🏼
View GitHub Profile
@AhmedNadar
AhmedNadar / application_controller.rb
Last active November 30, 2023 00:43
How to redirect to a 404 in Rails?
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def not_found
raise ActionController::RoutingError.new('Not Found')
rescue
render_404
end
@AhmedNadar
AhmedNadar / tinyurl.rb
Created May 18, 2012 22:18 — forked from woods/tinyurl.rb
Ruby: A complete URL-shortening web application in Sinatra.
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application
@AhmedNadar
AhmedNadar / blog-posts.html
Created September 29, 2022 04:18
Blog post TailwindCSS style
<div class="px-4 py-16 mx-auto sm:max-w-xl md:max-w-full lg:max-w-screen-xl md:px-24 lg:px-8 lg:py-20">
<div class="grid gap-8 lg:grid-cols-3 sm:max-w-sm sm:mx-auto lg:max-w-full">
<div class="flex">
<div class="pt-1 mr-6 text-center">
<div class="px-2 pb-1 mb-1 border-b border-gray-400">
<p class="text-sm text-blue-500">Jul</p>
</div>
<div class="px-2"><p class="text-lg font-bold">18</p></div>
</div>
<div>
@AhmedNadar
AhmedNadar / rspec_cheatsheet_controller_spec.rb
Created December 26, 2016 08:42
RSpec Controller Test Cheatsheet
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
context "GET index" do
#context "POST create" do
#context "GET show" do
#context "PATCH update" do (or PUT update)
#context "DELETE destroy" do
#context "GET new" do
@AhmedNadar
AhmedNadar / nested_if_statements.rb
Last active May 4, 2021 18:01
Refactor nested IF statements in Ruby
# Before refactor
def set_company
if current_user
if current_user.company_id.present?
if current_user.companies.include?(current_user.company)
current_account = current_user.company
set_current_tenant(current_account)
else
set_current_tenant(nil)
end
@AhmedNadar
AhmedNadar / 0 AWS Cloud9
Created April 4, 2021 01:45 — forked from yshmarov/0 AWS Cloud9
Ruby on Rails 6: Learn 25+ gems and build a Startup MVP 2020
# All AWS C9 envments
https://eu-central-1.console.aws.amazon.com/cloud9/home?region=us-east-1
# Instance management
https://console.aws.amazon.com/ec2/home?region=eu-central-1#Instances:sort=instanceId
# Create AWS C9 environment
https://eu-central-1.console.aws.amazon.com/cloud9/home/create
Setting - set tabs to 2
@AhmedNadar
AhmedNadar / stimulus.md
Created December 14, 2020 09:00 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
@AhmedNadar
AhmedNadar / index.md
Created February 13, 2018 21:23 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

#!/usr/bin/ruby
--database=postgresql
--skip-bundle
--skip-keeps
--skip-test
template=/path-to-template.rb