Skip to content

Instantly share code, notes, and snippets.

View warrenlalata's full-sized avatar
🏠
Working from home

Warren Lalata warrenlalata

🏠
Working from home
View GitHub Profile
@warrenlalata
warrenlalata / Capistrano Commands
Created July 3, 2017 08:33 — forked from clara101/Capistrano Commands
Deploy Rails 4 to AWS EC2(Ubuntu 14.04.4 LTS). Nginx, Puma, Capistrano3, PostgreSQL, RVM.
Capistrano::Rails::Db
cap production deploy:db:abort_if_pending_migrations # Run rake db:abort_if_pending_migrations
cap production deploy:db:create # Run rake db:create
cap production deploy:db:drop # Run rake db:drop
cap production deploy:db:migrate # Run rake db:migrate Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
cap production deploy:db:migrate:down # Run rake db:migrate:down Run the "down" for a given migration VERSION
cap production deploy:db:migrate:redo # Run rake db:migrate:redo Rollback the database one migration and re migrate up (options: STEP=x, VERSION=x)
cap production deploy:db:migrate:reset # Run rake db:migrate:reset Reset your database using your migrations
cap production deploy:db:migrate:status # Run rake db:migrate:status Display status of migrations
cap production deploy:db:migrate:up # Run rake db:mi
@warrenlalata
warrenlalata / rails http status codes
Created September 13, 2017 04:15 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@warrenlalata
warrenlalata / .env.sample
Last active June 3, 2019 09:14
Steps to configure Sequelize ORM to work with Node Backend
# Development
DEV_DB_USERNAME=root
DEV_DB_PASSWORD=yourdbpassword
DEV_DB_NAME=apollo_development
DEV_DB_HOSTNAME=localhost
# Test
TEST_DB_USERNAME=root
TEST_DB_PASSWORD=yourdbpassword
knex init
edit knexfile.js
in migration object, add directory property:
with 'db/migrations'
Open psql terminal
psql -U postgres -h localhost
Create database
create database dbname;
List databases
\l
Create user to work with db create
@warrenlalata
warrenlalata / index.js
Created February 6, 2020 03:57
Mask String with Thousand Separator
/**
* Masks Input with thousand separator
*
* @param {string} amount - Amount
* @return {string} Masked Amount
*
* @example
* formatAmount("1000") // 1,000
*/
export function formatAmount(amount) {
gem "devise_custom_authenticatable"
@warrenlalata
warrenlalata / App.js
Created July 19, 2020 12:40
KeyboardAvoidingView + React Navigation v5
import {
HeaderHeightContext
} from "@react-navigation/stack"; <
HeaderHeightContext.Consumer > {
headerHeight => ( <
KeyboardAvoidingView {
...(Platform.OS === "ios" ? {
behavior: "padding"
} : {})
}
@warrenlalata
warrenlalata / App.js
Created July 19, 2020 12:43
focus on next rn input
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
Platform,
Button,
ScrollView,
InputAccessoryView,
KeyboardAvoidingView,