Albara's blog

This blog for random codes that I use for solving minor problems or do some small tasks, most likely with no categories! I think it's easy for me to come here when I need to reuse something instead of rewriting it over and over again!



Copying file to multiple folders

Using shell script, I copy the following file /var/www/html/index.php to all the folders in the current directory:
for dir in *; do [ -d "$dir" ] && cp -f /var/www/html/index.php "$dir" ; done

Zipping folder in Linux

har is the target folder, har.zip is the zipped file:
zip -r har.zip har

Copying file to multiple folders

Using shell script, I copy the following file /var/www/html/index.php to all the folders in the current directory:
for dir in *; do [ -d "$dir" ] && cp -f /var/www/html/index.php "$dir" ; done

Changing the EC2 size

follow the direction here: url: ref (click here)
then use SSH to check the size
df -h
lsblk

Changing the EC2 type

AWS changing the type :ref (click here)
AWS pricing :ref (click here)
AWS types (CPU and RAM) : ref (click here)
then use SSH to check the size

SSH to AWS EC2

ssh -i aaa.pem ec2-user@1.2.3.4

Changing the owner of the file to apache on EC2 AWS

With this command, Apache server (PHP files) will be able to do changes in the files/directories in the server
sudo chown -R apache:apache ./file.json 
With this command, FileZilla (FTP app) will be able to do changes in the files/directories in the server
sudo chown -R ec2-user:apache ./file.json 

Set Different Volume Levels For Each App on Mac pro

Here is an app url: click here

Download and run Tensorflow on EC2 AWS

With these commands, you'll be able to install tensorflow in a virtual environment and run it:
#---------------------------------------------
#Create a virtual environment:
#---------------------------------------------
python3 -m venv --system-site-packages ./venv
source ./venv/bin/activate  # sh, bash, or zsh
pip install --upgrade pip
#---------------------------------------------
#Install TensorFlow
#---------------------------------------------
pip install --upgrade tensorflow
deactivate
#---------------------------------------------
#run python file out of the venv
#---------------------------------------------
./venv/bin/python file.py 

Get MAC address of rasperrypi for both eth and wlan

With these commands, you'll be able to get the MAC address of eth0 and wlan0 and print them in whatever text format you wish:
IFACE_E=eth0
read MAC_E </sys/class/net/$IFACE_E/address
IFACE_W=wlan0
read MAC_W </sys/class/net/$IFACE_W/address
MACX=${IFACE_E}${MAC_E}${IFACE_W}${MAC_W}
MACX2=$(echo $MACX | sed 's/[:"]//g')
echo $MACX2

Camera does not work on macbook-Pro

Run the following command
sudo killall VDCAssistant

Raspberry Pi SD Card to img on Mac on macbook-Pro

Find the disk number
diskutil list
run the command with the disk number (for example here is the disk2):
sudo dd if=/dev/rdisk2 of=aaa.img bs=1m 

PHP: To read the csv file without having to deal with new line issue

Here is the code, the csv file will be save in array: $csv
$filename="aaa.csv";
$file = fopen($filename,"r");
while(! feof($file))
  {
  $csv[]=fgetcsv($file);
  }
fclose($file);

Apahce: Increase the HTTP request size (GET).

First, open the file:
sudo vim /etc/httpd/conf/httpd.conf 
Add the limitationm line (by bytes)
LimitRequestLine 100000000
LimitRequestFieldSize 100000000
Then restart the server
sudo service httpd restart

PHP: Increase the HTTP request size (POST).

First, open the file:
sudo vim /etc/php.ini
Add the limitation size, or put 0 if you dont want to have any limitation.
post_max_size = 0