Skip to content

Instantly share code, notes, and snippets.

View DanielAmah's full-sized avatar

Daniel Amah DanielAmah

View GitHub Profile
@DanielAmah
DanielAmah / configure-ec2-instance.md
Created April 1, 2024 17:46 — forked from linuxdevops-34/configure-ec2-instance.md
Complete guide for deploying rails application to aws ec2 instance, using capistrano as deploying tool with nginx & puma server

Deploy Rails Application to AWS EC2

Creating AWS EC2 Instance

- login to 'AWS Management Console' (https://aws.amazon.com/console/)
- from 'Services'(in navbar) choose 'EC2'
- from 'Create Instance' section, click on 'Launch Instance'
- then select 'AMI' (Amazon Machine Image), we will be using 'Ubuntu Server 16.04 LTS (HVM)' as example
- select 'Instance Type' as per your requirement
- then click 'Next:Configure Instance Details' to continue
  change 'Configure Instance Details' or used as default settings
import { StyleSheet, Platform } from "react-native";
import { Colors, Typography, Mixins } from "../../styles";
const SIZE_10 = 10;
const SIZE_20 = 20;
const SIZE_30 = 30;
const SIZE_40 = 40;
const PERCENT_100 = "100%";
const BORDER_RADIUS = Typography["BORDER_RADIUS"];
const PRIMARY_COLOR = Colors["PRIMARY"];
@DanielAmah
DanielAmah / index.js
Last active September 9, 2020 22:43
Code review for Konga expo react native app
// Move axios calls to a single file. Say in the utils folder. You can name it api-client.js and add the following line
import axios from "axios";
import { BASE_URL } from "react-native-dotenv";
import AsyncStorage from "@react-native-community/async-storage";
const axiosInstance = axios.create({ baseURL: BASE_URL });
export const storeData = async (key, value) => {

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

## Plan + Subscription Relationship
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Plan < ApplicationRecord
has_many :subscriptions
end
## Plan + Subscription Relationship
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Plan < ApplicationRecord
has_many :subscriptions
end
## We can leverage on eager loading using joins to load the plans with the subscription in one single query.
def index
@subscriptions = Subscription.joins(:plan).order(created_at: :desc).page(params[:page]).per(100)
end
## As a sidenote, I would move the logic for the order into a scope in the Subscription model
## Something like this
class Subscription < ApplicationRecord
## Using Bootstrap 4.0 and with the assumption that kaminari pagination gem is installed.
<div class="container">
<% @subscriptions.each do |subscription| %>
<div class="row">
<div class="col-sm">
<%= subscription.email
<div>
<div class="col-sm">
<%= subscription.plan_id
# Merge Sort Implementation
# makes a recursive call on itself until the condition is met.
# merge all sub-arrays in a sorted manner
def merge_sort(array)
# check if the array is less or equal 1, return the array.
if array.length <= 1
array
else
mid = (array.length / 2).floor # divides the array in half and recursively call the merge_sort method
# First is to check if the array.length is less or equal to 1. If it is, it means the array is already sorted.
# Pick a pivot at random
# Delete the item at a specific index using ruby delete_at inbuild method
# We will using rand to get a randomized index from the array to make as our pivot.
# Save that item as the pivot
# Create a new left and right subarray
# Loop through all the items on the array and compare them with the pivot
# If an item is less than the pivot it should be added to the left subarray and if the item is more than the pivot, it should be added to the right subarray.
def quick_sort(array)