Skip to content

Instantly share code, notes, and snippets.

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

James Dela Cruz delacruzjames

🏠
Working from home
View GitHub Profile
@delacruzjames
delacruzjames / app.DockerFile
Created April 19, 2023 09:44 — forked from satendra02/app.DockerFile
docker+rails+puma+nginx+postgres (Production ready)
FROM ruby:2.3.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www/app_name
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran:
@delacruzjames
delacruzjames / change_primary_key.md
Created March 16, 2022 06:35 — forked from scaryguy/change_primary_key.md
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@delacruzjames
delacruzjames / migrate.py
Created March 15, 2022 07:29 — forked from jmuhlich/migrate.py
Alembic migration to rename primary and foreign key constraints along with a table rename
from alembic import op
from alembic.operations.ops import CreatePrimaryKeyOp, CreateForeignKeyOp
import sqlalchemy as sa
def upgrade():
conn = op.get_bind()
ctx = op.get_context()
existing_metadata = sa.schema.MetaData()
target_metadata = ctx.opts['target_metadata']
React File Structure
@delacruzjames
delacruzjames / index.md
Created June 13, 2020 15:26 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@delacruzjames
delacruzjames / NERDTree.mkd
Created March 22, 2020 03:44 — forked from m3nd3s/NERDTree.mkd
My Vim Cheat Sheet

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|

O.......Recursively open the selected directory..................|NERDTree-O|

Deploying a basic Ruby on Rails app with Postgres Database to Microsoft Azure

This was written on 8 November, 2019. Some of the issues mentioned below were discovered and resolved with the help of Microsoft support staff, and will hopefully be fixed in the near future.

Overview

The steps below are mostly taken from this tutorial, Deploying your Rails + PostgreSQL app on Microsoft Azure, but have also been influenced by these two other tutorials: Create a Ruby on Rails App in App Service on Linux and Build a Ruby and Postgres app in Azure App Service on Linux.

The descriptions of each step are my own personal understanding. I'm not an Azure expert, so they may not be correct 100% of the time.

Rails Version Note: The versions u

@delacruzjames
delacruzjames / gist:885c53650d487b8dc6b5f49be3497296
Created June 11, 2019 01:08
Installing mysql2 0.3.20 version
brew tap frnhr/homebrew-mariadb-connector-c-2
brew install frnhr/mariadb-connector-c-2/mariadb-connector-c
env ARCHFLAGS="-arch x86_64" gem install mysql2 -v '0.3.20' -- --with-mysql-config=/usr/local/Cellar/mariadb-connector-c/2.2.2/bin/mariadb_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
function maxDepth() {
var maxDep = 0,
d,
parents,
myselector = 'ul, ol';
$(myselector).each( function(i) {
parents = $(this).parents(myselector);
d = parents ? parents.length + 1 : 1;
maxDep = d > maxDep ? d : maxDep;
@delacruzjames
delacruzjames / Simple Form.md
Created February 24, 2018 07:24 — forked from stevenyap/Simple Form.md
Simple Form Cheatsheet

Gemfile

gem 'simple_form'

Installation

rails generate simple_form:install