|
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!
kill -9 $(lsof -t -i :3000)
history -c && history -w
console=serial0,115200 console=tty1 root=PARTUUID=d6b6a7aa-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-console init=/bin/shReboot then use the following commands
mount -o remount, rw / passwd pi sync exec /sbin/initRef
sudo yum install -y nmapUsing a Debian (Ubuntu/Raspbian):
sudo apt-get install -y nmapUsing the MAC Address To Identify a Pi
sudo nmap -sP 192.168.0.0/24
username: pi password: raspberryTo start SSH service
sudo service ssh startTo check the status of SSH service
sudo service ssh status
for dir in *; do [ -d "$dir" ] && cp -f /var/www/html/index.php "$dir" ; done
zip -r har.zip har
for dir in *; do [ -d "$dir" ] && cp -f /var/www/html/index.php "$dir" ; done
df -h lsblk
ssh -i aaa.pem ec2-user@1.2.3.4
sudo chown -R apache:apache ./file.jsonWith 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
#--------------------------------------------- #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
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
sudo killall VDCAssistant
cat /proc/device-tree/model
diskutil listrun the command with the disk number (for example here is the disk2):
sudo dd if=/dev/rdisk2 of=aaa.img bs=1m
diskutil listUnmount the disk:
diskutil unmountDisk /dev/disk2run the command with the disk number (for example here is the disk2):
sudo dd bs=1m if=aaa.img of=/dev/rdisk2Eject the disk. To safely remove the SD card:
diskutil eject /dev/rdisk2
$filename="aaa.csv"; $file = fopen($filename,"r"); while(! feof($file)) { $csv[]=fgetcsv($file); } fclose($file);
sudo vim /etc/httpd/conf/httpd.confAdd the limitationm line (by bytes)
LimitRequestBody 10000000000 LimitRequestLine 10000000000 LimitRequestFieldSize 10000000000Then restart the server
sudo service httpd restart
sudo vim /etc/php.iniAdd the limitation size, or put 0 if you dont want to have any limitation.
post_max_size = 0
$arrContextOptions=array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false,),);Then you could call the file_get_contents
$output = file_get_contents('http://website.com', false, stream_context_create($arrContextOptions));
$arrContextOptions=array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false,),);Then you could call the file_get_contents
$output = file_get_contents('http://website.com', false, stream_context_create($arrContextOptions));
#!/bin/bashThen give the following permsion te the sh file:
sudo chmod +x aaa.shex. if aaa.sh was your sh file you want to run then the format will be:
sudo nohup sh aaa.sh >/dev/null 2>&1 &
sudo du -h --max-depth=1 /home/
while true ; do sudo pkill -f tee ; done
import numpy as np np.array([])
sudo swapoff -aThe swap file is 4 GB (128 MB x 32):
sudo dd if=/dev/zero of=/swapfile bs=128M count=32Update the read and write permissions
sudo chmod 600 /swapfileSet up the swap area:
sudo mkswap /swapfileMake the swap file available
sudo swapon /swapfileVerify
sudo swapon -sStart the swap file at boot
sudo vi /etc/fstabAdd the following line at the end
/swapfile swap swap defaults 0 0
nohup sh ./cut-all.sh &
sudo du -sh ./folderA
python3 -m venv ./venvActivate:
source ./venv/bin/activate
import requests def is_there(path): r = requests.head(path) return r.status_code == requests.codes.ok
import numpy as np def mode(a): u, c = np.unique(a, return_counts=True) return u[c.argmax()] ##### g=pd.DataFrame(df[['A','B']].groupby(['A']).apply(mode) ) g.columns=["B"] XMODE=g['B'].mean()Ref: click here
plt.fill_between(df.index, df['A'],df['B'], interpolate=True, color='grey', alpha=0.5)Ref: click here
rsync -r dir1/ dir2
B=A[A['user'].str.contains("1234")]If we want the once that doesn't contain 1234
B=A[~A['user'].str.contains("1234")]
Ctrl+ATo go the end
Ctrl+E
sudo vim /etc/httpd/conf/httpd.confAdd the following commandL
Then restart the apache serverRewriteEngine On RewriteBase / RewriteCond %{HTTP_COOKIE} !user=admin [NC] RewriteRule ^ https://example.net/error.php [NC,L]
sudo /etc/init.d/httpd restart
import io import requests path="https://example.com/a.csv" s=requests.get(path).content cont=io.StringIO(s.decode('utf-8')) dfx=pd.read_csv(cont,header=None)
sudo vim /etc/crontab
sudo yum update sudo yum install python3 python3-venv libaugeas0 sudo python3 -m venv /opt/certbot/ sudo /opt/certbot/bin/pip install --upgrade pip sudo /opt/certbot/bin/pip install certbot certbot-apache sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbotCertbot edit the apache configuration automatically:
sudo certbot --apacheOr, just get a certificate:
sudo certbot certonly --apacheAuto renew:
echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
chmod 400 ttest.pem(2) Then we will need to use the following info:
Username: ec2-user(3) From the command line make the SSH connection
Public DNS: *.*.amazonaws.com [or you could use the IP instead]
Key: test.pem
ssh -i ttest.pem ec2-user@*.*.amazonaws.com
sudo yum update –y #sudo yum update(1) download the PHP package
#sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd(2) Start the HTTP service
sudo service httpd start #sudo chkconfig httpd on #chkconfig --list httpd(3) Go the folder of www (online)
cd /var/www/(4) give permission to add/delete and edit for the ec2-user
sudo chown -R ec2-user:apache /var/www
sudo service mysqld start(2) Run mysql_secure_installation.
sudo mysql_secure_installation(3) Setup password for example
username: root(4) In case you want to stop MySql
Password: 123456
sudo service mysqld stop(5) Auto run when setup server
sudo chkconfig mysqld on
sudo yum install php70-mbstring.x86_64 php70-zip.x86_64 -y sudo service httpd restart cd /var/www/html wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1 rm phpMyAdmin-latest-all-languages.tar.gz sudo service mysqld startTo access mysql:
mysql -u root -p
sudo cd /usr/local/bin sudo mkdir ffmpeg2 sudo cd ffmpeg2 sudo wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz # https://johnvansickle.com/ffmpeg/ sudo tar xvf ffmpeg-git-amd64-static.tar.xz sudo mv ffmpeg-git-20220722-amd64-static/ ./ffmpeg sudo cd .. sudo rm -r ffmpeg2 sudo cd ffmpeg ./ffmpeg -version sudo ln -s /usr/local/bin/ffmpeg/ffmpeg /usr/bin/ffmpegThen you could just use the following command from anywhere: Auto renew:
sudo ffmpeg -i vvv.mov vvv.mp4Ref: 1 and 2
sudo rm -r /var/log/httpd/
xrandr --output HDMI-1 --mode 1920x1080
nano ~/.profile # to find HDMI-1 or other run: xrandr # then run the command with the resution you want: cvt 1920 1080 60 sudo xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync sudo xrandr --addmode HDMI-1 "1920x1080_60.00" sudo xrandr --output HDMI-1 --rotate rightRef1 Ref2 Ref3
xrandr --output HDMI-1 --auto --rotate rightOff
xrandr --output HDMI-1 --offRef
sudo nano /boot/config.txt display_lcd_rotate=2Rotate touch
# create sh file (e.g screen.sh) and put the command in it xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1Open autostart and run the file from it
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart sudo screen.shHere is the rest angels:
Rotate left 90 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1 Rotate 180 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1 Rotate right 90 = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1 Return to upright = xinput set-prop 'raspberrypi-ts' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1Ref1 Ref2
sudo vim /etc/httpd/conf/httpd.confPut the following, and change example.com to your domain
Then restart apacheSetHandler server-status Require host example.net AllowOverride None # Allow open access: Require all granted
sudo service httpd restart
sudo nano /boot/conifg.txtUncomment the followig line
hdmi_safe=1Then restart the device
reboot
find . -name "*.csv"Ref: click here
find . -name "*.csv" -type f -deleteRef: click here
sudo nano /etc/php.iniupdate the max_input_time:
max_input_time = 3600Second update the httpd
sudo nano /etc/httpd/conf/httpd.confAdd this the following line right after the "Listen 80" :
Timeout 3600
sudo systemctl restart httpd
ps aux | grep ".py"
sudo pkill -9 -f "/example/venv/bin/python3"