Skip to content

Instantly share code, notes, and snippets.

@Abdurahman-hassan
Abdurahman-hassan / .gitignore
Last active February 17, 2024 22:06
This Python script calculates and sorts the total participation time of each attendee in a Zoom meeting from a CSV export. It groups data by participant names, sums up their durations, and lists them in descending order of attendance time. Ideal for analyzing meeting engagement, it requires Python 3.x and pandas, with an optional PyArrow install…
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/**
* infinite_while - Infinite loop
*
* Return: Always 0
*/
int infinite_while(void)
# Encapsulation
def encapsulated_function(some_value):
class HiddenClass:
def __init__(self, value):
self.value = value
def display_value(self):
print(self.value)
# # Decorators
#
# # func1(func) -> inner() -> logic -> return func1
#
# def decor(func):
#
# def inner():
# print("Decorated function")
# func() # ordinary has been executed
#
@Abdurahman-hassan
Abdurahman-hassan / django_stream_queryset_to_csv.md
Created November 14, 2022 00:50 — forked from niuware/django_stream_queryset_to_csv.md
How to stream a CSV file from a large QuerySet using Django's StreamingHttpResponse

Stream a CSV file from a QuerySet using StreamingHttpResponse

This is a sample on how to stream the results of a large QuerySet into a CSV file using Django StreamingHttpResponse class.

  1. Add the CSVStream class in your project, for example a writers.py file:
import csv
from django.http import StreamingHttpResponse
# List comprehension
# The syntax for list comprehension is:
# [ <expression> for x in <sequence> if <condition>]
data = [2,3,5,7,11,13,17,19,23,29,31]
# Ex1: List comprehension: updating the same list
data = [x+3 for x in data]
print("Updating the list: ", data)
# Updating the list output: [5, 6, 8, 10, 14, 16, 20, 22, 26, 32, 34]
@Abdurahman-hassan
Abdurahman-hassan / views.py
Last active July 13, 2022 01:17
queryset in django, one context that contains a different cases of searches in view file
from django.shortcuts import render
from .models import Product
# Create your views here.
# pricee = {"price1": "50", "product1": "car"}
class SearchIn:
@Abdurahman-hassan
Abdurahman-hassan / slicing.py
Created June 28, 2022 05:10
a slicing description in Python with a simple examples
# a list from 0 to 6
piano_keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
print(piano_keys[1:5])
# will print from position 1 to the position 5
# ['b', 'c', 'd', 'e']
print(piano_keys[1:5:2])
# will print from position 1 to the position 5
# it will skip the first one after position 1 and print the second one only one time
@Abdurahman-hassan
Abdurahman-hassan / orderFunction.py
Created June 19, 2022 20:57
simple uses of order functions , that we set a param in a function and then we use this param as a new function that takes the same param of the original function
def add(n1, n2):
return n1 + n2
def multiply(n1, n2):
return n1 * n2
def calc(n1, n2, newFun):
return newFun(n1, n2)