Skip to content

Instantly share code, notes, and snippets.

View harshildarji's full-sized avatar

Harshil harshildarji

View GitHub Profile
@harshildarji
harshildarji / docx_to_conll.py
Created November 7, 2023 12:52
Python script to extract comments from .docx file, and convert into CoNLL format.
import json
import os
import string
import zipfile
from lxml import etree
from nltk.tokenize import RegexpTokenizer
from tqdm import tqdm
import docx
import csv
from datetime import datetime
import speedtest
def measure_speed():
st = speedtest.Speedtest(secure=True)
st.get_best_server() # This will select the best server based on ping
@harshildarji
harshildarji / shadows_of_the_knight.py
Last active April 15, 2022 17:32
Shadows of the Knight
# https://www.codingame.com/ide/puzzle/shadows-of-the-knight-episode-1
import sys
import math
w, h = [int(i) for i in input().split()]
n = int(input())
x0, y0 = [int(i) for i in input().split()]
L, R, T, B = 0, w-1, 0, h-1
@harshildarji
harshildarji / compare_dfs_difference.py
Created March 27, 2022 14:44
Compare DFs, and store differences in separate one
import pandas as pd
df1 = pd.read_csv('raw.csv', sep='|')
df2 = pd.read_csv('clean_OLD.csv', sep='|')
not_clean = list(set(df1['id']) - set(df2['id']))
print(f'Raw DF: {df1.shape}\nClean DF: {df2.shape}\nNot clean: {len(not_clean)}')
data = df1[df1['id'].isin(not_clean)].reset_index(drop=True)
print(f'Not clean DF: {data.shape}')
@harshildarji
harshildarji / ner.py
Created March 4, 2022 12:27
Generate NER predictions
import os
import pickle
import warnings
from functools import reduce
from operator import add
import numpy as np
import pandas as pd
import torch
from tqdm import tqdm
@harshildarji
harshildarji / reber.py
Created May 24, 2021 09:17
Generate true Reber grammar sequences.
# This Python script can be used to generate true Reber grammar sequences.
# To generate false Reber grammar sequences, just change tuple values in 'traversal' at line 8.
import numpy as np
chars = 'BTSXPVE'
traversal = [[('T', 'P'), (1, 4)], [('S', 'X'), (1, 2)], [('S', 'X'), (3, 4)], [('E'), (-1,)], [('V', 'T'), (5, 4)], [('V', 'P'), (3, 2)]]
def generate_seq(min_length):
@harshildarji
harshildarji / color_mastermind.py
Created May 21, 2021 09:28
Color Mastermind Game in Python
def solution(secret, guess):
while secret != guess:
correct_position_guessed = [0] * len(secret)
correct_color_guessed = [color for color in secret if color in guess]
for i in range(len(secret)):
if secret[i] == guess[i]:
correct_position_guessed[i] = 1
print('Correct colors guessed: {}'.format(' '.join(color for color in correct_color_guessed)))
# Video link: https://youtu.be/3P3TcKaegbA?list=PLxvWWIq3F0k0GE1EYvricLniNSdv9gvZS
import os
import time
from datetime import datetime
from github import Github
from curtsies.fmtfuncs import yellow
ACCESS_TOKEN = open('token', 'r').read()
g = Github(ACCESS_TOKEN)
@harshildarji
harshildarji / word_chain.py
Created October 24, 2020 05:04
Word Chain Game
import random, json, requests, string, sys
def game():
chain = 0
usedWords = []
answer_Word = None
chainGood = True
min_length = 3
while chainGood:
# if chain != 0 and chain % 5 == 0: min_length += 1
@harshildarji
harshildarji / generate_random_number.py
Created April 20, 2020 11:38
Generate Random Number
import random, time
def generate_random_number():
number = list(map(str, str(time.time()).replace('.', '')))
return int(''.join(random.sample(number, len(number))))
print(generate_random_number())