Skip to content

Instantly share code, notes, and snippets.

@amirasaran
amirasaran / eml_parser.py
Last active Mar 1, 2020
Simple Python EML Parser - extract Attachements, HTML, PlainText
View eml_parser.py
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 Jul 24, 2022
Django JET admin RTL (For persian and arabic ,...)
View rtl.css
@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 Jun 18, 2022
Python3 SMTP (smtpd) Mail Server with authentication sample + smtpd TLS support
View smtp_server.py
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 Jun 11, 2017 — forked from yprez/fields.py
Django rest framework - Base64 image field
View fields.py
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 Dec 13, 2016
simple soap client for python
View soap_client.py
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 Dec 4, 2016
php regex is_date_time function to validate date time
View is_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 Oct 27, 2016
Python threading with callback function (callback function run after thread is finished)
View BaseThreading
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 Sep 27, 2016
JavaScript Arabic character to Persian (تبدیل حروف عربی به فارسی)
View 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 Sep 27, 2016
Java Script replace all in string (str_replace)
View 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 Jul 15, 2022
convert Arabic character to Persian (Farsi) - PHP
View Arabic character to Persian (Farsi) - PHP
<?php
public static function arabicToPersian($string)
{
$characters = [
'ك' => 'ک',
'دِ' => 'د',
'بِ' => 'ب',
'زِ' => 'ز',
'ذِ' => 'ذ',
'شِ' => 'ش',