You want to download a URL to a file using the requests python library, but you want to skip the download if it doesn’t exist
Use the following functions:
def download_file(filename, url):
Download an URL to a file
with open(filename, 'wb') as fout:
response = requests.get(url, stream=True)
# Write response data to file
for block in response.iter_content(4096):
def download_if_not_exists(filename, url):
Download a URL to a file if the file
does not exist already.
True if the file was downloaded,
False if it already existed
if not os.path.exists(filename):
You have a list of X/Y coordinates, for example:
coords = [(6.74219, -53.57835),
For these coordinates you want to compute the minimum bounding box.
You most likely found this post for one of two reasons:
- Either you haven’t heard of Z-Boxes and are interested in if they can somehow help you
- or you have to learn about Z-Boxes and you have absolutely no idea how to understand the mathematical definitions.
Either way, we’re going to investigate Z-Boxes – not using a box of formulas but using examples and Python code.
You have a ZIP file containing a single ESRI shapefile database (i.e. three files), for example the Natural Earth Countries database. Without unzipping the ZIP you want to use pyshp in order to read the data contain in the shapefile.
Occasionally I have to clean up some HTML code – mostly because parts of it were pasted into a CMS like WordPress from rich text editor like Word.
I’ve noticed that the formatting I want to remove is mostly based on
div elements with a
style attribute. Therefore, I’ve written a simple Python script based on BeautifulSoup4 which will replace certain tags with their contents if they have a
style attribute. While in some cases some other formatting might be destroyed by such a script, it is very useful for some recurring usecases.
Recently I’ve encountered a strange issue with the Broken Link Checker plugin for WordPress:
While all HTTP URLs work just fine, every single HTTPS URL yields an
Unknown error without any log message or explanation. Mehr lesen
In a previous post, I’ve written about how to check and enable transparent hugepages in Linux globally.
Although this post is important if you actually have a usecase for hugepages, I’ve seen multiple people getting fooled by the prospect that hugepages will magically increase performance. However, hugepaging is a complex topic and, if used in the wrong way, might easily decrease overall performance. Mehr lesen
For an explanation of in-place algorithms see my previous post on zero-copy in-place splitting
You have a C string possibly containing whitespace at the beginning and/or the end.
char* s = " abc \n\r";
Using an in-place algorithm, you want to remove the whitespace from this string.
Doing this is also possible using
boost::algorithm::trim, but it has the same caveats as
boost::algorithm::split as discussed in my previous post about C splitting Mehr lesen
Let’s assume you have a string:
char* s = "1,23,456,7890";
You want to split said string at each comma in order to obtain its parts as C strings (with the number of parts being variable):
char* s1 = "1";
char* s2 = "23";
char* s3 = "456";
char* s4 = "7890";
smartctl on your hard drive, you often get a plethora of information that can be hard to interpret for unexperienced users. This post attempts to provide aid in interpreting what the technical reasons behind the error messages are. If you’re looking for advice on whether to replace your hard drive, the only guidance I can give you is it might fail any time, so better backup your data, but it might also run for many years to come.. Furthermore, this article does not describe basic SMART
WHEN_FAILED checking but rather interpretation of more subtle signs of possibly impending HDD failures.