Skip to content

Instantly share code, notes, and snippets.

View tapanhp's full-sized avatar
🎯
Focusing

Tapan Parmar tapanhp

🎯
Focusing
View GitHub Profile
@tapanhp
tapanhp / regex.md
Created October 27, 2020 11:28 — forked from vitorbritto/regex.md
Regex Cheat Sheet

Regular Expressions

Basic Syntax

  • /.../: Start and end regex delimiters
  • |: Alternation
  • (): Grouping
@tapanhp
tapanhp / CheckThingsAboutGPU.py
Last active March 17, 2020 05:55
To check how much RAM is allocated on google colab hosted runtime
import torch
print(torch.cuda.current_device()) #to check current device id
print(torch.cuda.device_count()) #to check number of devices
print(torch.cuda.get_device_name(0)) #to find device name
@tapanhp
tapanhp / logger_utils.py
Created February 12, 2020 09:32
Python Logging module utilities
import datetime
import logging
import os
import re
import constants
log_separator = "\n===================================================================================================="
@tapanhp
tapanhp / pandas_utils
Created June 10, 2019 11:36
Pandas utilities
import pandas as pd
from pandas import DataFrame
# Prints a single line, It's same as println() in other languages, by default print single empty line or "\n"
printline = lambda times=1 : print("\n" * times)
# function that counts NaN values for whole dataframe
__checkAllNaNs = lambda dataframe: dataframe.isnull().sum()
import re
def test_patterns(text, patterns):
"""Given source text and a list of patterns, look for
matches for each pattern within the text and print
them to stdout.
"""
# Look for each pattern in the text and print the results
for pattern, desc in patterns:
# not 6 + 5 **(3//2) - 5 > 5
# (6 * 3 > 5) and ((6//3) + 5 - 9 * 2 **3 < 56)
# ((6//3) + 5 - 9 * 2 **3 > 56) or 18 * 2 + 9//2 *(4-5) > 56