Skip to content

Instantly share code, notes, and snippets.

View mosi-kha's full-sized avatar

mostafa khaki mosi-kha

View GitHub Profile
dmmeteo /
Last active June 7, 2024 14:11
SOLID Principles explained in Python with examples.
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
class Animal:
def __init__(self, name: str):
Django ORM Optimization Tips
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
# ---------------------------------------------------------------------------
ba11b0y /
Last active August 31, 2023 19:21
Installing Postman on Ubuntu/Gnome

Since Chrome apps are now being deprecated. Download postman from

Although I highly recommend using a snap

sudo snap install postman

Installing Postman

tar -xzf Postman-linux-x64-5.3.2.tar.gz
obskyr /
Last active June 14, 2024 11:25
How to stream a requests response as a file-like object.
# -*- coding: utf-8 -*-
import requests
from io import BytesIO, SEEK_SET, SEEK_END
class ResponseStream(object):
def __init__(self, request_iterator):
self._bytes = BytesIO()
self._iterator = request_iterator
ipbastola /
Last active June 5, 2024 21:05
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64


Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
jameslyons /
Last active May 27, 2024 20:52
Caesar Cipher Python
# we need 2 helper mappings, from letters to ints and the inverse
key = 3
# encipher
ciphertext = ""
for c in plaintext.upper():
sloria /
Last active July 21, 2024 04:44
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General


  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
atul-bhouraskar /
Created November 29, 2012 03:13
Django function to populate a thumbnail image field from another image field
from PIL import Image as PILImage
import os
from django.core.files import File
from django.core.files.base import ContentFile
from cStringIO import StringIO
def create_thumbnail_from_image_field(image_field, thumbnail_image_field,
thumb_width, thumb_height):
This function is intended to be used with a model similar to