Skip to content

Instantly share code, notes, and snippets.

@HebeHH
HebeHH / CurlHeaderExtraction.py
Created August 19, 2020 15:22
Extracting Headers from cURL request as a dictionary for the python Requests library
# The function:
get_headers = lambda curl: {k:v for k, v in
[[i.strip().strip(r"'-H \$'") for i in
[x.split(': ')[0], ': '.join(x.split(': ')[1:])]]
for x in curl.split('\n')
if '-H' in x]}
# You get a curl request in this kind of format from eg: Chrome Developer Tools
# Important: all arguments must be on a new line and it must be a raw string (the r before the triple quotes)
@HebeHH
HebeHH / Timer.py
Created August 27, 2020 07:55
Timer class for profiling
class Timer:
def __init__(self, indent = 30):
self.start = time.time()
self.rj = indent
self.report = 'Start:'.rjust(self.rj) + '0.000000'.rjust(10)
self.current = self.start
def diff(self, msg):
tmp = self.current
self.current = time.time()
return msg.rjust(self.rj) +':'+str(round(self.current - tmp, 6)).rjust(10)
@HebeHH
HebeHH / password_game_elements_solver.py
Last active October 2, 2024 07:50
Solver for The Password Game, specifically the section "The elements in your password must have atomic numbers that add up to 200"
# This is a solver for The Password Game: https://neal.fun/password-game/,
# Specifically the section "The elements in your password must have atomic numbers that add up to 200"
# It's written as a Flask app because I was sharing it with my friends that were also playing.
# However you can just use the function `get_required_elements_for_password_game(password)`
# to do it locally
# Got ChatGPT to write the element list for me
elements = [
{"name": "Hydrogen", "symbol": "H", "atomic_number": 1},
@HebeHH
HebeHH / basic-rag-news.py
Created March 20, 2024 23:31
Basic RAG news teller
import requests, sys, os
from openai import OpenAI
newsapi_apikey = os.environ.get('NEWS_APIKEY')
# This is a terrible excuse for a keywords function. Please replace. Most issues with this RAG can be blamed on this.
def get_keywords(input_text):
stripped = ''.join([i for i in input_text if i.isalpha() or i == ' '])
@HebeHH
HebeHH / HoverSVG.tsx
Created October 7, 2024 01:53
React class to color an svg file on hover
"use client";
import React, { useState, useRef, useEffect } from "react";
interface HoverSVGProps {
src: string;
width: number;
height: number;
color: string;
alt: string;
hoverColor: string;