Skip to content

Instantly share code, notes, and snippets.

View GreatBahram's full-sized avatar
🚀
No STATUS!

Bahram Aghaei GreatBahram

🚀
No STATUS!
View GitHub Profile
@GreatBahram
GreatBahram / tmux.conf
Created June 24, 2017 06:46 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@GreatBahram
GreatBahram / person.py
Last active December 28, 2018 09:37
Dataclass introduction @ virgool
class Person:
def __init__(self, name, surname, age):
self.name = name
self.surname = surname
self.age = age
def __repr__(self):
return f'{self.__class__.__name__}: <{self.name} {self.surname}>'
def __eq__(self, other):
@GreatBahram
GreatBahram / emoji.py
Created January 18, 2019 11:10
Positive and negative emoji regex detection (Not unicode ones!)
import re
POSITIVE_EMOJI_RE = re.compile(r"[;:=]-?[\)|D]+")
NEGATIVE_EMOJI_RE = re.compile(r"[:=]-?[\(]+")
@GreatBahram
GreatBahram / redirect.py
Last active March 10, 2019 11:28
Redirect stdout to what ever you want: context manager and decorator implementation
import sys
from contextlib import contextmanager
from functools import wraps
def redirect_stdout_to(out_new):
"""Redirect stdout to out_new with context manager."""
out_old = sys.stdout
sys.stdout = out_new
yield
@GreatBahram
GreatBahram / spinner.py
Created May 28, 2019 17:59
simple spinner
import itertools
import sys
import threading
import time
class Signal:
stop = False
@GreatBahram
GreatBahram / execute.py
Created June 11, 2019 18:37
How to use subprocess methods in general.
from subprocess import STDOUT, CalledProcessError, check_output
class SomethingYouWant:
def __init__(self, working_dir):
self.working_dir= working_dir
def _build_cmd(self, cmd):
return cmd.split(' ')
@GreatBahram
GreatBahram / debian.sh
Created November 16, 2019 10:59
Get different information about program on debian os
# Get list of available packages on your operating system
dpkg --get-selections
# To check whether a package is installed or not:
get --get-selections {prg_name}
# Search for a filename comes from which package
dpkg -S `which ifconfig`
# List files installed to your system from package-name.
@GreatBahram
GreatBahram / context_managers.py
Created November 24, 2019 06:09
Useful context managers
def tmp_copy(source, destination):
import shutil
import os
shutil.copy(source, destination)
try:
yield
finally:
os.remove(destination)
@GreatBahram
GreatBahram / main.py
Created February 26, 2020 19:33
Get notified when sanjesh provide ets voucher
import requests
import bs4
import sys
URL_ROOT = "https://ets.sanjesh.org/Register.aspx"
SPECIFIC_TEXT = "موجودي ووچر به پايان رسيده است"
def get_data(url):
req = requests.get(url)
@GreatBahram
GreatBahram / decorators.py
Created March 31, 2020 11:52
Useful decorators
import os
from functools import wraps
def sudo_required(func):
"""Check sudo permission, if it hasn't, it'll exit non-zero."""
@wraps(func)
def wrapper(*args, **kwargs):
if os.getuid() != 0: