Skip to content

Instantly share code, notes, and snippets.

@achadha235
achadha235 / check-py-installs.ts
Last active February 28, 2025 07:47
Debug python installs on your machine.
#!/usr/bin/env bun
// This script searches through the system PATH environment variable to locate Python installations
// It checks each directory in PATH for both 'python' and 'python3' executables
// When found, it prints the directory location and specific executable paths
// This can help diagnose which Python versions are available and their resolution order
// this script is written for bun - to run it use `bun run script.ts`
// it should also be runnable with node using `npx tsx ./script.ts`
@achadha235
achadha235 / use-push-notifications.ts
Last active November 19, 2024 06:18
React hook for managing web push notifications
import { useEffect, useState } from "react";
enum NotificationError {
ServiceWorkerAndPushManagerNotSupported = "ServiceWorkerAndPushManagerNotSupported",
PushManagerUnavailable = "PushManagerUnavailable",
ExistingSubscription = "ExistingSubscription",
PermissionNotGranted = "PermissionNotGranted",
}
export function useNotifications() {
@achadha235
achadha235 / clear-node-modules.sh
Created September 10, 2024 06:10
Clear all node modules in a folder recursively
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
@achadha235
achadha235 / activate_pyenv.sh
Created September 5, 2024 04:50
A convenience script to activate a conda environment in a given directory and make sure the correct binary is discoverable
activate_pyenv() {
if [[ -f ./.conda-env ]]; then
env_name=$(cat ./.conda-env)
conda activate "$env_name"
## This is to ensure that the python executable for conda is in the PATH and overrides any executables in
python_executable_path=$(dirname $(which python))
## add this to the front of the PATH
export PATH="$python_executable_path:$PATH"
fi
@achadha235
achadha235 / annas-archive-download.js
Created July 8, 2024 04:02
Anna's archive auto download
/**
* Wait on a slow download page for Anna's archive and auto * click the Download button once it is ready
*/
function checkAndClickDownloadButton() {
const intervalMs = 1000;
let clicked = false;
let intervalId;
function check() {
const btns = Array.from(document.getElementsByTagName("a")).filter(
(ele) => ele.innerText === "Download now"
@achadha235
achadha235 / cache.py
Last active June 28, 2023 21:36
A simple and fast redis based caching system with TTL and cron-based expiry
import os
import json
import pytz
import redis
import pickle
import hashlib
import datetime as dt
from typing import Optional, Union
from croniter import croniter
from urllib.parse import urlparse
import { DateTime } from "luxon";
import { Page } from "puppeteer";
import { logger } from "./index";
import { sleep } from "./utils";
export async function goToEDFSearchPage(
page: Page,
start: string,
end: string
) {
import { Icon, InlineIcon } from '@iconify/react';
import bxQuestionMark from '@iconify/icons-bx/bx-question-mark';
import { useState } from 'react';
import { Fade } from '@material-ui/core';
// mapping of language codes to shortcut strings
const shortcuts = {
en: [
{
shortcut: 'CMD + K',
@achadha235
achadha235 / InteractiveComponent.js
Last active December 11, 2020 11:10
Interactive React Component
/**
* InteractiveComponent - Easily trigger event handler binding
* to instance context with a customizable method naming convention
e.g.
class Foo extends InteractiveComponent {
onFooClickedHandler(event){
console.log('state', this.state)
@achadha235
achadha235 / try-me.js
Created March 12, 2019 03:38
Webauthn
var createChallenge = () => window.crypto.getRandomValues(new Uint8Array(32)).buffer;
var createUserId = () => new Uint8Array(16);
var credential;
var attestation;
var assertion;
var createCredentialDefaultArgs = {
publicKey: {
rp: { name: "Dapper" },