Skip to content

Instantly share code, notes, and snippets.

@LLyaudet
LLyaudet / gist:874f2530cec5ec35b5726c0554ef151c
Last active July 27, 2023 16:11
Prepend and append to your source files
import os
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".py"):
my_path = os.path.join(root, file)
# sed does not work on truly empty file
os.system("sed -i '1s;^;import os\\nos.system(\"echo DEBUT \" + os.path.abspath(__file__) + \" >> /tmp/montest\")\\n;' " + my_path)
os.system("echo '\\nos.system(\"echo FIN \" + os.path.abspath(__file__) + \" >> /tmp/montest\")' >> " + my_path)
# A variant to avoid complicated escaping
@LLyaudet
LLyaudet / req_to_curl.py
Last active November 23, 2022 15:05 — forked from asfaltboy/req_to_curl.py
Django HTTP Request to curl command (for replay)
"""
Convert a Django HTTPRequest object (or dictionary of such a request) into a
cURL command.
"""
def get_curl(request):
def convert(word, delim='-'):
return delim.join(x.capitalize() or '_' for x in word.split('_'))
def get_headers(request):
headers = {