Skip to content

Instantly share code, notes, and snippets.

@apoorvnandan
apoorvnandan / app.js
Created December 12, 2023 03:03
Basic contenteditable text editor
document.getElementById("editor").addEventListener("keydown", function (event) {
// Check if Enter is pressed without the Ctrl key
if (event.key === "Enter" && !event.ctrlKey) {
event.preventDefault();
}
// Check if both Ctrl and Enter are pressed
if (event.ctrlKey && event.key === "Enter") {
event.preventDefault();
@apoorvnandan
apoorvnandan / minimal_progress_bar.py
Created August 27, 2020 07:03
Extremely simple progress bar in python
class ProgressBar:
def __init__(self, total, desc='', width=10):
self.total = total
self.width = width
self.header = f"{desc}: " if len(desc) > 0 else ''
self.i = 0
self.__print_progress()
def __print_progress(self):
p = round((self.i*self.width) / self.total)
@apoorvnandan
apoorvnandan / convert_nb_script.py
Last active January 20, 2020 10:53
Convert jupyter notebook to python script (inspired by nbdev)
##
# usage:
# 1. Add '#export' as the first line of the cells you want to export.
# This script will ignore all other cells.
# 2. $python convert_nb_script.py -n sample.ipynb > sample_script.py
#
# You can use other tags to selectively export other cells
# eg. Add tag #test to the cells containing unit tests
# python convert_nb_script.py -n sample.ipynb -t test > unit_tests.py
##
def prefix_beam_search(ctc,
alphabet,
blank_token,
end_token,
space_token,
lm,
k=25,
alpha=0.30,
beta=5,
prune=0.001):
def create_spectrogram(signals):
stfts = tf.signal.stft(signals, fft_length=256)
spectrograms = tf.math.pow(tf.abs(stfts), 0.5)
return spectrograms
class ASR(tf.keras.Model):
def __init__(self, filters, kernel_size, conv_stride, conv_border, n_lstm_units, n_dense_units):
super(ASR, self).__init__()
self.conv_layer = tf.keras.layers.Conv1D(filters,
kernel_size,
strides=conv_stride,
padding=conv_border,
activation='relu')
self.lstm_layer = tf.keras.layers.LSTM(n_lstm_units,
return_sequences=True,
@apoorvnandan
apoorvnandan / prefix_beam_search_complete.py
Last active August 19, 2019 09:16
Prefix Beam Search
class Cache:
'''
class to cache the probability values while performing prefix beam search
'''
def __init__(self):
self.data = {}
def add(self, key1, key2, value):
if key1 not in self.data:
self.data[key1] = {}
@apoorvnandan
apoorvnandan / README.md
Last active December 26, 2017 04:22
Zoomable Unilevel Partition

I modified Mike Bostock's Bilevel Partition so that only one level is viewable at a time and added labels.
This visualization also accepts negative values in the data, and displays them in Red color. The positive values are displayed in Green color Click on any arc to zoom in. Click in the center to zoom out.