Posts

Django Session Cleanup

django sessions hold some space in database these are data of non logged out users and there is no auto cleaning mechanism for these data, so you should be aware of that you need to clean up sessions from database periodically with python manage.py clearsessions command, it's better to set it up on crontab daily basis. you can find respective documentation below https://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-store

Raspberry PI USB mount as external drive

I chosed NTFS USB Drive as an external storage for my raspberry pi for this you need to install ntfs-3g library if it's not installed sudo apt install ntfs-3g to auto mount usb at boot stage you can add entry to fstab it's always to good to verify your entry before reboot sudo findmnt --verify --verbose run command to get info about your usb lsblk -fp and save UUID for to use in fstab and add following line to your fstab replace XXX with UUID that you saved earlier, and uid is user, and group id that directory will be mounted with ownership of this user and group that you can get from /etc/passwd UUID=XXX /mnt/FOLDERNAME ntfs defaults,auto,uid=1001,gid=1001,rw,nofail,umask=000 0 0

django tagging

django update string value with using existing value

it's possible to use F queries to make updates with using existing values in database, it's quite easy if value is number but when you want to do updates on string values things are getting complicated  a bit Here below I am replacing empty char coming after comma in location field such as London, UK We need to use django's special functions for this purpose F Value and Func from django.db.models import F, Func, Value Developer.objects.filter(location__contains=", ").update(location=Func(         F('location'),         Value(', '), Value(','),         function='replace',     )) Result will be London,UK which is our intended solution

Raspberry pi OTG cluster networking raspberry pi3 and raspberry pi zero

Let's assume you have two raspi zero and one raspi3, we want to connect pi zeros to reach internal networking with raspi3 as host and internet over raspi3. Add this to  /boot/cmdline.txt  after  rootwait pizero1 modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff: 01 g_ether.dev_addr=00:22:82:ff:ff: 11 quiet pizero2 modules-load=dwc2,g_ether g_ether.host_addr=00:22:82:ff:ff: 02 g_ether.dev_addr=00:22:82:ff:ff: 12 quiet Add this to  /boot/config.txt pizero1 and pizero2 dtoverlay=dwc2 gpu_mem=16 Add this to /etc/dhcpcd.conf  pizero1 interface usb0 static ip_address=192.168.7.2/24 static routers=192.168.7.1 static domain_name_servers=8.8.8.8 pizero2 interface usb0 static ip_address=192.168.7.2/24 static routers=192.168.7.1 static domain_name_servers=8.8.8.8 edit /etc/sysctl.conf make ip forward 1 and check if it's ok sudo sysctl -p /etc/sysctl.conf net.ipv4.ip_forward = 1 make sure ip forward is 1 an

[Solved] never ending lxml build raspberry pi 3, usb stick swap

Image
 if you have docker never ending lxml build for raspberry pi, you need to increase swap space. raspberry pi's default 100m is not enough for this. I had to make it with raspi overclock and usb stick 2gb swap space allocation, even with this setup 1gb memory and almost 350m swap usage it takes a lot of time to build lxml, be patient #result  Created wheel for websockets: filename=websockets-8.1-cp37-cp37m-linux_armv7l.whl size=78100 sha256=790eb0ccb81f08ae48e1d1930f2a2e8c2e2e846a01d7fe8bb1cb282cd8e5025f   Stored in directory: /root/.cache/pip/wheels/74/54/40/797b9f77057c12b05b85edbf63465cbe4c24f53d301de1432b   Building wheel for lxml (setup.py): started   Building wheel for lxml (setup.py): still running...   Building wheel for lxml (setup.py): still running...   Building wheel for lxml (setup.py): still running...   Building wheel for lxml (setup.py): still running...   Building wheel for lxml (setup.py): still running...   Building wheel for lxml (setup.py

How to train spamassassin to stop SPAM emails

train spam assasian with commands to learn from existing emails DOMAINPART will be your domain name LOCALPART will be your username  LOCALPART@ DOMAINPART root@ip-10-0-0-12:/var/log# sa-learn -p /home/USER/.spamassassin/user_prefs --ham /home/vmail/DOMAINPART/LOCALPART/.INBOX.Sent\ Messages/{cur,new} Learned tokens from 333 message(s) (333 message(s) examined) root@ip-10-0-0-12:/var/log# sa-learn -p /home/USER/.spamassassin/user_prefs --spam /home/vmail/DOMAINPART/LOCALPART/.Junk/{cur,new} Learned tokens from 1 message(s) (20 message(s) examined) root@ip-10-0-0-12:/var/log# sa-learn -p /home/USER/.spamassassin/user_prefs --spam /home/vmail/DOMAINPART/LOCALPART/.Trash/{cur,new} get and download new rules into spamassassin run following command from command line sa-update