Skip to content

Instantly share code, notes, and snippets.

View Davis-3450's full-sized avatar
⚙️
Rustling

Davis Davis-3450

⚙️
Rustling
View GitHub Profile
@Davis-3450
Davis-3450 / conversions.txt
Created September 16, 2025 02:11
hormone conversion factors
## Universal
- nmol/L -> pmol/L = 1000
- pmol/L -> nmol/L = 0.001
- ng/mL -> ng/dL = 100
- ng/dL -> ng/mL = 0.01
- ng/mL -> pg/mL = 1000
- pg/mL -> ng/mL = 0.001
## Hormone specific
import argparse
import os
import re
import subprocess
import sys
from pathlib import Path
def repo_root() -> Path:
return Path(__file__).resolve().parent
@Davis-3450
Davis-3450 / structs2.rs
Created August 17, 2025 00:13
Rustlings structs 2
// Clone trait
// structs by default don't allow cloning, if we add this trait we can allow it and implement an alternative fix to this
#[derive(Debug, Clone)]
struct Order {
name: String,
year: u32,
made_by_phone: bool,
made_by_mobile: bool,
made_by_email: bool,
@Davis-3450
Davis-3450 / dfs.py
Created August 15, 2025 21:18
DSA snippets
def dfs(obj, key) -> dict | list | None:
"""
Finds an item and returns values
Args:
obj (dict | list): object
key (str): target key
Returns:
dict | list | None
"""
# Handle dicts
@Davis-3450
Davis-3450 / ModeToggle.tsx
Last active August 7, 2025 05:11
Theme switch for astro.
import * as React from "react";
import { Moon, Sun } from "lucide-react";
import { Button } from "@/components/ui/button"; // shadcn button
export function ModeToggle() {
const [theme, setThemeState] = React.useState<"light" | "dark">("light");
// Initialize theme from localStorage or DOM
React.useEffect(() => {
---
description: "Use shadcn/ui components as needed for any UI code"
patterns: "*.tsx"
---
# Shadcn UI Components
This project uses @shadcn/ui for UI components. These are beautifully designed, accessible components that you can copy and paste into your apps.
## Finding and Using Components
// 1) Abre el diálogo de compartir
const openBtn = document.querySelector('div[role="button"][aria-label="Send this to friends or post it on your profile."]');
if (openBtn) {
const e1 = new MouseEvent('click', {bubbles: true, cancelable: true, view: window});
openBtn.dispatchEvent(e1);
// 2) Espera un momento a que aparezca el botón “Share now”
setTimeout(() => {
const shareBtn = document.querySelector('div[role="button"][aria-label="Share now"]');
if (shareBtn) {
const e2 = new MouseEvent('click', {bubbles: true, cancelable: true, view: window});
from stem import Signal
from stem.control import Controller
import requests
class TorController:
def __init__(self, control_port=9051):
self.control_port = control_port
self.local_ip = f"127.0.0.1{control_port}"
@Davis-3450
Davis-3450 / spintax.js
Created December 24, 2024 07:01
A JS implementation of nested spintax
function processSpintax(text) {
// Define the regex that captures the innermost { ... }
const regex = /\{([^{}]+)\}/;
// Keep going while the text still matches { ... }
while (regex.test(text)) {
text = text.replace(regex, (match, contents) => {
// Split the contents by "|"
const parts = contents.split('|');
@Davis-3450
Davis-3450 / captionScraper.js
Created November 14, 2024 01:04
twitter caption scraper (js console)
// Run this in the browser console on any profile's timeline page
(async function() {
// Set to store unique tweets
let tweetsSet = new Set();
let scrollAttempts = 0;
const maxScrollAttempts = 5; // Number of times to try scrolling without new tweets before stopping
// Function to sleep for a given time (in milliseconds)
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));