Skip to content

Instantly share code, notes, and snippets.

View specbug's full-sized avatar

Rishit Vora specbug

View GitHub Profile
@specbug
specbug / encrypt.py
Last active November 25, 2024 17:50
import hashlib
import binascii
import random
def derive_key(password, salt, iterations, dklen):
password = password.encode('utf-8')
salt = salt.encode('utf-8')
dk = hashlib.pbkdf2_hmac('sha256', password, salt, iterations, dklen)
return binascii.hexlify(dk).decode('utf-8')
"""
Run: `python ia_assignment.py 5`
(1) Generate all combinations & prune branches with four consecutive misses.
(2) Track cases where the student is absent on the Nth day.
I use backtracking to generate all combinations with early pruning to optimize runtime.
For each valid attendance branch, we increment the count of ways by one.
If a branch concludes with an absence, the count of misses increases by one.
@specbug
specbug / switch_git_profile.sh
Last active June 24, 2023 10:37
Switch easily b/w personal & work profiles
#!/bin/zsh
if [[ "$1" == "work" ]]; then
git config --global user.email <work email>
git config --global user.name <work username>
echo "Switched to work profile"
elif [[ "$1" == "personal" ]]; then
git config --global user.email <personal email>
git config --global user.name <personal username>
echo "Switched to personal profile"

Keybase proof

I hereby claim:

  • I am specbug on github.
  • I am specbug (https://keybase.io/specbug) on keybase.
  • I have a public key ASDStgoHWKiP216MqojMY0BmVc9Ybb1q2-PoQ--w5FYOXwo

To claim this, I am signing this object:

@specbug
specbug / analyse_cluster.py
Last active December 1, 2022 14:04
A sample representation of Twitter information bubble. Generated by ChatGPT.
# Analyze the clusters and connections in the graph
for node, cluster in partition.items():
if cluster == 1:
# Calculate the percentage of nodes that represent Tweets and the percentage of nodes that represent people you follow
num_tweets = len([n for n in cluster1 if n['type'] == 'tweet'])
num_following = len([n for n in cluster1 if n['type'] == 'person'])
tweet_percentage = num_tweets / len(cluster1)
following_percentage = num_following / len(cluster1)
print(f'Cluster 1: {tweet_percentage}% Tweets, {following_percentage}% people you follow')
@specbug
specbug / greadywrap.ipynb
Created November 18, 2022 12:27
Fetch & populate thumbnails for a Goodreads export.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#1
for i in range(n): # executes n times - {1}
for j in range(m): # executes m times - {2}
t += i * j # executes in constant time - {3}
@specbug
specbug / curry.py
Last active August 7, 2021 08:10
Python curry decorator
def curry(func):
total_args = func.__code__.co_argcount
def curried_wrapper(*args):
l_args = list(args)
def recurry(*args):
l_args.extend(args)
if len(l_args) == total_args:
return func(*l_args)
return recurry
@specbug
specbug / cc.sh
Created July 19, 2021 12:02
Count total commits, across all your GitHub repos.
# Place all repos, and the script, in a folder.
COUNTER=0
for d in */
do
cd "./$d"
GIT_C=$(git rev-list --all --count)
echo "Commits in $d: $GIT_C"
COUNTER=$((COUNTER + GIT_C))