Skip to content

Instantly share code, notes, and snippets.

View giasuddin90's full-sized avatar
🎯
Focusing

Gias Uddin giasuddin90

🎯
Focusing
View GitHub Profile
@giasuddin90
giasuddin90 / py_dict_merge.py
Created October 30, 2019 11:03
python script for merging dictionary
def dict_merge():
"""
merge two dictionary
:return:
"""
dict_a = {'a':1, 'b': 2}
dict_b = {'b':10, 'c': 11}
z = dict_a.copy()
@giasuddin90
giasuddin90 / python_image_resize.py
Created October 30, 2019 11:00
Python image file resize using pill library
__author__ = 'giasuddin'
from PIL import Image
import os, sys
size = (250, 500)
path = "/home/giasuddin/script/imgresize/all"
dirs = os.listdir(path)
directory = '/home/giasuddin/script/imgresize/dr'
# os.makedirs(directory)
@giasuddin90
giasuddin90 / python_file_sanitize.py
Created October 30, 2019 10:57
python sanitize string. is there any script, SQL tag in string
__author__ = 'giasuddin'
import html
data = {"description":"><img src=x onerror=prompt(1)>",
}
def sanitizeHtmlText(**kwargs):
"""
python sanitize string. is there any script, sql tag in string
@giasuddin90
giasuddin90 / python_file_download_save.py
Created October 30, 2019 10:54
using python file download from HTTP URL and save in desired directory
__author__ = 'giasuddin'
import requests
import os
f_url = "http://files.test.org.bd/crop/250/300/media/image/publication/wallpaper_poster_20180307.jpg"
STORAGE_DESTINATION = "/home/giasuddin/Pictures/"
def file_download(file_url):
@giasuddin90
giasuddin90 / python_pagination.py
Created October 30, 2019 10:48
python script for generating pagination by using total number of row.
__author__ = 'giasuddin'
def pager(total_row=None, item_per_page=None):
"""
We are using this function for pagination database total row.
Then using offset for query
"""
pages = {}
total_page = total_row/item_per_page
@giasuddin90
giasuddin90 / gist:8d85519735d395c0fcb9cc4e961baea4
Created October 30, 2019 10:46
python script for checking ASCII. Result will be provided in Boolean.
__author__ = 'giasuddin'
def is_ascii(s):
return all(ord(c) < 128 for c in s)
if __name__ == '__main__':
test=is_ascii('রিকোয়ারমেন্')
print(test)
@giasuddin90
giasuddin90 / pyramid_cookie.py
Created October 30, 2019 10:43
python pyramid cookie setting method when htm file render
@giasuddin90
giasuddin90 / pyramid_view_force_download
Created October 30, 2019 10:41
In python pyramid force download functionality.python file force download
__author__ = 'giasuddin'
from pyramid.response import Response, FileResponse
import os
from pyramid.view import view_config
@view_config(route_name='download', renderer='json')
def download_view(request):
if request.params.get('filename', ''):
filename = request.params['filename']
@giasuddin90
giasuddin90 / pyramid_view_file_download.py
Created October 30, 2019 10:39
using python pyramid framework and post method.By providing file type and file name we we download file.
__author__ = 'giasuddin'
from pyramid.view import view_config
import os
@view_config(request_method='POST', renderer='json')
def post(self):
file_type = self.request.matchdict['file_type']
node_type = self.request.matchdict['node_type']
sanitize_file = False
@giasuddin90
giasuddin90 / file_process.py
Created October 30, 2019 10:33
Using python script find different pattern file from a directory and replace file name as a way we want.
import re
import glob, os
def file_rename(dir, pattern, titlePattern):
for pathAndFilename in glob.iglob(os.path.join(dir, pattern)):
title, ext = os.path.splitext(os.path.basename(pathAndFilename))
replace_file = re.sub("[^a-zA-Z0-9_]+", "_", title)
new_filename = (replace_file + ext ).lower()
os.rename(pathAndFilename,