Sunday, September 27, 2020

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

Tuesday, March 10, 2020

django tagging

Monday, March 9, 2020

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(
        Value(', '), Value(','),

Result will be


which is our intended solution

Wednesday, December 18, 2019

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
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
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

Add this to /etc/dhcpcd.conf 
interface usb0
static ip_address=
static routers=
static domain_name_servers=

interface usb0
static ip_address=
static routers=
static domain_name_servers=

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 and add this iptables entries based on your network conn eth0 or wlan0 if you are using wifi
sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward' 
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o

for raspi3
add this to /etc/dhcpcd.conf 
interface eth1
static ip_address=
static domain_name_servers= 

interface eth2
static ip_address=
static domain_name_servers=  

add this to /etc/udev/rules.d/90-pi-network.rules
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:01", NAME="eth1"
SUBSYSTEM=="net", ATTR{address}=="00:22:82:ff:ff:02", NAME="eth2"

now you can connect pizeros from raspi3 with and they can reach internet

now you can try pinging google from pizeros
ping google

Sunday, November 24, 2019

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

 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


 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 ( started
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( still running...
  Building wheel for lxml ( finished with status 'done'
  Created wheel for lxml: filename=lxml-4.4.1-cp37-cp37m-linux_armv7l.whl size=6273585 sha256=df03cf857c0cdcfa1f9833150387f5b8426320094472cf8565f9ef7c421276db
  Stored in directory: /root/.cache/pip/wheels/19/96/46/e4e538ebbe7496324a669bb244156a0b7d8796266d8bc1b6ce
  Building wheel for websockets ( started

  Building wheel for websockets ( finished with status 'done'

-- solution ---

#create 2gb partition on usb
fdisk /dev/sda1

# make filesystem
sudo mkfs.ext4 -L USBSWAP /dev/sda1

#mount usb to /mnt
root@raspberrypi3:/ cat /etc/fstab 
proc            /proc           proc    defaults          0       0
PARTUUID=610c3b14-01  /boot           vfat    defaults          0       2
PARTUUID=610c3b14-02  /               ext4    defaults,noatime  0       1
UUID=YOUR_USB_UUID /mnt ext4 defaults,noatime 0 1

#find your usb uuid

blkid -o export /dev/sda1 | grep ^UUID

# edit these values to make swap 2gb
sudo vi /etc/dphys-swapfile


#setup and enable swap
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

Thursday, September 12, 2019

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 


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


Monday, August 12, 2019

iCloud missing original date of videos and photos

I downloaded some videos from iCloud since it is not showing original date of videos in finder
so I try to find solution to reveal original dates of videos
I found exiftool which is working perfectly in mac
I am planning to write a small script to add this information to the filenames or replace visible date in finder with this create and modify date

coming soon...

Media Create Date : 2017:06:04 17:03:37
Media Modify Date : 2017:06:04 17:04:33

macbook-air:jhead-3.03 sertac$ exiftool /Users/sertac/Downloads/IMG_7267.MOV
ExifTool Version Number : 11.61
File Name : IMG_7267.MOV
Directory : /Users/sertac/Downloads
File Size : 103 MB
File Modification Date/Time : 2019:08:12 15:24:04+03:00
File Access Date/Time : 2019:08:12 15:44:00+03:00
File Inode Change Date/Time : 2019:08:12 15:24:17+03:00
File Permissions : rw-r--r--
File Type : MOV
File Type Extension : mov
MIME Type : video/quicktime
Major Brand : Apple QuickTime (.MOV/QT)
Minor Version : 0.0.0
Compatible Brands : qt
Movie Data Size : 108253575
Movie Data Offset : 36
Movie Header Version : 0
Create Date : 2017:06:04 17:03:37
Modify Date : 2017:06:04 17:04:33
Time Scale : 600
Duration : 0:00:56
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 5
Track Header Version : 0
Track Create Date : 2017:06:04 17:03:37
Track Modify Date : 2017:06:04 17:04:33
Track ID : 1
Track Duration : 0:00:56
Track Layer : 0
Track Volume : 100.00%
Image Width : 1920
Image Height : 1080
Clean Aperture Dimensions : 1920x1080
Production Aperture Dimensions : 1920x1080
Encoded Pixels Dimensions : 1920x1080
Graphics Mode : ditherCopy
Op Color : 32768 32768 32768
Compressor ID : avc1
Source Image Width : 1920
Source Image Height : 1080
X Resolution : 72
Y Resolution : 72
Compressor Name : H.264
Bit Depth : 24
Video Frame Rate : 30.001
Balance : 0
Audio Format : mp4a
Audio Bits Per Sample : 16
Audio Sample Rate : 44100
Layout Flags : Mono
Audio Channels : 1
Purchase File Format : mp4a
Warning : [minor] The ExtractEmbedded option may find more tags in the movie data
Matrix Structure : 1 0 0 0 1 0 0 0 1
Content Describes : Track 1
Media Header Version : 0
Media Create Date : 2017:06:04 17:03:37
Media Modify Date : 2017:06:04 17:04:33
Media Time Scale : 600
Media Duration : 0:00:56
Media Language Code : und
Gen Media Version : 0
Gen Flags : 0 0 0
Gen Graphics Mode : ditherCopy
Gen Op Color : 32768 32768 32768
Gen Balance : 0
Handler Class : Data Handler
Handler Vendor ID : Apple
Handler Description : Core Media Data Handler
Meta Format : mebx
Handler Type : Metadata Tags
Make : Apple
Model : iPhone 7 Plus
Software : 10.3.2
Creation Date : 2017:06:04 20:03:37+03:00
Image Size : 1920x1080
Megapixels : 2.1
Avg Bitrate : 15.5 Mbps
Rotation :