Skip to content

Instantly share code, notes, and snippets.

@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 / password_game_elements_solver.py
Last active June 29, 2024 15:20
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 / 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 / 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 / eps-to-pdf.sh
Created February 19, 2019 09:48
Batch eps to pdf from mac command line
FILES="*.eps"; for f in $FILES; do ps2pdf -dEPSCrop $f; done
@HebeHH
HebeHH / turtle-messenger.py
Created February 1, 2019 18:48
Turn plain text into a messenger chat animation using python's turtle graphic library.
import turtle
# msgr font is Roboto
# draw rounded corner
def corner(tess):
for i in range(15):
tess.right(6)
tess.forward(2)
# draw rounded, filled rectangle of around (40+h)*(40+w) dimensions
import praw
import re
import pandas as pd
# connect to reddit
reddit = praw.Reddit(client_id='my_id', client_secret='my_secret', user_agent='me')
# get new submissions from News
submissions = []
for submission in reddit.subreddit("News").new(limit = None):
@HebeHH
HebeHH / reddit_cmdline_search.py
Last active August 3, 2018 15:27
Search through specific subreddits from the command line. Returns titles and vote scores only
import praw
import re
from tqdm import tqdm
import pandas as pd
pd.options.display.max_colwidth = 70
# pick subreddits, any delimiter but letter, number and new line is okay (will default to r/news if no valid input)
subreddits = "+".join(re.findall(r'[A-Za-z0-9]+', raw_input("Enter desired subreddits on one line\n")))
print "Your subreddits are: " + subreddits