How to push from Branch to Master in Git

How to push from a remote branch to master: https://stackoverflow.com/questions/5423517/how-do-i-push-a-local-git-branch-to-master-branch-in-the-remote

What to do if you know what you are doing or are experienced with Git:

$ git push <remote branch>:master

General format:

$ git push <remote> <local branch name>:<remote branch to push into>
For less experienced:
git checkout master
git pull               # to update the latest  master state
git merge develop      # to merge branch to master
git push origin master # push current HEAD to master

I did the second version, and was able to successfully push to master!

How to Add Line Numbers to Vim Permanently

Recently I’ve started working with a VM and I realized that debugging was a bit hard because I couldn’t see the line numbers for the code, so I searched up how you can see line numbers in vim, and found that when you are in a file with vim, press ESC, then enter the command:

:set number

The line numbers will show up. Yet, if you quit out of that session, and vi into the file again, you will see that the line numbers are gone. In order to set line numbers permanently in vim, you would need to go into your ~/.vimrc file and set properties for vim, but I noticed that in the VM I was on, there were no other directories or that file, so I created that file in my home directory by doing:

cd ~ 
vim .vimrc
set number
:wq

1st command: goes to home directory

2nd command: creates .vimrc file

3rd command: adds “set numbers” property into vimrc

4th command: saves and quits out of file

How to Query from MySQL Database in Python

Link: https://www.w3schools.com/python/python_mysql_select.asp

fetch-all()

import mysql.connector
mydb = mysql.connector.connect (
  host="localhost",
user="yourusername",
  password="yourpassword",
  database="mydatabase"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM customers")
myresult = mycursor.fetchall()
for x in myresult:
  print(x)
fetchone()
import mysql.connector
mydb = mysql.connector.connect (
  host="localhost",
user="yourusername",
  password="yourpassword",
  database="mydatabase"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM customers")
myresult = mycursor.fetchone()
for x in myresult:
  print(x)
I also did notice something quite peculiar when I printed out the data received from fetchone() or fetchall(). It seemed to be a tuple format, and when I tried to index for each element of the data or indexing for each element (such as data[0]), I received it in this format: (‘entry’,) which was difficult to parse. Therefore, I had to parse again just for the first element: data[0][0] to get the actual entry and data from the database I needed.
Note: This only works if you are searching for 1 column.

Python UUID

Generating UUID in Python: https://docs.python.org/3/library/uuid.html

>>> import uuid

>>> # make a UUID based on the host ID and current time
>>> uuid.uuid1()
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')

>>> # make a UUID using an MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')

>>> # make a random UUID
>>> uuid.uuid4()
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')

>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')

>>> # make a UUID from a string of hex digits (braces and hyphens ignored)
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')

>>> # convert a UUID to a string of hex digits in standard form
>>> str(x)
'00010203-0405-0607-0809-0a0b0c0d0e0f'

>>> # get the raw 16 bytes of the UUID
>>> x.bytes
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'

>>> # make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')

Installing Postgres on MacOS with Brew

This is what I followed to install postgres: https://gist.github.com/ibraheem4/ce5ccd3e4d7a65589ce84f2a3b7c23a3

Pre-Reqs

brew doctor
brew update

Installing

brew install postgres
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

Create aliases:

alias pg_start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"
  1. alias pg_stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"

This alias is only set for that terminal window, so to set this permanently, find your shell path by:

  1. echo $SHELL
    

Then you can append the alias to the computer shell file. For me, this was ~/.zshrc

Note: Make sure to echo the alias and use “>>” to append, not “>” which completely wipes the file with the text. This is what I did, and unfortunately, all the past things I added to my shell file were erased and it could not be undone.