EC2 with no space for tmp file to start apache or mysql
It will come to the time that you won't be able to run any command that is required creating tmp file when you have no space on your EC2 instance. Once it happens, you can't even start/restart web server or mysql.
Run following 2 commands to check your disk status:
$ df -h
$ df -i
df -i . checks your inodes. what are...
MySQL sql_mode - Get and Set sql_mode Settings to solve
Check your current sql_mode
Edit your my.cnf and remove "ONLY_FULL_GROUP_BY". if you don't have sql_mode, just add sql_mode to .conf. Restart mysql server.
Update to latest stable version of node in an easy way
Check your current version
$ node -v
Install n with npm
$ sudo npm install -g n
Update your version with one of the following options
# install/update the stable node release
$ sudo n stable
#install/update the latest node release
$ sudo n latest
#install/update the latest LTS node release
$ sudo n lts
Check your version again
$ node -v
Setup Firebase FCM for push notification
1. create an account for Firebase FCM
2. create one app for ios and download GoogleService-Info.plist
3. create one app for android and download google-services.json
Follow this document to complete the setup: ttps://docs.expo.dev/guides/setup-native-firebase/
Data types in Python 3
Integers: Like in math, integers in computer programming are whole numbers that can be positive, negative, or 0 (…, -1, 0, 1, …). An integer can also be known as an int. As with other programming languages, you should not use commas in numbers of four digits or more, so when you write 1,000 in your program, write it...
How To Slice Strings in Python 3 by Index
Accessing Characters by Positive Index Number
print(ss) ==> y
Accessing Characters by Negative Index Number
print(ss[-3]) ==> r
print(ss[6:11]) => Shark
print(ss[:5]) ==> Sammy
print(ss[7:]) ==> hark!
print(ss[-4:-1]) ==> ark
Specifying Stride while Slicing Strings
print(ss[6:11]) ==> Shark
print(ss[6:11:1]) ==> Shark
print(ss[0:12:2]) ==> SmySak
print(ss[0:12:4]) ==> Sya
print(ss[::4]) ==> Sya
print(ss[::-1]) ==> !krahS ymmaS
print(ss[::-2]) ==> !rh ma
print(len(ss)) ==> 12
print(len("Let's print the length of this string.")) ==> 38
print(ss.count("a")) ==> 2
print(ss.count("s")) ==> 0
Simple Python Flask Rest API
Setup project folder:
$ mkdir flask-rest-api; cd flask-rest-api
$ python3 -m venv venv
$ source venv/bin/activate
Check your env, make sure it is the version that you should run on:
$ python -V; pip -V
Install flask and packages:
$ pip install flask flask-sqlalchemy marshmallow psycopg2-binary
Generate freeze requirement text file:
$ pip3 freeze > requirements.txt
Create your app.py file
$ touch app.py
Use any code editor to work on your project.
Run your Python Flask app with existing Apache server
If you already have an EC2 with Apache, you can use it to run your Python Flask app.
Install and Enable mod_wsgi:
$ sudo apt-get install libapache2-mod-wsgi-py3 python-dev
$ sudo a2enmod wsgi
Create a Flask app if you don't have one. See my other blog for create / run flask app.
Configure and Enable a New Virtual Host:
$ sudo nano /etc/apache2/sites-available/MyFlaskApp.conf
Add the following conf code...