This file contains hidden or 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
| def df_to_html_table(df): | |
| css = """ | |
| <style> | |
| table { | |
| border-collapse: collapse; | |
| width: 50%; | |
| margin: 20px auto; | |
| font-family: Arial, sans-serif; | |
| } | |
| th { |
This file contains hidden or 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
| const cronstrue = require("cronstrue"); // https://www.npmjs.com/package/cronstrue | |
| const cronparser = require("cron-parser"); // https://www.npmjs.com/package/cron-parser | |
| const timeDiff = require("js-time-diff"); // https://www.npmjs.com/package/js-time-diff | |
| let cronExpression = "5 * * * SUN"; | |
| let currentDate = new Date(); | |
| try { | |
| let nextDate = cronparser.parseExpression(cronExpression).next().toDate(); | |
| let cronMeaning = cronstrue.toString(cronExpression); |
This file contains hidden or 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
| def convert_bytes(num): | |
| for x in ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']: | |
| if num < 1024.0: | |
| return f"{num:.2f} {x}" | |
| num /= 1024.0 | |
| print(convert_bytes(1000_000_000_000)) |
This file contains hidden or 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 java.math.BigInteger; | |
| import java.security.MessageDigest; | |
| import java.security.NoSuchAlgorithmException; | |
| class Hash { | |
| public static void main(String[] args) throws NoSuchAlgorithmException { | |
| String message = "Hello World"; | |
| Hash hash = new Hash(); | |
| System.out.println("MD5: " + hash.getMD5(message)); | |
| System.out.println("SHA-1: " + hash.getSHA1(message)); |
This file contains hidden or 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 sqlite3 | |
| import os | |
| import json | |
| from cryptography import fernet | |
| class KeyValStore: | |
| """ | |
| KeyValStore is a simple key-value store that uses sqlite3 as a backend. | |
| It is not intended to be used as a production database, but rather as a |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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') |