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 / cassandra_python_connection.py
Created September 4, 2019 08:28
python Cassandra connection by using python Cassandra driver and cqlengine.
__author__ = 'giasuddin'
from cassandra.cqlengine.connection import setup
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import dict_factory
from cassandra.cqlengine import connection
from cassandra.policies import RoundRobinPolicy
@giasuddin90
giasuddin90 / cassandra_python_raw_connection.py
Created September 4, 2019 08:30
Cassandra connection by using python driver, connect to Cassandra 2.1 with protocol version 3
def connect21(keyspace="test_keyspace"):
"""
Cassandra connection by using python driver
connect to cassandra 2.1 with protocol version 3
:param keyspace:
:return:
"""
auth_provider = PlainTextAuthProvider(username="cassandra", password="cassandra")
cluster = Cluster(["127.0.0.1"], auth_provider=auth_provider, protocol_version=4)
@giasuddin90
giasuddin90 / Cassandra_data_model_sync.py
Created September 4, 2019 08:33
Cassandra data modeling using python Cassandra driver
__author__ = 'giasuddin'
from cassandra.cqlengine import management
from cassandra.cqlengine.columns import *
from cassandra.cqlengine.models import Model
from datetime import datetime
import uuid
import cassandra
@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,
@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 / 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_cookie.py
Created October 30, 2019 10:43
python pyramid cookie setting method when htm file render
@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 / 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 / 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):