Skip to content

Instantly share code, notes, and snippets.

View GeekEast's full-sized avatar
🎧
Focusing

James Tan GeekEast

🎧
Focusing
View GitHub Profile
@GeekEast
GeekEast / rails_snippets.md
Created November 20, 2020 00:13
Rails: Knowledge Base

Rails

Rails Routes

# basic syntax
get 'home/index', to: 'home#index' # localhost:3000/home/index
get 'home/index' # localhost:3000/home/index

# set default controller for home page
root 'home#index'
root to: 'home#index'
@GeekEast
GeekEast / rails_association.md
Last active November 20, 2020 00:11
Rails: Associations

Database Operations

rails db # run sql
rails console # run rails

Associations

One to One

@GeekEast
GeekEast / rails_generators.md
Last active November 20, 2020 00:11
Rails: Generators All in One

Generator

no image found

rails generate [model|controller|resource|scaffold] [name]
rails destroy [model|controller|resource|scaffold] [name]

Model

rails g model hello
@GeekEast
GeekEast / install_rails_mac.md
Created November 19, 2020 23:51
Rails: Install on Mac

Install

  • Install rbenv
    • brew install rbenv
    • rbenv init
  • Install ruby
    • rbenv install 2.6.3
    • rbenv global 2.6.3
  • Install rails
    • export GEM_HOME="$HOME/.gem"
  • gem install rails -v 5.2.3
@GeekEast
GeekEast / model_validation.md
Last active April 1, 2021 05:48
Rails Model Validation

Model Validation

  • Validations are used to ensure that only valid data is saved into your database.

Types of Validation

  • Database constriants: database-dependent, testing and maintenance difficult
  • Client-side validation: unreliable, immediate feedback on the client-side
  • Controller-level validation: difficult to test and maintain, controller should be slim

Method Trigger Model Validation

  • create and create!
  • save and save!
@GeekEast
GeekEast / rails_routes.md
Last active November 19, 2020 01:26
Rails Routes

Root

# kitten's instance method
root to: "kitten#index"

Resources (with ID)

@GeekEast
GeekEast / rails_naming_convention.md
Created November 11, 2020 05:01
Rails: Naming Convention

Rails Naming Convention

General Ruby Convention

  • Class Name: CamelCase
  • Methods: snake_case
  • Variables: snake_case
  • method?: will return boolean anyway
  • method!: will throw exception if possible
  • class::method: class method
  • class#method: instance method
@GeekEast
GeekEast / moayan_scrapper.md
Last active November 20, 2020 00:17
Python: Crack Unicode-Number Mapping and Scarp MaoYan Moive Gross
import re,pymongo,time,os
import pandas as pd
import warnings; warnings.simplefilter('ignore')
from fontTools.ttLib import TTFont
from fontTools.unicode import unichr
from config import *
from pyquery import PyQuery as pq
from aip import AipOcr
from PIL import Image