Skip to content

Instantly share code, notes, and snippets.

View mthri's full-sized avatar
🦄

Amir Motahari mthri

🦄
View GitHub Profile
@mthri
mthri / script.sh
Created December 24, 2022 16:59
search some word in all files of a folder
ls | cut -d " " -f2 | xargs grep "SOME WORD"
@mthri
mthri / readme.md
Last active September 29, 2022 09:48
get http proxy form proxychain program

If you are using proxychain for chaing proxy then need to get it http proxy for some reason(i.e set it on Telegram) you need to run some proxy server with this program. In this example I will use proxy.py. this is a http proxy server writed with pure python.

after config proxychains use following code.

pip install proxy.py
proxychains proxy

by defualt run http proxy on host 127.0.0.1 and port 8899

@mthri
mthri / converter.py
Created February 5, 2022 07:12
convert arabic alphabet to persian in python
def arabic_to_persian(text: str) -> str:
# arabic: persian
characters = {
'ك': 'ک',
'دِ': 'د',
'بِ': 'ب',
'زِ': 'ز',
'ذِ': 'ذ',
'شِ': 'ش',
'سِ': 'س',
@mthri
mthri / tunneling.sh
Created December 15, 2021 08:52
Create an SSH Tunnel on Linux and Connect to MySQL
ssh -p 22 -N -L 3306:127.0.0.1:3306 [USER]@[SERVER-IP]
# -p -> ssh port
mysql -u [MYSQL-USER] -p -h 127.0.0.1
@mthri
mthri / mysql.sql
Created May 13, 2021 22:37
solved mysql docker tcp connection
CREATE USER 'root'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
@mthri
mthri / Remove Old Snap Versions.sh
Created May 4, 2021 20:53
Remove Old Snap Versions
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@mthri
mthri / check_required_input.js
Created March 7, 2021 12:12
check required input
function full_fill_check(target_element) {
let all_required_checked = true
$(target_element).find('input:required').each((index, element) => {
if (!$(element).val()) {
$(element).attr('placeholder', '*اجباری')
all_required_checked = false
}
})
if (!all_required_checked) {
Swal.fire(
@mthri
mthri / error_with_jq.js
Created March 7, 2021 12:09
show ajax response error with jq
/*
<div class="form-group col-md-6">
<label for="organization-name" class="float-right">جزئیات نام</label>
<input type="text" class="form-control" id="organization-name" name="organization_name" required>
<div><ul class="errorlist text-right"></ul></div>
</div>
*/
function show_error(form, errors){
for (const [key, value] of Object.entries(errors)) {
@mthri
mthri / mian.py
Created January 16, 2021 18:33
Proxy Some URL with Python
import requests
from flask import Flask
app = Flask(__name__)
TARGET_URL = ''
@app.route('/')
def index():
request = requests.get(TARGET_URL)
return request.text
@mthri
mthri / login_one_session.py
Created January 11, 2021 06:21
each user one session in django - also works on redis as cache engine
def login_one_session(request, user):
from importlib import import_module
from django.core.cache import cache
# Get Session Key and Prefix
from django.contrib.auth import SESSION_KEY
from django.contrib.sessions.backends.cache import KEY_PREFIX
# login authorized user
login(request, user)