Skip to content

Instantly share code, notes, and snippets.

@abhijitmamarde
abhijitmamarde / github gist.md
Last active March 27, 2024 18:38
Creating the gists using commandline

using github client - gh https://cli.github.com/manual/gh_gist

create

add --public for creating public gist; if not given, by default created - secret

$ gh gist create --public hello.py
@abhijitmamarde
abhijitmamarde / openai_key_validator.py
Created March 26, 2024 07:40
Verify if the given openai API key is valid or not.
import openai
import openai.types
def check_openai_api_key(api_key):
openai.api_key = api_key
try:
openai.models.list()
except openai.AuthenticationError as e:
return False
@abhijitmamarde
abhijitmamarde / req_script.js
Last active January 17, 2024 12:43
To send click event to a element on plain javascript
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
@abhijitmamarde
abhijitmamarde / draw_magic_grid.py
Created December 1, 2023 06:32
Draws and Traces the magic grid using Turtle, works only for odd length grid
import sys
import turtle
def generate_magic_square(n):
"""
This works only for odd grid size 3x3, 5x5, 11x11 etc., not for even
"""
magic_square = [[0] * n for _ in range(n)]
num = 1
@abhijitmamarde
abhijitmamarde / test_process_start.py
Created November 23, 2023 09:29
Running blocking servers / long running tasks before running a test
import time
from multiprocessing import Process
import pytest
def proc_a():
print("starting proc a")
i = 1
# for i in range(10):
alias via="vi ~/.bash_aliases"
alias reload=". ~/.bash_aliases"
alias c="clear"
alias cls="clear"
alias lk="ls -lrta"
alias pp="pwd"
echo "Aliases Set"
@abhijitmamarde
abhijitmamarde / get_log_lines.py
Created April 4, 2023 11:28
Get specific lines from log after a specific pattern
import re
import linecache
def find_line_with_pattern(log_file_name, pattern):
lines = open(log_file_name).readlines()
for i, line in enumerate(lines):
if re.match(pattern, line):
return i+1
@abhijitmamarde
abhijitmamarde / wordle_solver.py
Last active March 3, 2023 05:18
Script to help solve wordle game
words_list = [
'aahed',
'aalii',
'aargh',
'aarti',
'abaca',
'abaci',
'aback',
'abacs',
'abaft',
@abhijitmamarde
abhijitmamarde / gist:2af39b6e61c5c9fd31b773942d552662
Created December 21, 2022 05:30
Windows command line to check chrome browser version
# Update path as required
powershell -command "&{(Get-Item 'C:\Program Files\Google\Chrome\Application\chrome.exe').VersionInfo.ProductVersion}"
ex: O/P
108.0.5359.125
@abhijitmamarde
abhijitmamarde / rubik_scrambler_for_a_solution.py
Created October 5, 2022 09:52
Gets the scrambler steps for a Rubiks cube, for the given solution
"""
For the given Rubik's cube solution, generates the scramble
For getting solution:
https://ruwix.com/widget/3d/?label=Sample%20Solve&alg=F%20R%20F%20R%20U%20U%20L%20R%20L%20R%20U%27&flags=showalg&colors=WCA
for this specific solution
F R F R U U L R L R U'
the scramble step is: