This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cx_Oracle | |
# Connect to the database | |
connection = cx_Oracle.connect("user", "password", "host:port/service_name") | |
# Create a cursor | |
cursor = connection.cursor() | |
try: | |
# Execute a statement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docker | |
# connect to docker client | |
client = docker.from_env() | |
# execute command to get env_list variables | |
output = client.containers.run(image="ikunalchhabra/airflow-datascience:latest", | |
command="printenv", | |
remove=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
string = "Kunal Chhabra" | |
search_char = "a" | |
counter = Counter(string.lower()) | |
print(counter) | |
# output -> Counter({'a': 3, 'h': 2, 'k': 1, 'u': 1, 'n': 1, 'l': 1, ' ': 1, 'c': 1, 'b': 1, 'r': 1}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author : Kunal Chhabra | |
from collections import Counter | |
# text source : https://www.gutenberg.org/files/11/11-h/11-h.htm | |
data = ''' | |
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversations?” | |
So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. | |
There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, “Oh dear! Oh dear! I shall be late!” (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
import logging | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.INFO) | |
logging.basicConfig( | |
format='%(asctime)s %(levelname)-8s %(message)s', | |
level=logging.INFO, | |
datefmt='%Y-%m-%d %H:%M:%S') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from colorama import Fore, Back, Style | |
import logging | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.DEBUG) | |
logging.basicConfig( | |
format='%(asctime)s %(levelname)-8s %(message)s', | |
level=logging.INFO, | |
datefmt='%Y-%m-%d %H:%M:%S') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
import pandas as pd | |
class Mongo: | |
def __init__(self, db_name, host, port): | |
self.__db_name = db_name | |
self.__host = host | |
self.__port = port | |
self.__client = pymongo.MongoClient(self.__host, self.__port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from confluent_kafka import Consumer, Producer, KafkaError, KafkaException | |
from confluent_kafka.schema_registry.avro import AvroSerializer, AvroDeserializer | |
from confluent_kafka.serialization import StringSerializer, SerializationContext, MessageField | |
from confluent_kafka.schema_registry import SchemaRegistryClient | |
class Kafka: | |
def __init__(self, bootstrap_server, topic, timeout=60.0): | |
self.__bootstrap_server = bootstrap_server | |
self.__topic = topic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import json | |
def get_hash(data, hash_type='md5', sort=True): | |
if not data: | |
raise ValueError('Data cannot be empty') | |
if hash_type not in hashlib.algorithms_available: | |
raise ValueError(f"Invalid hash type: {hash_type}\nAvailable hash types: {hashlib.algorithms_available}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import country_list # pip install country_list | |
import phonenumbers # pip install phonenumbers | |
import pycountry # pip install pycountry | |
import langdetect # pip install langdetect | |
import whois # pip install python-whois | |
import re | |
import datetime | |
langdetect.DetectorFactory.seed = 0 |
OlderNewer