Skip to content

Instantly share code, notes, and snippets.

View tjaved573's full-sized avatar

Taimoor Javed tjaved573

View GitHub Profile
@tjaved573
tjaved573 / ruby_or-equals_operator.md
Last active July 1, 2022 19:08
Ruby or-equals operator

||=

a || = b

is a conditional operator. Assign b to a if a is uninitialized.

@tjaved573
tjaved573 / hotkeys.md
Created June 23, 2022 16:40
Keyboard shortcuts

Keyboard shortcuts ———————————————

Show suggestion - ctrl + space

Shifting between terminal and window: Terminal ctrl ` , Window ctrl 1

Open keyboard shortcuts : cmd K + cmd S

@tjaved573
tjaved573 / ruby-yield.rb
Last active May 12, 2022 18:58
Ruby-Yield Statement
# Ruby Yield Statement
# Yield statement is used for a method that takes in a block and needs to invoke the code block.
# In this e.g, name() method takes in a block defined in line #10.
# In the method definition, wherever 'yield' keyword comes up, the code block is rendered.
def name
puts "A yield will be called with id of 12"
yield 12
@tjaved573
tjaved573 / pip3-commands.md
Last active May 12, 2022 08:10
pip3 commands

to list all installed packages installed

pip3 list

to create a virtual environment

virtualenv test_env_1

to specify a version as well, run:

virtualenv -p /usr/local/bin py_env_3.8

to active a virtual environment, use

source test_env_1/bin/activate

@tjaved573
tjaved573 / argument_passing_to_methods.rb
Last active April 26, 2022 19:28
Ruby Method Arguments
# with this syntax, the order of parameters does not matter
# have to use same name for parameters when passing arguments
#! required and optional arguments are ordered
#! order of passing parameters
#! required => optional => variable => keyword
#! keyword arguments => for more clarity, and removing the need for arguments to be ordered
def method_1(m1:, m2:, m3:)
@tjaved573
tjaved573 / splat_operator.rb
Last active September 8, 2022 19:59
splat_operator.rb
# single splat operator converts all arguments into an array.
# double splat operator converts all arguments into a hash
# order of arguments:
#// required -> optional -> variable -> keyword (use hash syntax)
def dubSplat (*c, **d)
p c
p d
end
@tjaved573
tjaved573 / rails_associations_guide.rb
Last active September 8, 2022 20:17
Rails Association Guide
#// RAILS ASSOCIATIONS
class Author
has_one :book
# indicates that one other model has a reference to this model.
# Rails assumes that Books.author_id is a foreign key to Author.id in this table.
end
class Book < AR
belongs_to :author