Skip to content

Instantly share code, notes, and snippets.

View salah93's full-sized avatar

salah ahmed salah93

View GitHub Profile
@salah93
salah93 / consumer.py
Last active June 12, 2021 19:47
kafka in docker
from confluent_kafka import Consumer
consumer = Consumer({'group.id': '1', 'bootstrap.servers': 'localhost:9092'})
consumer.subscribe(['abc'])
m = consumer.poll()
print(m.value())
@salah93
salah93 / get_index_differences_mongo.py
Last active May 26, 2021 14:33
get missing, extra indices between environments
import pymongo
from argparse import ArgumentParser
from typing import Any, Dict, List, Tuple
def get_create_string(
collection: str,
index_name: str,
key: List[Tuple[str, int]],
@salah93
salah93 / dogpile_cache_with_redis.py
Last active May 19, 2021 16:57
using dogpile-cache with Redis
import redis
from dogpile.cache import make_region
from dogpile.cache.util import function_key_generator
from time import sleep
from typing import Any
client = redis.StrictRedis()
region = (
@salah93
salah93 / kill-ssh-agent.fish
Last active February 18, 2021 14:57
starting ssh agent in fish shell
function kill-ssh-agent
killall ssh-agent
set -e SSH_AGENT_PID
set -e SSH_AUTH_SOCK
rm $SSH_ENV > /dev/null 2>&1
end
@salah93
salah93 / read-lock.sh
Created January 27, 2021 04:49
scripts with locking
#!/bin/bash
set -xeuo pipefail
(
flock -s -w 6 200
cat /tmp/x
echo read
sleep 5
) 200>/tmp/pidlock
@salah93
salah93 / create_shared_folder.sh
Created January 18, 2021 03:47
when you want to create a directory shared by multiple users
#!/bin/bash
set -xeuo pipefail
username=`whoami`
groupname=$1
shareddirectorypath=$2
# 1. create group
sudo groupadd $groupname || true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@salah93
salah93 / kubernetes.rst
Created May 9, 2020 19:51
kubernetes with minikube

Kubernetes

Installations

I am operating on a Fedora 31 OS with docker installed, I can run minikube on my machine directly (rather than in a vm) with docker by specifying minikube with --driver=docker.

I think this will be fine for development/exploration.

# notes from Łukasz Langa's video https://www.youtube.com/watch?v=-CzqsgaXUM8
import asyncio
import time
import httpx
from typing import *
addr = "https://langa.pl/crawl/"
@salah93
salah93 / requests_with_retries.py
Last active February 22, 2020 18:38
Adding urllib3's Retry class to requests
import requests
from argparse import ArgumentParser
from urllib3.util.retry import Retry
def main(args):
s = get_session()
response = s.get(args.url)
return response.status_code