This article quite frankly saved my life, I hope it helps you too: https://pynative.com/python-post-json-using-requests-library/
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>
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)
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
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"
-
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:
-
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.
Installing a Virtual Machine from VirtualBox
Link to download VirtualBox: https://www.virtualbox.org
After downloading, must download a Virtual Machine Image: https://www.osboxes.org/virtualbox-images/
Installing flask-mysqldb (Debug and Solution)
In this post, I will go through how I was able to install flask-mysqldb after going through lots of trial and error. I wanted to install flask-mysqldb to connect the Flask API to the MySQL database we were planning on using.
To install flask-mysqldb, the command to run is:
pip install flask_mysqldb
Yet, when I ran it, I kept receiving these errors:
jessicapeng@Jessicas-MacBook-Pro-2 ~ % pip install flask_mysqldb Collecting flask_mysqldb Using cached Flask-MySQLdb-0.2.0.tar.gz (2.1 kB) Collecting Flask>=0.10 Using cached Flask-1.1.2-py2.py3-none-any.whl (94 kB) Collecting mysqlclient Using cached mysqlclient-1.4.6.tar.gz (85 kB) ERROR: Command errored out with exit status 1: command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-pip-egg-info-0D9Xsz cwd: /private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/ Complete output (12 lines): sh: mysql_config: command not found sh: mariadb_config: command not found sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/__/j8b0d7wn7_796hd4c4x56f040000gn/T/pip-install-rCiijx/mysqlclient/setup.py", line 16, in <module> metadata, options = get_config() File "setup_posix.py", line 61, in get_config libs = mysql_config("libs") File "setup_posix.py", line 29, in mysql_config raise EnvironmentError("%s not found" % (_mysql_config_path,)) EnvironmentError: mysql_config not found ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
In the error, it indicated that mysql_config: command not found
so I found this thread referring to it in my search: https://stackoverflow.com/questions/7475223/mysql-config-not-found-when-installing-mysqldb-python-interface
In the thread, it mentions to use apt-get
but I had trouble running this command in terminal, and I learned that apt-get
is only for debian and ubuntu, whereas yum
is for centos/fedora/redhat distribution. I decided to use brew
which is a 3rd party community doing unix-like things on macOS.
When I attempted to install with brew using this command:
brew install mysql-client
I received these errors:
mysql-client is keg-only, which means it was not symlinked into /usr/local, because it conflicts with mysql (which contains client libraries).If you need to have mysql-client first in your PATH run: echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrcFor compilers to find mysql-client you may need to set: export LDFLAGS="-L/usr/local/opt/mysql-client/lib" export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
Which essentially tells me to put it into my .zshrc folder. That is done through this command:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
This briefly translates to:
“Please update my STARTUP config, and when I start a new terminal, in that terminal, update my PATH”
Note: Just editing .zhrc does not affect current window
Afterwards, a new terminal must be opened (my previous mistake with checking in the same terminal window and being confused that no path had been added) in order to check the path with:
echo $PATH
I was able to see the path added after:
(base) jessicapeng@Jessicas-MacBook-Pro ~ % echo $PATH /usr/local/opt/mysql-client/bin:/Users/jessicapeng/opt/anaconda3/bin:/Users/jessicapeng/opt/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
Afterwards, when I tried to install flask-mysqldb with the command:
pip install flask-mysqldb
It worked and installed flask-mysqldb successfully! Afterwards, I was able to run the flask program I had built!
This took me hours of stack overflow, so hopefully it’s helpful for those who have run into the same problem with installing flask-mysqldb!
Github SSH Key
Recently, I tried to clone a repository I was working on in GitHub that I had created, but I received the following error:
Permission denied (publickey). fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.
Apparently, I needed to create an SSH key and add it to Github SSH Keys in order to access the repository. To do this, I followed these instructions (on https://github.com/facebookresearch/deepmask/issues/23):
Generate SSH key using ssh-keygen -t rsa -b 4096 -C "[email protected]".
Copy the output of cat id_rsa.pub
Paste the above copied output into your Github profile -> Settings -> SSH and GPG Keys -> Add new SSH key
Regarding this, I created an SSH key, but couldn’t find it, so I ended up following the path: /Users/jessicapeng/.ssh/id_rsa.pub and I ran command cat .ssh/id_rsa.pub once I was in the directory jessicapeng in order to get it. Then, I followed the instructions and went to my Github Profile > Settings> SSH and GPG Key > Add SSH Key. And afterwards, I was able to successfully clone it and use git with it!