Skip to content

Instantly share code, notes, and snippets.

View berinaniesh's full-sized avatar
🗿
In theory, theory works!

Berin Aniesh berinaniesh

🗿
In theory, theory works!
View GitHub Profile
@berinaniesh
berinaniesh / +layout.svelte
Last active November 20, 2023 07:09
svelte progress bar
<script>
import { browser } from '$app/environment';
if (browser) {
const progressBar = document.getElementById('progress');
const content = document.getElementById('content');
function updateProgressBar() {
const scrollTop = window.scrollY;
const contentHeight = content.offsetHeight;
const windowHeight = window.innerHeight;
const progress = (scrollTop / (contentHeight - windowHeight)) * 100;
@berinaniesh
berinaniesh / db.py
Created October 7, 2023 21:26
Script to feed usfm to database. Check github.com/berinaniesh/bible-api for schema.
import psycopg
import requests
import glob
from tqdm import tqdm
import subprocess
API = "http://127.0.0.1:7000"
usfms = glob.glob("usfm1910/*")
abbreviations = requests.get(f"{API}/abbreviations").json()
@berinaniesh
berinaniesh / tf-mnist-cnn.py
Created August 8, 2023 10:39
Tensorflow MNIST CNN
import tensorflow as tf
import tensorflow_datasets as tfds
(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True,
with_info=True,
data_dir="./tensorflow_datasets"
# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import (
ResolverPlayground,
ResolverPlaygroundTestCase,
)
@berinaniesh
berinaniesh / a.txt
Last active June 18, 2023 10:26
Profiling results
Profiling results.
@berinaniesh
berinaniesh / profile.png
Last active June 7, 2023 01:57
emerge --version cProfile results
Contains the cProfile result as an image
@berinaniesh
berinaniesh / script-output.txt
Last active June 7, 2023 01:55
Git bisect results - moved from http://sprunge.us/eUWqr8 for permanence
running './script'
0.8035502433776855
skip
Error during set creation: Could not import 'portage._sets.dbapi.SubslotChangedSet' for section 'changed-subslot'
Exception in callback AsyncScheduler._task_coroutine_done(<_emerge.Ebui...x7fec345ea200>)(<Future finis...te 'ebuild'")>)
handle: <Handle AsyncScheduler._task_coroutine_done(<_emerge.Ebui...x7fec345ea200>)(<Future finis...te 'ebuild'")>)>
Traceback (most recent call last):
File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
@berinaniesh
berinaniesh / systeminfo.txt
Created February 23, 2023 13:12
System Information
Computer Information:
Manufacturer: ASUSTeK COMPUTER INC.
Model: ROG Strix G513QY_G513QY
Form Factor: Laptop
No Touch Input Detected
Processor Information:
CPU Vendor: AuthenticAMD
CPU Brand: AMD Ryzen 9 5900HX with Radeon Graphics
CPU Family: 0x19
@berinaniesh
berinaniesh / faq.md
Last active October 27, 2021 07:13
Digits of a number

FAQ

  • Can we solve the problem using print("\n") rather println()?
    • Yes, they produce the same exact output.
  • Is there an easier way to produce powers of 10 without using loops?
    • We can use Math.pow from the java.lang.Math library, but that returns a double. We have to convert it to an integer.
  • Why does the loop run till the number is not equal to zero?
    • Because we want the program to execute till we print all digits.
@berinaniesh
berinaniesh / faq.md
Created October 26, 2021 12:27
Sort Dates

FAQ

  • The algorithm seems to be using a lot of space to sort a few dates. Is this the optimal solution?

    • One thing we have to keep in mind is that count sort sorts any number of dates in constant space, that is O(1). Even if the number seems big, when we scale up the number of inputs, the algorithm will be much faster and more efficient than most other implementations.
  • What happens if we sort by year first?

    • We need the output to be sorted by year, month and date with respective order of precedence. So, when we first sort by year, then by date, the later sort reorders the years which leads to wrong answer. So, it is not possible to sort by year first.
  • Is this still the optimal solution if we know the number of inputs beforehand?

    • Probably not because, if we know the number of inputs, we need not create an array of size 2501. We can sort the dates in a more space optimal way without much implication on the time complexity.