Skip to content

Instantly share code, notes, and snippets.

@rjchee
rjchee / cassidoo_437.py
Created December 29, 2025 08:40
for cassidoo's #437 interview question
import re
def replaceRepeats(s: str, n: int) -> str:
return re.sub(f"{n}+", lambda m: str(len(m[0])), s)
print(f"{replaceRepeats('1234500362000440', 0)=}")
print(f"{replaceRepeats('000000000000', 0)=}")
print(f"{replaceRepeats('123456789', 1)=}")
@rjchee
rjchee / download.py
Created February 22, 2019 02:35
Download videos
import os
import subprocess
import sys
import xml.etree.ElementTree as ET
with open(sys.argv[1], 'r') as rss:
et = ET.parse(rss)
root = et.getroot()
for name, url in zip((e.text for e in root.findall('./channel/item/title')), (e.attrib['url'] for e in root.findall('./channel/item/enclosure'))):
download_name = f"{name.replace(' ', '-')}.mp4"
@rjchee
rjchee / stressbot.py
Created October 10, 2017 22:27
stressbot
from twython import Twython
API_KEY = '<Your API key here>'
API_SECRET = '<Your API secret here>'
OAUTH_TOKEN = '<Your OAuth token here>'
OAUTH_SECRET = '<Your OAuth secret here>'
twitter = Twython(API_KEY, API_SECRET, OAUTH_TOKEN, OAUTH_SECRET)
twitter.update_status(status="I'm stressed")