Skip to content

Instantly share code, notes, and snippets.

View Chiheb-Nexus's full-sized avatar

Chiheb Chiheb-Nexus

View GitHub Profile
@Chiheb-Nexus
Chiheb-Nexus / kombu_example.py
Last active May 20, 2021 01:08
Kombu & Celery example for workflow usage
# send a msg from another app to RQ
from kombu import Connection
from tasks import add
from time import sleep
queue_name = 'tasks'
while True:
try:
@Chiheb-Nexus
Chiheb-Nexus / coroutines_mutex.py
Last active May 3, 2020 14:59
Python coroutines with Mutex
#
# Example using coroutines within Mutex
#
import asyncio
MUTEX = asyncio.Lock()
@Chiheb-Nexus
Chiheb-Nexus / couroutines_thread_pool_executor.py
Created May 3, 2020 14:30
Python coroutines using ThreadPoolExecutor
#
# Example using coroutines within Threads and blocking task
#
import time
import asyncio
from concurrent.futures import ThreadPoolExecutor
def blocking_task(num):
@Chiheb-Nexus
Chiheb-Nexus / couroutines.py
Last active May 3, 2020 15:09
Python coroutines example
#
# Example using coroutines
#
import time
import asyncio
async def task(num):
# Wait 1s
@Chiheb-Nexus
Chiheb-Nexus / multiprocessing_pool.py
Created May 2, 2020 19:04
Multiprocessing using Pool
#
# Multiprocessing using Pool
#
import time
from multiprocessing import Pool, cpu_count
def task(arg):
return arg ** 2
@Chiheb-Nexus
Chiheb-Nexus / multiprocessing_mutex.py
Created May 2, 2020 19:02
Multiprocessing with Mutex
#
# MultiProcessing using Mutex example
#
import time
from multiprocessing import Process, Lock, Array, Value
def task(index, result):
result[index.value] = index.value ** 2
@Chiheb-Nexus
Chiheb-Nexus / threading_mutex.py
Created May 2, 2020 18:58
Multithreading with/without Mutex
#
# Threading with/without mutex
#
import time
import threading
MUTEX = threading.Lock()
@Chiheb-Nexus
Chiheb-Nexus / find_and_merge_class_members.py
Created June 29, 2017 22:22
Find an merge class members in Python
class A:
dependencies = ["x", "y"]
@classmethod
def get_dep(cls):
dep = []
for k in cls.__mro__[:-1]:
dep += k.__dict__.get('dependencies', [])
return dep
@Chiheb-Nexus
Chiheb-Nexus / Project_Euler_problem34.py
Last active May 15, 2017 03:16
Solution to ProjectEuler.net : Problem 34
# Project Euler: Problem 34
# 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
#
# Find the sum of all numbers which are equal to the sum of the factorial of their digits.
#
# Note: as 1! = 1 and 2! = 2 are not sums they are not included.
################################
# Solution: 40730
# Best time: 9.244094610214233
@Chiheb-Nexus
Chiheb-Nexus / Python3 Virtualenv Setup
Created May 10, 2017 22:54 — forked from evansneath/Python3 Virtualenv Setup
Setting up and using Python3 Virtualenv
To install virtualenv via pip
$ pip3 install virtualenv
Note that virtualenv installs to the python3 directory. For me it's:
$ /usr/local/share/python3/virtualenv
Create a virtualenvs directory to store all virtual environments
$ mkdir somewhere/virtualenvs
Make a new virtual environment with no packages