Skip to content

Instantly share code, notes, and snippets.

View mthri's full-sized avatar
🦄

Amir Motahari mthri

🦄
View GitHub Profile
@mthri
mthri / main.py
Created October 26, 2020 12:20
PySerial Arduino
import serial
ser = serial.Serial('/dev/ttyACM0', baudrate=9600, timeout=1)
data = ser.readline()
data = str(data, encoding='utf-8')
data = data.strip()
ser.close()
ser.open()
@mthri
mthri / esptool-micropython.md
Last active November 13, 2020 17:42
Install MicroPython on NodeMCU(ESP8266) with esptool.py

esptool.py --port <PORT> --baud 460800 write_flash -e --flash_size=detect -fm dout 0 <FIRMWARE ADDRESS> NOTICE: after install, default baud rate is 115200

@mthri
mthri / githubusercontent.md
Created November 27, 2020 11:18
Direct Link on Github

Direct link to uploaded file on github repo https://raw.githubusercontent.com/{username}/{repo name}/{branche}/{directory + filename}

@mthri
mthri / boot.py
Created January 10, 2021 17:14
MicroPython AP and WiFi
import network
# wlan = network.WLAN(network.STA_IF)
# wlan.active(True)
# wlan.connect('mthri', '123456789')
# print('connecting...')
# while not wlan.isconnected():
# pass
# print('connected!')
@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)
@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 / 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 / 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 / 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 / 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;