Skip to content

Instantly share code, notes, and snippets.

View napsternxg's full-sized avatar
🎯
Focusing

Shubhanshu Mishra napsternxg

🎯
Focusing
View GitHub Profile
@napsternxg
napsternxg / Timer Fix.md
Created December 18, 2025 11:43
shorthandians.in Fix

Key Issues:

  • Double Decrementing (--timer): This is likely why your timer "stops early" or moves too fast. You are calling --timer twice inside the same setInterval loop: once when checking for the "warning" class and again when checking for the "expired" state. This means for every 1 second of real time, the code removes 2 seconds from the counter.

  • Overlapping Intervals: If startCountdown is called more than once (e.g., a user clicks a button twice), multiple intervals will run simultaneously. This causes the timer to flicker or count down at warp speed because each interval is fighting to update the same display element.

  • Scope and Garbage Collection: The interval variable is defined locally within the function. While the listener for the "compareButton" can access it via a closure, if the function is re-run, the reference to the previous interval is lost, making it impossible to clear the old timer.

  • Event Listener Stacking: Every time the disableBackspaceCheckbox is toggled, a new event listener

# Download the data from: https://gpc-browser.gs1.org/ using Download GPC as JSON
import json
data_file = "./data/GPC_May2024.json"
output_file = "./data/GPC_May2024.flattened.json"
with open(data_file) as fp:
data = json.load(fp)
from collections import defaultdict
from typing import Callable
class LazyVal:
_uncomputed_val = object()
def __init__(self, fn, *args, **kwargs) -> None:
self._val = self._uncomputed_val
self.args = args
@napsternxg
napsternxg / Walmart Info.md
Last active June 14, 2024 18:32
Walmart Data
@napsternxg
napsternxg / Colbertv2_Torch_Scratch.ipynb
Created January 24, 2024 18:04
Colbertv2_Torch_Scratch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@napsternxg
napsternxg / onnx_edit.py
Last active January 24, 2024 15:58
Edit Onnx Model Ops
import onnx
model_path = "./model.onnx"
fixed_model_path = model_path.replace(".onnx", ".fixed.onnx")
# # Load the ONNX model which should have last layer as Sigmoid.
# LGBM Models may sometime not add the Sigmoid op during export when using regression loss
onnx_model = onnx.load(model_path)
print(onnx_model)
onnx.checker.check_model(onnx_model)
@napsternxg
napsternxg / TasteAtlas.ipynb
Last active October 24, 2023 21:06
TasteAtlas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@napsternxg
napsternxg / display_ner.py
Last active October 17, 2023 17:35
NER utilities
from IPython.display import display, HTML
class DisplayEntities:
@classmethod
def display(cls, texts, grouped_entities):
html = []
html.append(cls.get_style())
for text, entities in zip(texts, grouped_entities):
html.append(cls.show_entities(text, entities))
display(HTML("".join(html)))
@napsternxg
napsternxg / generate.py
Created August 15, 2023 00:41
T5 CausalLM Constrained Generation Using Tries
import functools
import pandas as pd
import torch
import transformers
from accelerate import Accelerator
from datasets import Dataset
from torch.utils.data import DataLoader
from tqdm.auto import tqdm
@napsternxg
napsternxg / async_queue_runner.py
Last active August 28, 2023 21:26
asyncio_queue_event
import asyncio
import logging
import random
import time
from dataclasses import dataclass
from typing import Any
from tqdm.auto import tqdm
logger = logging.getLogger(__name__)