Monday, April 27, 2026

virtual environment on python on Ubuntu

 # 1. Update system and install Python tools

sudo apt update && sudo apt install python3-pip python3-venv -y


# 2. Setup Django in a Virtual Environment

mkdir ~/my_project && cd ~/my_project

python3 -m venv venv

source venv/bin/activate


# 3. Install Latest Django

pip install django

django-admin --version


# 4. Verify Ollama is still active

systemctl status ollama --no-pager

# run the server 
python manage.py runserver 0.0.0.0:8000

# on windows 
Then, open http://localhost:8000 on Windows to see the Django rocket!
Example:


root@kayyum-VirtualBox:~/osh# sudo apt install python3-pip python3-venv -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-pip is already the newest version (22.0.2+dfsg-1ubuntu0.7).
The following additional packages will be installed:
  python3-pip-whl python3-setuptools-whl python3.10-venv
The following NEW packages will be installed:
  python3-pip-whl python3-setuptools-whl python3-venv python3.10-venv
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,479 kB of archives.
After this operation, 2,897 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-pip-whl all 22.0.2+dfsg-1ubuntu0.7 [1,683 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-setuptools-whl all 59.6.0-1.2ubuntu0.22.04.3 [789 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3.10-venv amd64 3.10.12-1~22.04.15 [5,714 B]
Get:4 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-venv amd64 3.10.6-1~22.04.1 [1,042 B]
Fetched 2,479 kB in 4s (707 kB/s)
Selecting previously unselected package python3-pip-whl.
(Reading database ... 216450 files and directories currently installed.)
Preparing to unpack .../python3-pip-whl_22.0.2+dfsg-1ubuntu0.7_all.deb ...
Unpacking python3-pip-whl (22.0.2+dfsg-1ubuntu0.7) ...
Selecting previously unselected package python3-setuptools-whl.
Preparing to unpack .../python3-setuptools-whl_59.6.0-1.2ubuntu0.22.04.3_all.deb ...
Unpacking python3-setuptools-whl (59.6.0-1.2ubuntu0.22.04.3) ...
Selecting previously unselected package python3.10-venv.
Preparing to unpack .../python3.10-venv_3.10.12-1~22.04.15_amd64.deb ...
Unpacking python3.10-venv (3.10.12-1~22.04.15) ...
Selecting previously unselected package python3-venv.
Preparing to unpack .../python3-venv_3.10.6-1~22.04.1_amd64.deb ...
Unpacking python3-venv (3.10.6-1~22.04.1) ...
Setting up python3-setuptools-whl (59.6.0-1.2ubuntu0.22.04.3) ...
Setting up python3-pip-whl (22.0.2+dfsg-1ubuntu0.7) ...
Setting up python3.10-venv (3.10.12-1~22.04.15) ...
Setting up python3-venv (3.10.6-1~22.04.1) ...
root@kayyum-VirtualBox:~/osh# mkdir ~/my_django_project && cd ~/my_django_project
python3 -m venv env

root@kayyum-VirtualBox:~/my_django_project#
root@kayyum-VirtualBox:~/my_django_project#
root@kayyum-VirtualBox:~/my_django_project# python3 -m venv env
root@kayyum-VirtualBox:~/my_django_project# ls
env
root@kayyum-VirtualBox:~/my_django_project# source env/bin/activate
pip install django
Collecting django
  Downloading django-5.2.13-py3-none-any.whl (8.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.3/8.3 MB 3.5 MB/s eta 0:00:00
Collecting asgiref>=3.8.1
  Downloading asgiref-3.11.1-py3-none-any.whl (24 kB)
Collecting sqlparse>=0.3.1
  Downloading sqlparse-0.5.5-py3-none-any.whl (46 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.1/46.1 KB 611.9 kB/s eta 0:00:00
Collecting typing_extensions>=4
  Downloading typing_extensions-4.15.0-py3-none-any.whl (44 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.6/44.6 KB 649.0 kB/s eta 0:00:00
Installing collected packages: typing_extensions, sqlparse, asgiref, django
Successfully installed asgiref-3.11.1 django-5.2.13 sqlparse-0.5.5 typing_extensions-4.15.0
(env) root@kayyum-VirtualBox:~/my_django_project#
(env) root@kayyum-VirtualBox:~/my_django_project#
(env) root@kayyum-VirtualBox:~/my_django_project#
(env) root@kayyum-VirtualBox:~/my_django_project# ls
env
(env) root@kayyum-VirtualBox:~/my_django_project#
(env) root@kayyum-VirtualBox:~/my_django_project# ls
env
(env) root@kayyum-VirtualBox:~/my_django_project# rpm -qa | grep django
(env) root@kayyum-VirtualBox:~/my_django_project# pip install djangorestframework django-cors-headers
Collecting djangorestframework
  Downloading djangorestframework-3.17.1-py3-none-any.whl (898 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 898.8/898.8 KB 3.2 MB/s eta 0:00:00
Collecting django-cors-headers
  Downloading django_cors_headers-4.9.0-py3-none-any.whl (12 kB)
Requirement already satisfied: django>=4.2 in ./env/lib/python3.10/site-packages (from djangorestframework) (5.2.13)
Requirement already satisfied: asgiref>=3.6 in ./env/lib/python3.10/site-packages (from django-cors-headers) (3.11.1)
Requirement already satisfied: typing_extensions>=4 in ./env/lib/python3.10/site-packages (from asgiref>=3.6->django-cors-headers) (4.15.0)
Requirement already satisfied: sqlparse>=0.3.1 in ./env/lib/python3.10/site-packages (from django>=4.2->djangorestframework) (0.5.5)
Installing collected packages: djangorestframework, django-cors-headers
Successfully installed django-cors-headers-4.9.0 djangorestframework-3.17.1
(env) root@kayyum-VirtualBox:~/my_django_project# pip install djangorestframework django-cors-headers^C
(env) root@kayyum-VirtualBox:~/my_django_project#

Monday, October 13, 2025

Github repo

GITHUB INITIALIZATION OR NEW GITHUB push 

 # ✅ Step 1: Check if Git is installed

git --version


# ✅ Step 2: Configure your Git identity

git config --global user.name "Your Name"

git config --global user.email "youremail@example.com"


# ✅ Step 3: Go to your project directory

cd path/to/your/project


# ✅ Step 4: Initialize git

git init


# ✅ Step 5: Create .gitignore file (optional but recommended)

echo "*.pyc

__pycache__/

.env

venv/

*.sqlite3

" > .gitignore


# ✅ Step 6: Add all files to staging

git add .


# ✅ Step 7: Commit your code

git commit -m "Initial commit"


# ✅ Step 8: Connect to your GitHub repository (replace the URL)

git remote add origin https://github.com/yourusername/your-repo.git


# ✅ Step 9: Rename main branch and push

git branch -M main

git push -u origin main


# ✅ Step 10: Verify connection

git remote -v

----------------------------------------------------------------------------------------
--------------------- Github push failing reason and resolution ---------------
# ๐Ÿงฉ Check Git installation
git --version

# ๐Ÿงฐ Set up Git identity
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

# ๐Ÿ“‚ Move into your project directory
cd path/to/your/project

# ๐Ÿ—️ Initialize Git if not already done
git init

# ๐Ÿงพ Create .gitignore (optional but recommended)
echo "*.pyc
__pycache__/
.env
venv/
*.sqlite3
" > .gitignore

# ➕ Add all files to staging
git add .

# ๐Ÿ’ฌ Commit your code
git commit -m "Initial commit"

# ๐Ÿ”— Set or reset remote repository (replace with your actual repo URL)
git remote remove origin 2> /dev/null
git remote add origin https://github.com/yourusername/your-repo.git

# ๐ŸŒฟ Rename branch to main
git branch -M main

# ๐Ÿงช Verify remote
git remote -v

# ๐Ÿš€ Try pushing your code
git push -u origin main

# ๐Ÿงฑ If push fails due to authentication, generate a Personal Access Token:
#    1. Visit https://github.com/settings/tokens
#    2. Generate new token (classic) with "repo" and "workflow" permissions
#    3. Use your GitHub username, and the token as your password when prompted

# ๐Ÿ’พ Save credentials so Git remembers them
git config --global credential.helper store

# ๐Ÿ› ️ If the repo already has commits (like a README), pull first:
git pull origin main --rebase
git push -u origin main

# ๐Ÿงน If you still face branch mismatch issues
git branch -M main
git push -u origin main

# ๐Ÿ”’ If switching to SSH (optional)
# git remote set-url origin git@github.com:yourusername/your-repo.git
-----------------------------------------------------------------------------------------
********* SSH SETUp *************************************
# ๐Ÿงฉ Check if SSH is installed
ssh -V

# ✅ Generate a new SSH key (replace with your GitHub email)
ssh-keygen -t ed25519 -C "youremail@example.com"

# When asked for a file path, just press Enter to accept default
# When asked for a passphrase, you can press Enter (optional)

# ✅ Start the SSH agent
eval "$(ssh-agent -s)"

# ✅ Add your private SSH key to the agent
ssh-add ~/.ssh/id_ed25519

# ✅ Show your public key (copy this output)
cat ~/.ssh/id_ed25519.pub

# ๐Ÿ”— Go to https://github.com/settings/keys
# → Click "New SSH key"
# → Give it a title (e.g., MyLaptop)
# → Paste the copied key
# → Click "Add SSH key"

# ✅ Test SSH connection
ssh -T git@github.com

# ✅ If success: you'll see "Hi username! You've successfully authenticated..."

# ๐Ÿงฐ Now connect your local project with SSH
cd path/to/your/project

# Initialize git if not done already
git init

# Add .gitignore (optional)
echo "*.pyc
__pycache__/
.env
venv/
*.sqlite3
" > .gitignore

# Stage and commit files
git add .
git commit -m "Initial commit"

# ✅ Link your GitHub repo using SSH (replace username/repo)
git remote remove origin 2> /dev/null
git remote add origin git@github.com:yourusername/your-repo.git

# ✅ Push to GitHub
git branch -M main
git push -u origin main

# ✅ Verify remote connection
git remote -v
------------------------------------------------------------------------------
kayyum@DESKTOP-QM3A3JG MINGW64 ~
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=Kayyum Shaikh
user.email=kayyum****@gmail.com
-------------------------------------------------------------------------------

Thursday, August 21, 2025

Python Errors and Meaning

Pro Tips to Spot Errors Quickly

  • ValueError → "The value you gave is wrong" ✅ → Right type, wrong data

  • IndexError → "The position you're trying to reach doesn’t exist" ❌

  • TypeError → "You're mixing incompatible types" ⚡

  • NameError → "That variable doesn’t exist" ๐Ÿ”

  • SyntaxError → "Python can’t even read this code" ๐Ÿ›‘


-------------------------------------------------------------------------------------------------------------------

Error Type
---------------
Meaning
--------------------
Cause
-------------------------
Example
------------------------
How to Spot / Fix
-----------------------
SyntaxError Invalid code structure Python cannot parse your code print "Hello" Check for missing colons, parentheses, quotes
IndentationError Wrong indentation level Misaligned spaces/tabs if True:\nprint("Hi") Always use consistent indentation (4 spaces)
NameError Variable not defined Using a variable before declaring it print(x) Define the variable before use
TypeError Incompatible types Performing invalid operations between data types "5" + 5 Convert types explicitly: int("5") + 5
ValueError Invalid value for the operation Correct type but unacceptable value int("abc") Ensure input values are valid
IndexError Index out of range Accessing an invalid list/tuple index [1,2,3][5] Check list length before accessing
KeyError Missing dictionary key Accessing a non-existent key {"a":1}["b"] Use .get() or check with in
ZeroDivisionError Division by zero Dividing a number by zero 10/0 Check denominator before division
AttributeError Invalid attribute access Using a method or property that doesn't exist "abc".push() Use dir(obj) to see valid attributes
ImportError Module not found Importing a non-existent or misplaced module import mymodule (not present) Check module name and path
ModuleNotFoundError Subclass of ImportError Specific case when the module cannot be located import unknownlib Install or correct module
RuntimeError Error that occurs at runtime General unexpected errors Rare and contextual Check traceback for details
AssertionError Failed assert statement When the assertion condition is false assert 2+2==5 Validate assumptions
OverflowError Number too large for calculation Exceeding numeric limits math.exp(1000) Use decimal or fractions module
MemoryError Not enough memory Processing huge datasets Creating a massive list Optimize memory usage
EOFError Input ends unexpectedly Calling input() but no data provided input() without data Ensure valid user input
OSError System-related errors Issues like missing files, permissions, etc. open("nofile.txt") Check file paths and permissions
--------------------------------------------------------------------------------------------------------------------

Thursday, July 3, 2025

singly linked list advanced

 class Node:
  def __init__(self,data):
    self.data = data 
    self.next = None 
class sl:
  def __init__(self):
    self.head = None 
  
  def is_empty(self):
    return self.head is None 
  
  def insert(self,value):
    new_node = Node(value)
    if self.is_empty():
      self.head = new_node
    else:
      new_node.next = self.head 
      self.head = new_node
  
  def insert_at(self,value,new_value):
    new_node = Node(new_value)
    current = self.head 
    while current:
      if current.data == value:
        new_node.next = current.next 
        current.next = new_node
      current = current.next 
    print()
  
  def show(self):
    current = self.head 
    while current:
      print(current.data,'->',end='')
      current = current.next 
    print()
  
  def delete(self,value):
    current = self.head 
    
    if current.data == value:
      self.head.data = None 
      self.head = self.head.next
    while current:
      if current.data == value and current.next != None:
        current.data = current.next.data 
        current.next = current.next.next 
      current = current.next 
    l.show()
    print()
    
l = sl()
for i in range(1,10):
  l.insert(i)
  
l.show()
l.delete(9)
l.delete(1)
l.delete(8)
l.delete(7)
l.delete(6)
l.delete(3)
l.delete(2)

Output:

9 ->8 ->7 ->6 ->5 ->4 ->3 ->2 ->1 ->
8 ->7 ->6 ->5 ->4 ->3 ->2 ->1 ->

8 ->7 ->6 ->5 ->4 ->3 ->2 ->1 ->

7 ->6 ->5 ->4 ->3 ->2 ->1 ->

6 ->5 ->4 ->3 ->2 ->1 ->

5 ->4 ->3 ->2 ->1 ->

5 ->4 ->2 ->1 ->

5 ->4 ->1 ->

Saturday, December 28, 2024

Circular Linked List Python



# python circular linked list
class Node:
  def __init__(self,data):
    self.data = data
    self.next = None

class cl:
  def __init__(self):
    self.head = None
 
  def is_empty(self):
    return self.head is None
 
  def insert(self,value):
    new_node = Node(value)
    if self.is_empty():
      self.head = new_node
      new_node.next = self.head
    else:
      current = self.head
      while current.next != self.head :
        current = current.next
      current.next = new_node
      new_node.next = self.head
      self.head = new_node
 
  def display(self):
    current = self.head
    while current.next != self.head :
      print(current.data,'<->',end='')
      current = current.next
    print()
   
  def delete(self,value):
    current = self.head
    while current.next != self.head:
      if current.data == value:
        current.data = None
        current.data = current.next.data
        current.next = current.next.next
      current = current.next
    print("deleted.")
    self.display()
   
  def update(self,value,alternate):
    current = self.head
    while current.next != self.head:
      if current.data == value:
        current.data = alternate
      current = current.next
    print("updated.")
    self.display()
 
  def size(self):
    current = self.head
    size=0
    while current.next != self.head:
      size+=1
      current = current.next
    print(f"size of circular linked list: \n{size}")

   
l = cl()
for i in range(10):
  l.insert(i)

l.display()
l.delete(5)
l.insert(55)
l.display()
l.delete(1)
l.update(6,66)
l.size()

-----------------------------------------------------
output:
-----------------------------------------------------
9 <->8 <->7 <->6 <->5 <->4 <->3 <->2 <->1 <-> deleted. 9 <->8 <->7 <->6 <->4 <->3 <->2 <->1 <-> 55 <->9 <->8 <->7 <->6 <->4 <->3 <->2 <->1 <-> deleted. 55 <->9 <->8 <->7 <->6 <->4 <->3 <->2 <-> updated. 55 <->9 <->8 <->7 <->66 <->4 <->3 <->2 <-> size of circular linked list: 8
------------------------------------------------------

Friday, October 25, 2024

Doubly Linked List Python

 


# singly linked list

class Node:
  def __init__(self,data):
    self.data = data
    self.prev = None
    self.next = None

class dl:
  def __init__(self):
    self.head = None
    self.tail = None
 
  def is_empty(self):
    return self.head is None
 
  def insertb(self,value):
    new_node = Node(value)
    if self.is_empty():
      self.head = self.tail = new_node
    else:
      new_node.next = self.head
      self.head.prev = new_node
      self.head = new_node
 
  def inserte(self,value):
    new_node = Node(value)
    if self.is_empty():
      self.head = self.tail = new_node
    else:
      new_node.prev = self.tail
      self.tail.next = new_node
      self.tail = new_node
 
  def forward(self):
    current = self.head
    while current:
      if current.data != None:
        print(current.data,'<->',end='')
      current = current.next
    print()

  def backward(self):
    current = self.tail
    while current:
      if current.data != None:
        print(current.data,'<->',end='')
      current = current.prev
    print()

  def delete(self,value):
    current = self.head
    while current:
      if current.data != None and current.data == value:
        current.data = None
      current = current.next
    print("deleted...")
    self.forward()
    self.backward()
    self.size()
 
  def update(self,value,replace):
    current = self.head
    while current:
      if current.data != None and current.data == value:
        current.data = replace
      current = current.next
    print("updated...")
    self.forward()
    self.backward()
   
  def size(self):
    current = self.head
    size=0
    while current:
      if current.data != None :
        size += 1
      current = current.next
    print(f"size is {size}...!")
 
l = dl()
l.insertb(1)
l.insertb(2)
l.insertb(3)
l.inserte(4)
l.inserte(5)
l.delete(1)
l.update(2,22)

Singly linked list python

 


# singly linked list

class Node:
  def __init__(self,data):
    self.data = data
    self.next = None

class ll:
  def __init__(self):
    self.head = None
 
  def is_empty(self):
    return self.head is None
 
  def insert(self,value):
    new_node = Node(value)
    if self.is_empty():
      self.head = new_node
    else:
      new_node.next = self.head
      self.head = new_node
 
  def show(self):
    current = self.head
    while current:
      if current.data != None:
        print(current.data,'->',end='')
      current = current.next
    print()
 
  def delete(self,value):
    current = self.head
    while current:
      if current.data != None and current.data == value:
        current.data = None
      current = current.next
    print("deleted...")
    self.show()
    self.size()

# if you wish to delete the node and don't want none
    def delete(self,value):
        current = self.head
        while current:
            if current.data == value:
                previous.next = current.next  # Skip over the node to delete it
                current = None  # Optional: free the node
                print(f"Node with value {value} deleted.")
                self.display()
                return
            previous = current
            current = current.next
 
  def update(self,value,replace):
    current = self.head
    while current:
      if current.data != None and current.data == value:
        current.data = replace
      current = current.next
    print("updated...")
    self.show()
   
  def size(self):
    current = self.head
    size=0
    while current:
      if current.data != None :
        size += 1
      current = current.next
    print(f"size is {size}...!")
 
l = ll()
l.insert(1)
l.insert(2)
l.insert(3)
l.insert(4)
l.insert(5)

l.show()

virtual environment on python on Ubuntu

 # 1. Update system and install Python tools sudo apt update && sudo apt install python3-pip python3-venv -y # 2. Setup Django in a ...