- 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) => { |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Plan + Subscription Relationship | |
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
end | |
class Plan < ApplicationRecord | |
has_many :subscriptions | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Plan + Subscription Relationship | |
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
end | |
class Plan < ApplicationRecord | |
has_many :subscriptions | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
NewerOlder