Skip to content

Instantly share code, notes, and snippets.

@amirasaran
amirasaran / eml_parser.py
Last active April 21, 2024 09:01
Simple Python EML Parser - extract Attachements, HTML, PlainText
import re
from email import parser, message
from email.header import decode_header
class EmlParser(object):
def __init__(self, email: bytes):
self.parsed = parser.BytesParser().parsebytes(email)
def file_name_extractor(self, text):
@amirasaran
amirasaran / rtl.css
Last active July 24, 2022 13:34
Django JET admin RTL (For persian and arabic ,...)
@import url("../fonts/css/fontiran.css");
html {
direction: rtl;
font-family: IRANSans;
}
.sidebar {
right: 0 !important;
left: auto !important;
@amirasaran
amirasaran / smtp_server.py
Last active March 20, 2024 12:00
Python3 SMTP (smtpd) Mail Server with authentication sample + smtpd TLS support
import asynchat
import base64
import ssl
import asyncore
from smtpd import SMTPServer as BaseSMTPServer, SMTPChannel as BaseSMTPChannel, DEBUGSTREAM
def decode_b64(data):
"""Wrapper for b64decode, without having to struggle with bytestrings."""
@amirasaran
amirasaran / fields.py
Last active June 11, 2017 10:46 — forked from yprez/fields.py
Django rest framework - Base64 image field
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def to_internal_value(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@amirasaran
amirasaran / soap_client.py
Created December 13, 2016 07:09
simple soap client for python
from zeep import helpers, Client
import types
class SoapConnector(object):
def __init__(self, base_url):
self._client = Client(base_url)
def send(self, method, data):
connector = getattr(self._client.service, method)
@amirasaran
amirasaran / is_date_time
Created December 4, 2016 15:13
php regex is_date_time function to validate date time
function is_date_time($value){
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])[T|\s]{1}([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/",$value))
{
return true;
}else{
return false;
}
}
@amirasaran
amirasaran / BaseThreading
Created October 27, 2016 06:36
Python threading with callback function (callback function run after thread is finished)
import time
import threading
class BaseThread(threading.Thread):
def __init__(self, callback=None, callback_args=None, *args, **kwargs):
target = kwargs.pop('target')
super(BaseThread, self).__init__(target=self.target_with_callback, *args, **kwargs)
self.callback = callback
self.method = target
@amirasaran
amirasaran / JavaScript Arabic character to Persian
Created September 27, 2016 06:23
JavaScript Arabic character to Persian (تبدیل حروف عربی به فارسی)
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
String.prototype.toPersianCharacter = function () {
var string = this;
var obj = {
'ك' :'ک',
'دِ': 'د',
@amirasaran
amirasaran / Java Script replace all in string (str_replace)
Created September 27, 2016 06:09
Java Script replace all in string (str_replace)
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
/**
* Example
*/
@amirasaran
amirasaran / Arabic character to Persian (Farsi) - PHP
Last active May 26, 2024 01:35
convert Arabic character to Persian (Farsi) - PHP
<?php
public static function arabicToPersian($string)
{
$characters = [
'ك' => 'ک',
'دِ' => 'د',
'بِ' => 'ب',
'زِ' => 'ز',
'ذِ' => 'ذ',
'شِ' => 'ش',