Skip to content

Instantly share code, notes, and snippets.

View mthri's full-sized avatar
🦄

Amir Motahari mthri

🦄
View GitHub Profile
@mthri
mthri / SocketClient.ino
Last active June 16, 2024 02:40
esp8266 socket client and python socket server
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const uint16_t port = 8585;
const char *host = "SERVER-IP";
WiFiClient client;
void setup()
{
Serial.begin(115200);
@mthri
mthri / django-orm.md
Last active February 27, 2020 21:28
Django ORM

Making queries with Django ORM

Official tutorial

from django.db import models

class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()
@mthri
mthri / Model.md
Last active March 27, 2020 23:28
Extend User class in django

Extend User class in django

Notic :

If you have foreign key in new filds,must allow null(like below) or set default value else don't work

from django.db.models.signals import post_save
from django.dispatch import receiver

class Role(models.Model):
    RoleID = models.IntegerField(primary_key=True)
 name = models.CharField(max_length=10)
@mthri
mthri / vim.md
Created April 25, 2020 10:56
Vim Cheatsheet
@mthri
mthri / django-secure.md
Created June 24, 2020 17:48
A checklist to secure Django site

1- use rate limit to block brute force attack like this
2- use anti bot services like reCAPTCHA
3- config web server to disable directory browsing (like here)
4- scanning all file and check allowed type before upload to server(ClamAV).

@mthri
mthri / base-template.md
Created July 4, 2020 16:55
send data to base template in django

If you need to use data in base template the was sent to child template use block.super in some tag

{% block tmp %}
    {{ block.super }}
{% endblock %}

@mthri
mthri / code-pro.md
Last active January 27, 2021 22:08
Programming Hints

Use Comment

Use TODO keyword in comment

Obey Naming rule from each language

Use Changelog file

@mthri
mthri / command-line-hero.MD
Created October 1, 2020 20:32
Command Line Hero (Part Software)

Command Line Hero (Part Software)


echo

Display a line of text/string on standard output or a file.

Syntax

echo [Options] [Strings]

Options:

@mthri
mthri / self_restart.py
Created October 9, 2020 10:55
Self Restart Python Module
import os, sys
os.execl(sys.executable, sys.executable, * sys.argv)