Let's say you want to add a search box to your web site to find words within your published content. Or let's say you want to display a list of articles published on your blog, together with snippets of what the article looks like, or a short summary.
In both cases you probably have an .html page or some content from which you want to generate a snippet, just like on this blog: if you visit http://rabexc.org, you can see all articles published recently. Not the whole article, just a short summary of each.
Or if you look to the right of this page, you can see snippets of articles in the same category as this one.
Turns out that generating those snippets in
flask and basic python
library is extremely easy.
So, here are a few ways to do it...
[ ... ]
I am writing a small python script to keep track of various events and messages. It uses a flat file as an index, each record being of the same size and containing details about each message.
This file can get large, in the order of several hundreds of megabytes. The python code is trivial, given that each record is exactly the same size, but what is the fastest way to access and use that index file?
With python (or any programming language, for what is worth), I have plenty of ways to read a file:
io.readin python having perfectly good buffering, and just
io.read) a record at a time.
readin a string, followed by using offsets within the string).
readof some multiple of the size of the record, followed by using offsets within each chunk).
mmapor use some other crazy approach.
[ ... ]
Let's say you have a CSS with a few thousand selectors and many many rules. Let's say you want to eliminate the unused rules, how do you do that?
I spent about an hour looking online for some tool that would easily clean up CSS files. I've ended up trying a few browser extensions:
CSS Remove and combine, for chrome, did not work for me. It would only parse the very first web site in my browser window, and seemed to refuse
file:/// urls. I later discovered that
chrome natively supports this feature: just go in
developer tools (ctrl + shift + i), click the
audits tab, click
run, and you will find a drop down with the list of unused rules in your CSS.
Dust-me Selectors, for firefox, worked like a charm: it correctly identified all the unused selectors.
In both cases, however, the list was huge, I had thousands of unused selectors. I was really not looking forward to go through my CSS by hand, considering also that many styles had multiple selectors, and I could only remove the unused ones.
[ ... ]